The audit-tool allows you to analyze and compare Kubernetes API server audit logs, etcd metrics, and alerts grabbed using the gather_for_visualization must-gather script, by importing them into Prometheus and enabling querying with PromQL.
You can install audit-tool directly using go install:
go install [github.com/natamm4/audit-tool/cmd/audit-tool@latest](https://github.com/natamm4/audit-tool/cmd/audit-tool@latest)This guide outlines the steps to collect the audit logs, etcd and alert metrics, the process and and import them into Prometheus with audit-tool, and finally query them using PromQL.
oc adm must-gather -- /usr/bin/gather_for_visualizationConvert the collected audit logs into OpenMetrics format, create Prometheus TSDB blocks for each metrics file, and start a combined Prometheus instance.
audit-tool visualize --read /PATH/TO/must-gatherOpen your web browser and navigate to http://localhost:9090.
Use PromQL to perform RCA.
Once Prometheus is running, you can use PromQL to analyze your metrics. The following are the bits of info queryable for the audit events:
- verb (eg. 'update', 'get', etc.)
- resource (eg. 'pods')
- subresource
- name (eg. 'etcd-endpoints')
- namespace
- user
- code (http status code eg. 200)
- stage (eg. 'RequestReceived', 'ResponseComplete')
For the etcd metrics:
- container
- endpoint
- instance
- job
- namespace
- pod
- service
For the alerts:
- alertname
- alertstate
- container
- endpoint
- instance
- job
- namespace
- pod
- service
- severity
- type
count(audit_event_duration_seconds_bucket{verb="watch"}) by (user)count(audit_event_duration_seconds_bucket{verb="update", resource="configmaps", name="etcd-endpoints"}) by (user)count(audit_event_duration_seconds_bucket{verb="list",resource="pods"}) by (user)Currently, the gather_for_visualization script grabs etcd metrics and alerts (because the builder was on the etcd team), but this can be expanded to include gather more metrics.