CodeBlanks Logo Icon CodeBlanks

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

Practice 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.

Starter code

terminal
# buraya yaz

Sample solution

terminal
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

Expected output

"prometheus-community" has been added to your repositories
NAME: izleme
STATUS: deployed
NAME                                                READY   STATUS    RESTARTS   AGE
alertmanager-izleme-kube-prometheus-sta-alertmanager-0   2/2     Running   0          60s
izleme-grafana-6c8d9b7f4-x2k9p                      3/3     Running   0          65s
prometheus-izleme-kube-prometheus-sta-prometheus-0  2/2     Running   0          60s

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 How does Prometheus collect metrics?

  • By reading log files
  • From etcd
  • By pulling the targets' /metrics endpoint at intervals Correct answer
  • Applications push to it

Explanation: There is a Pushgateway intermediary for short-lived jobs.

2 Write the target's metrics endpoint.

Question
curl -s http://api:8000/____
Answer
curl -s http://api:8000/metrics

Explanation: Prometheus conventionally reads /metrics.

3 Match the types.

Term Meaning
Counter Only goes up
Gauge Goes up and down
Histogram Bucketed distribution
scrape Pulling

All lessons in Advanced