Alert on cluster metrics with Managed Prometheus
In this task you'll collect cluster metrics with Prometheus and alert on them.
Managed Prometheus scrapes your AKS cluster's metrics for you and stores them in an Azure Monitor workspace. Azure Managed Grafana reads the same workspace for dashboards.
Alerts are PromQL expressions in a Prometheus rule group, evaluated every minute. When an expression returns results for longer than its for duration, Azure Monitor raises an alert and runs your action groups.
Example. Fernhill Cloud alerts when a container in the shop namespace restarts more than 3 times in 10 minutes. The first time it fired, on-call found a bad config before any customer noticed.
Costs money. This task creates resources that are charged while they exist. Delete them as soon as you finish.
Before you start
You need: An AKS cluster. Time: 30 minutes.
Where to look
- Kubernetes services
- (cluster)
- Monitoring
- Insights
Steps
- Create an Azure Monitor workspace and, if you want dashboards, a Managed Grafana.
- Turn on metrics:
az aks update --enable-azure-monitor-metrics --azure-monitor-workspace-resource-id <id> --grafana-resource-id <id>. - Deploy a Prometheus rule group scoped to the workspace with your alert's PromQL expression and clusterName.
- Break something on purpose and confirm the alert fires in Monitor, Alerts.
Commands
# Connect kubectl to the cluster first
az aks get-credentials -g <group> -n <cluster>
az aks update -g <group> -n <cluster> --enable-azure-monitor-metrics --azure-monitor-workspace-resource-id <workspace-id> --grafana-resource-id <grafana-id>
Watch out for
- Cost
- You pay for metrics ingested and Grafana's hours; the default scrape profile keeps it small.
- Security
- Give people Grafana Viewer unless they need more; Grafana Admin can change data sources.
- Common mistakes
- Alerts nobody has seen fire, and alerting on causes (CPU) instead of symptoms (failed requests, restarts).
Clean up
Delete the rule group, then turn metrics off with az aks update --disable-azure-monitor-metrics, or delete the group.
Words to know
- Managed Prometheus
- Azure's hosted Prometheus: scraping and storage without running servers.
- Azure Monitor workspace
- Where Managed Prometheus keeps its metrics.
- PromQL
- Prometheus's query language, used for dashboards and alert rules.
Tick off each step and track your progress in the guide.
Open this task in DevOps, Hands On