Skip to main content

Prometheus

Prometheus is an open-source monitoring system that collects time-series metrics by scraping HTTP endpoints at regular intervals, stores them locally, and exposes them through the PromQL query language. In Kubernetes it is the standard tool for pod, node, and application metrics.

The pull model

Instead of applications pushing metrics, Prometheus visits each target's /metrics endpoint on a schedule, commonly every 15 to 30 seconds. A failed scrape is itself a signal that the target is down. Short-lived jobs that cannot be scraped can use the Pushgateway.

flowchart TD P["Prometheus"] -->|"scrape /metrics"| A["App pods"] P -->|"scrape /metrics"| N["Node Exporter"] P -->|"scrape /metrics"| K["kube-state-metrics"] P -->|"alerts"| M["Alertmanager"] G["Grafana"] -->|"PromQL"| P classDef core fill:#F97316,color:#ffffff classDef tgt fill:#DBEAFE,color:#1E293B classDef other fill:#D1FAE5,color:#1E293B class P core class A,N,K tgt class M,G other

Install the full stack

Bash
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm repo update
helm install kube-prometheus-stack prometheus-community/kube-prometheus-stack \
--namespace monitoring --create-namespace \
--set prometheus.prometheusSpec.retention=30d
kubectl port-forward svc/prometheus-operated 9090:9090 -n monitoring

The chart installs Prometheus, Alertmanager, Grafana, Node Exporter, and kube-state-metrics, managed by the Prometheus Operator.

Scrape your app with a ServiceMonitor

YAML
apiVersion: monitoring.coreos.com/v1
kind: ServiceMonitor
metadata:
name: payment-api
namespace: production
labels:
release: kube-prometheus-stack # must match the Prometheus selector
spec:
selector:
matchLabels:
app: payment-api
endpoints:
- port: http
path: /metrics
interval: 15s

Check the Targets page at http://localhost:9090/targets. A target should show state UP.

Troubleshooting

Problem Likely cause Fix
Target DOWN App not exposing metrics Curl /metrics from inside the pod
ServiceMonitor ignored Label selector mismatch Match the release label
High memory use High-cardinality labels Remove IDs from labels
Data lost No persistent volume Use persistent storage
Tip

Keep label values low cardinality. A label such as user_id creates a time series per user and can exhaust memory.

Remember

Prometheus stores data locally and is not horizontally scalable. For long retention or multiple clusters, add remote write to Thanos, Mimir, or a managed service.

Common Mistake

Treating a single Prometheus as long-term storage. Set retention and size limits and plan remote storage for compliance needs.

Frequently Asked Questions

Why does Prometheus pull instead of receiving pushes?

Pulling makes target health visible, needs no ingestion pipeline for applications, and lets you scrape a target ad hoc while debugging. The Pushgateway covers short-lived batch jobs.

What is cardinality explosion?

Putting unbounded values such as user IDs or URLs into labels creates a huge number of series, which inflates memory and disk usage. Keep label values bounded.

What does kube-state-metrics add?

It exposes Kubernetes object state as metrics, such as desired and available replicas and pod phases, complementing resource usage metrics from cAdvisor and Node Exporter.

Found a mistake, an outdated step or a broken link?