Docker & Kubernetes
What is Prometheus?
Learn Prometheus as a metrics collection system.
What is Prometheus?
Prometheus is an open-source monitoring system that collects and stores time-series metrics. It works with a pull model: it reads the targets' /metrics endpoint at intervals (scrape). Metrics are identified by name and labels:
$ curl -s http://api:8000/metrics | head -4
# HELP http_requests_total Toplam HTTP istekleri
# TYPE http_requests_total counter
http_requests_total{method="GET",path="/urunler",status="200"} 10432
http_requests_total{method="POST",path="/sepet",status="500"} 17
In Kubernetes, the most common installation is the kube-prometheus-stack Helm chart: Prometheus, Alertmanager, Grafana and ready dashboards.
Metric types
- Counter: a counter that only goes up (total requests, errors). Used with
rate() for speed. - Gauge: a value that goes up and down (memory, queue length).
- Histogram: the distribution of values in buckets (response time); percentiles are calculated.
- Summary: percentiles calculated on the client side.
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install izleme prometheus-community/kube-prometheus-stack -n izleme --create-namespace
kubectl port-forward -n izleme svc/izleme-kube-prometheus-sta-prometheus 9090
Exercise Install Prometheus
Write three commands: add the prometheus-community repository with the address https://prometheus-community.github.io/helm-charts; install the prometheus-community/kube-prometheus-stack chart with the release name izleme into the izleme namespace (creating it if missing); list the pods in izleme.
Show example solution
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install izleme prometheus-community/kube-prometheus-stack -n izleme --create-namespace
kubectl get pods -n izleme
Test yourself
-
How does Prometheus collect metrics?
- By reading log files
- From etcd
- By pulling the targets' /metrics endpoint at intervals
- Applications push to it
Show answer
By pulling the targets' /metrics endpoint at intervals — There is a Pushgateway intermediary for short-lived jobs.
-
Write the target's metrics endpoint.
curl -s http://api:8000/____
Show answer
curl -s http://api:8000/metrics
-
Match the types.
- Counter
- Only goes up
- Gauge
- Goes up and down
- Histogram
- Bucketed distribution
- scrape
- Pulling
Next lesson: ServiceMonitor