Skip to content

Kafka Configs Metrics Exporter for Prometheus

License

Apache-2.0, Apache-2.0 licenses found

Licenses found

Apache-2.0
LICENSE
Apache-2.0
LICENSE.md
Notifications You must be signed in to change notification settings

EladLeev/kafka-config-metrics

Kafka Configs Metrics Exporter

GitHub Workflow Status Go Report Card Renovate

"Kafka Configs Metrics Exporter" for Prometheus allows you to export some of the Kafka configuration as metrics.

Motivation

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

Table of Contents

Build from source

Prerequisites

  • Install Go version 1.20+

Building Steps

  1. Clone this repository
git clone https://github.com/EladLeev/kafka-config-metrics
cd kafka-config-metrics
  1. Build the exporter binary
go build -o kcm-exporter .
  1. Copy and edit the config file from this repository and point it into your Kafka clusters.
    Use topic filtering as needed.

  2. 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.

Using Docker Image

  1. Clone this repository
git clone https://github.com/EladLeev/kafka-config-metrics
cd kafka-config-metrics
  1. Build the Docker image
docker build . -t kcm-exporter
  1. Run it with your custom configuration file
docker run -p 9899:9899 -v ~/my_kcm.yaml:/opt/kcm/kcm.yaml kcm-exporter:latest

Helm

Helm chart is available under the /charts dir.

To install the chart:

helm install kafka-config-metrics ./charts/kafka-config-metrics -f values.yaml

Configuration

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-).*$"

Authentication

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

Prometheus Configuration

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']

Endpoints

/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.

Dashboard Example

Dashboard Sample

Contributing

Please read CONTRIBUTING.md for details of submitting a pull requests.

License

This project is licensed under the Apache License - see the LICENSE.md file for details.