Skip to content

Prometheus Tutorials

This page collects practical Prometheus setup and query examples.

A Minimal Scrape Config

global:
  scrape_interval: 15s
  evaluation_interval: 15s

scrape_configs:
  - job_name: node
    static_configs:
      - targets:
          - node-exporter:9100

  - job_name: app
    metrics_path: /metrics
    static_configs:
      - targets:
          - app:8080

Basic Queries

up
rate(http_requests_total[5m])
sum by (status) (rate(http_requests_total[5m]))

Useful patterns:

  • rate() for counters.
  • sum by (...) to aggregate dimensions.
  • histogram_quantile() for latency percentiles.

Alert Rule Example

groups:
  - name: app-alerts
    rules:
      - alert: HighErrorRate
        expr: rate(http_requests_total{status=~"5.."}[5m]) > 1
        for: 10m
        labels:
          severity: warning
        annotations:
          summary: High 5xx error rate

Common Setup Flow

  1. Expose /metrics in the application or install exporters.
  2. Add the target to scrape_configs.
  3. Verify the target is up.
  4. Build one or two dashboards in Grafana.
  5. Add alerting once the dashboards reflect the real system.

Practical Notes

  • Start with a small set of metrics that answer operational questions.
  • Use labels for dimensions you actually need to filter or group by.
  • Keep the dashboard and alert names close to the service or team that owns them.