Metric Collection
Metric Collection is the process of scraping metrics from applications running in Kubernetes pods using Prometheus.
Collecting container metrics based on pod annotations
Kubernetes Pod Annotations are used to mark pods as targets for metric collection. Set the value to true to enable metric scraping for containers inside the pod. You can add the following annotation:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
prometheus.io/path: /metrics
There are two ways to enable metric collection:
1. Through pod definition
Annotate workloads (e.g., Deployment) to enable metric collection:
spec:
template:
metadata:
annotations:
prometheus.io/scrape: "true"
prometheus.io/port: "8000"
prometheus.io/path: /metrics
2. Through running pods
This is a temporary method that works on running pods. The annotation will be reverted after the pod is rolled out or restarted.
kubectl -n <namespace> annotate pod <pod_name> prometheus.io/scrape="true"
kubectl -n <namespace> annotate pod <pod_name> prometheus.io/port="8080"
kubectl -n <namespace> annotate pod <pod_name> prometheus.io/path="/metrics"
Last updated