A comprehensive monitoring solution for Apache Kafka using Prometheus for metrics collection and Grafana for visualization. This repository provides a complete Docker-based setup for monitoring Kafka clusters with pre-configured dashboards and alerting rules.
This monitoring stack consists of:
- Apache Kafka - Message broker with JMX metrics enabled
- Zookeeper - Kafka's coordination service
- Prometheus - Time-series database for metrics collection
- Grafana - Visualization and dashboard platform
- JMX Prometheus Agent - Exposes Kafka JMX metrics to Prometheus
- Docker and Docker Compose
- Ports 3000, 9090, 9092, 2181 available
-
Clone the repository
git clone <repository-url> cd kafka-promethues-grafana
-
Start the monitoring stack
docker-compose up -d
-
Access the services
- Grafana Dashboard: http://localhost:3000 (admin/admin)
- Prometheus: http://localhost:9090
- Kafka Broker: localhost:9092
- Zookeeper: localhost:2181
-
Kafka Overview Dashboard (
kafka_dashboard.json)- Cluster health metrics
- Topic and partition statistics
- Consumer lag monitoring
- Broker performance metrics
-
Advanced Kafka Dashboard (
grafana-kafka-dashboard-advanced.json)- Detailed broker metrics
- Network and request statistics
- Log and controller metrics
- Custom visualizations
The stack collects comprehensive Kafka metrics including:
- Cluster Metrics: Broker count, controller status, cluster size
- Topic Metrics: Message rates, partition counts, replication status
- Consumer Metrics: Consumer lag, fetch rates, commit rates
- Network Metrics: Request rates, response times, connection counts
- JVM Metrics: Memory usage, GC statistics, thread counts
The prometheus.yml file is configured to:
- Scrape Kafka metrics from port 7071
- Use a 15-second scrape interval
- Collect metrics with proper labeling
The prom-jmx-agent-config.yml file defines:
- Metric naming conventions
- Label extraction patterns
- Metric type mappings (Counter, Gauge, etc.)
The Dockerfile extends the official Kafka image to:
- Add the JMX Prometheus agent
- Configure JMX metrics exposure
- Set up proper port mappings
-
Consumer Lag (
kafka_consumer_lag)- Indicates if consumers are keeping up with producers
- High lag may indicate performance issues
-
Broker Health (
kafka_server_broker_state)- Monitors broker availability and status
- Critical for cluster stability
-
Request Rates (
kafka_network_request_total)- Tracks incoming request volume
- Helps identify traffic patterns
-
JVM Metrics (
jvm_*)- Memory usage and garbage collection
- Essential for performance tuning
While this setup includes comprehensive monitoring, you may want to add alerting rules for:
- High consumer lag
- Broker unavailability
- High memory usage
- Network errors
- Topic replication issues
- Modify
prom-jmx-agent-config.ymlto include additional JMX metrics - Update
prometheus.ymlif adding new scrape targets - Restart the stack:
docker-compose restart
- Import the provided dashboard JSON files into Grafana
- Modify panels, queries, and visualizations as needed
- Export updated dashboards and replace the JSON files
kafka-promethues-grafana/
├── docker-compose.yml # Service orchestration
├── Dockerfile # Custom Kafka image with JMX agent
├── prometheus.yml # Prometheus configuration
├── prom-jmx-agent-config.yml # JMX metrics mapping
├── kafka_dashboard.json # Basic Kafka dashboard
├── grafana-kafka-dashboard-advanced.json # Advanced dashboard
└── README.md # This file
-
Services not starting
- Check if required ports are available
- Ensure Docker has sufficient resources
-
No metrics in Grafana
- Verify Prometheus is scraping Kafka metrics
- Check JMX agent configuration
-
Dashboard import errors
- Ensure Grafana version compatibility
- Check JSON file format
# Check service status
docker-compose ps
# View logs
docker-compose logs kafka
docker-compose logs prometheus
docker-compose logs grafana
# Restart specific service
docker-compose restart kafka
# Clean up
docker-compose down -vNote: This repository was created as part of the blog article Kafka Monitoring Using Prometheus. For detailed explanations and best practices, refer to the original article.