Summary - Monitoring
- Docker & Kubernetes course
- Advanced
- Lesson 54/70
- 5 min
Combine Prometheus and Grafana to write a metrics query.
Summary: monitoring
In this group:
- Prometheus pulls the targets'
/metrics; types: counter, gauge, histogram, summary. - kube-prometheus-stack installs Prometheus, Alertmanager and Grafana; a ServiceMonitor is a target definition (mind the
releaselabel). - Grafana dashboards follow the RED (Rate, Errors, Duration) and USE methods.
- PromQL: label filters,
rate(),increase(),sum by,histogram_quantile. - A PrometheusRule holds alerting rules (
expr,for,severity); Alertmanager groups and routes.
sum by (path) (rate(http_requests_total{status=~"5.."}[5m]))Practice Add a metrics port to the service
Write a Service YAML: name api, label app: api; selector app: api; a single port: name: http, port: 8000, targetPort: 8000. (The ServiceMonitor uses this named port.)
Starter code
# buraya yazSample solution
apiVersion: v1
kind: Service
metadata:
name: api
labels:
app: api
spec:
selector:
app: api
ports:
- name: http
port: 8000
targetPort: 8000Expected output
service/api configured
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 A new ServiceMonitor's target doesn't appear on Prometheus's Targets page. What is checked first?
- The PVC size
- Whether the release label and the Service selector match Correct answer
- The Grafana password
- The node count
Explanation: The Prometheus object's serviceMonitorSelector must select the ServiceMonitor.
2 Calculate the 95th percentile.
____(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
histogram_quantile(0.95, sum(rate(http_request_duration_seconds_bucket[5m])) by (le))
Explanation: It calculates a percentile from histogram buckets.
3 Match.
| Term | Meaning |
|---|---|
Prometheus |
Collects |
Grafana |
Displays |
Alertmanager |
Notifies |
ServiceMonitor |
Defines the target |