"Kafka Configs Metrics Exporter" for Prometheus allows you to export some of the Kafka configuration as metrics.
Unlike some other systems, Kafka doesn't expose its configurations as metrics.
There are few useful configuration parameters that might be beneficial to collect in order to improve the visibility and alerting over Kafka.
A good example might be log.retention.ms
parameter per topic, which can be integrated into Kafka's dashboards to extend its visibility, or to integrate it into an alerting query to create smarter alerts or automations based on topic retention.
Therefore, I decided to create a Prometheus exporter to collect those metrics.
Read more on Confluent Blog
- Install Go version 1.20+
- Clone this repository
git clone https://github.com/EladLeev/kafka-config-metrics
cd kafka-config-metrics
- Build the exporter binary
go build -o kcm-exporter .
-
Copy and edit the config file from this repository and point it into your Kafka clusters.
Use topic filtering as needed. -
Deploy the binary and run the exporter
cp ~/my_kcm.yaml /opt/kcm/kcm.yaml
./kcm-exporter
The exporter will use /opt/kcm/kcm.yaml
as default.
- Clone this repository
git clone https://github.com/EladLeev/kafka-config-metrics
cd kafka-config-metrics
- Build the Docker image
docker build . -t kcm-exporter
- Run it with your custom configuration file
docker run -p 9899:9899 -v ~/my_kcm.yaml:/opt/kcm/kcm.yaml kcm-exporter:latest
Helm chart is available under the /charts
dir.
To install the chart:
helm install kafka-config-metrics ./charts/kafka-config-metrics -f values.yaml
This project tried to stand in the Prometheus community best practices -
"You should aim for an exporter that requires no custom configuration by the user beyond telling it where the application is".
In fact, you don't really need to change anything beyond the clusters
configuration.
Example configuration:
global:
port: ":9899" # Which port to bind
timeout: 3 # HTTP server timeout in seconds
log:
format: "text" # Log format: text or json
level: "info" # Log level: info, debug, trace
kafka:
defaultRefreshRate: 60 # Refresh rate in seconds
minKafkaVersion: "2.8.0" # Minimum Kafka version
adminTimeout: 5 # Admin client timeout in seconds
clusters:
prod:
brokers:
- "kafka01-prod:9092"
topicFilter: "" # Optional regex filter
tls:
enabled: false
# caCert: "/path/to/ca.crt"
# clientCert: "/path/to/client.crt"
# clientKey: "/path/to/client.key"
sasl:
enabled: false
usernameEnv: "KAFKA_USERNAME"
passwordEnv: "KAFKA_PASSWORD"
mechanism: "PLAIN" # PLAIN, SCRAM-SHA-256, or SCRAM-SHA-512
test:
brokers:
- "kafka02-test:9092"
- "kafka03-test:9092"
topicFilter: "^(qa-|test-).*$"
The exporter supports both TLS and SASL authentication:
- TLS: Provide CA certificate and optionally client certificate/key
- SASL: Supports PLAIN, SCRAM-SHA-256, and SCRAM-SHA-512 mechanisms
- Credentials are loaded from environment variables
When setting this exporter in the Prometheus targets, bear in mind that topic configs are not subject to change that often in most use cases.
Setting a higher scrape_interval
, let's say to 10 minutes, will lead to lower requests rate to the Kafka cluster while still keeping the exporter functional.
scrape_configs:
- job_name: 'kcm'
scrape_interval: 600s
static_configs:
- targets: ['kcm-prod:9899']
/metrics
- Metrics endpoint
/-/healthy
- This endpoint returns 200 and should be used to check the exporter health.
/-/ready
- This endpoint returns 200 when the exporter is ready to serve traffic.
Please read CONTRIBUTING.md for details of submitting a pull requests.
This project is licensed under the Apache License - see the LICENSE.md file for details.