OPA Gatekeeper Metrics and Grafana Dashboard
Posted on October 29, 2022 by Adrian Wyssmann ‐ 2 min read
Now, as we have installed OPA Gatekeeper in our clusters successfully, I wonder how to get metrics in Prometheus and show them in Grafana Dashboard
Gatekeeper Metrics
When looking at the documentation, both the gatekeeper-controller-manager and gatekeeper-audit deployments expose a metrics port for Prometheus scrapping. These metrics endpoints are not exposed via a Kubernetes service, so the user has to create [PodMonitor] resources, to configure the rancher-monitoring Prometheus instance to scrape metrics from them.
This issue explains the difference of both resources:
- [ServiceMonitor], which declaratively specifies how groups of services should be monitored. The Operator automatically generates Prometheus scrape configuration based on the definition. It will scrape all pods behind the service, because the Service maintains an
Endpoints
object. - [PodMonitor], which declaratively specifies how groups of pods should be monitored. The Operator automatically generates Prometheus scrape configuration based on the definition.
Based on this example, I create this resource in the cluster:
Grafana Dashboard
Once you have the metrics in Prometheus you can create a dashboard in Grafana. I actually found this gatekeeper dashboard provided by Grafana itself: