Skip to content

Prometheus Cheatsheet

Monitoring and alerting toolkit with time-series database.

01

Getting Started

Config

Prometheus config in YAML.

prometheus
global:
  scrape_interval: 15s

scrape_configs:
  - job_name: "myapp"
    static_configs:
      - targets: ["localhost:9090"]

Metrics Types

Four metric types: counter, gauge, histogram, summary.

prometheus
# Counter (only increases)
requests_total{method="GET"}

# Gauge (can go up/down)
temperature_celsius{sensor="A"}

# Histogram
request_duration_seconds_bucket{le="0.1"}

# Summary
request_duration_seconds{quantile="0.95"}
02

PromQL

Basic Query

Select time series by label.

prometheus
http_requests_total{method="GET"}

Rate

Calculate per-second rate over 5 minutes.

prometheus
rate(http_requests_total[5m])

Aggregation

Aggregate by label.

prometheus
sum by (method) (rate(http_requests_total[5m]))

Alerting

Alert rules in PromQL.

prometheus
ALERT HighRequestRate
  IF rate(http_requests_total[5m]) > 100
  FOR 10m
  LABELS { severity = "critical" }

Was this helpful?