Skip to main content

Instalação

# Docker
docker run -d \
  --name prometheus \
  -p 9090:9090 \
  -v /etc/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml \
  prom/prometheus

# Ou via systemd
apt install prometheus

Configuração

# /etc/prometheus/prometheus.yml
global:
  scrape_interval: 15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
    - static_configs:
        - targets:
          - alertmanager:9093

scrape_configs:
  - job_name: 'prometheus'
    static_configs:
      - targets: ['localhost:9090']

  - job_name: 'node'
    static_configs:
      - targets: ['node-exporter:9100']

Node Exporter

docker run -d \
  --name node-exporter \
  -p 9100:9100 \
  prom/node-exporter

PromQL

# Selecores
up{job="prometheus"}

# Rate
rate(http_requests_total[5m])

# Aggregations
sum(rate(http_requests_total[5m])) by (job)

# 95th percentile
histogram_quantile(0.95, rate(http_request_duration_seconds_bucket[5m]))

Alertmanager

# /etc/alertmanager/alertmanager.yml
global:
  smtp_smarthost: 'smtp.gmail.com:587'
  smtp_from: 'alertmanager@example.com'

route:
  group_by: ['alertname']
  receiver: 'email'

receivers:
  - name: 'email'
    email_configs:
      - to: 'admin@example.com'

Alertas

groups:
  - name: node_alerts
    rules:
      - alert: NodeDown
        expr: up{job="node"} == 0
        for: 5m
        labels:
          severity: critical
        annotations:
          summary: "Node {{ $labels.instance }} down"