Send Kafka Metrics to StatsD.
Let us know! If you fork this, or if you use it, or if it helps in anyway, we'd love to hear from you! opensource@airbnb.com
Kafka uses Yammer Metrics (now part of the Dropwizard project) for metrics reporting in both the server and the client. This can be configured to report stats using pluggable stats reporters to hook up to your monitoring system.
This project provides a simple integration between Kafka and a StatsD reporter for Metrics.
Metrics can be filtered based on the metric name and the metric dimensions (min, max, percentiles, etc).
0.9.0.0 or later use kafka-statsd-metrics2-0.5.00.8.2.0 or later use kafka-statsd-metrics2-0.4.00.8.1.1 or prior use kafka-statsd-metrics2-0.3.00.5.0 add support to report new producer/consumer metrics in kafka-0.90.4.0 adds support for tags on metrics. See dogstatsd extensions. If your statsd server does not support tags, you can disable them in the Kafka configuration. See property external.kafka.statsd.tag.enabled below.
The statsd client is com.indeed:java-dogstatsd-client:2.0.11.
MetricNames introduced by kafka 0.8.2.xkafka-statsd-metrics../kafka_2.11-0.9.0.1/libs/server.properties, add the following properties. Default values are in parenthesis.metric.reporters in producer.properties or consumer.properties # declare the reporter if new producer/consumer is used
metric.reporters=com.airbnb.kafka.kafka09.StatsdMetricsReporter
Producer:
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --new-consumer --zookeeper localhost:2181 --topic test -from-beginning --consumer.config config/consumer.properties
kafka.metrics.reporters in producer.properties or consumer.properties # declare the reporter if old producer/consumer is used
kafka.metrics.reporters=com.airbnb.kafka.kafka08.StatsdMetricsReporter
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic test --producer.config config/producer.properties --old-producer
bin/kafka-console-consumer.sh --bootstrap-server localhost:9092 --zookeeper localhost:2181 --topic test -from-beginning --consumer.config config/consumer.properties
# declare the reporter if new producer/consumer is used
metric.reporters=com.airbnb.kafka.StatsdMetricsReporter
# declare the reporter if old producer/consumer is used
kafka.metrics.reporters=com.airbnb.kafka.kafka08.StatsdMetricsReporter
# enable the reporter, (false)
external.kafka.statsd.reporter.enabled=true
# the host of the StatsD server (localhost)
external.kafka.statsd.host=localhost
# the port of the StatsD server (8125)
external.kafka.statsd.port=8125
# enable the support of statsd tag extension, e.g. datadog statsd (true)
external.kafka.statsd.tag.enabled=true
# a prefix for all metrics names (empty)
external.kafka.statsd.metrics.prefix=
# note that the StatsD reporter follows the global polling interval (10)
# kafka.metrics.polling.interval.secs=10
# A regex to exclude some metrics
# Default is: (kafka\.consumer\.FetchRequestAndResponseMetrics.*)|(.*ReplicaFetcherThread.*)|(kafka\.server\.FetcherLagMetrics\..*)|(kafka\.log\.Log\..*)|(kafka\.cluster\.Partition\..*)
#
# The metric name is formatted with this template: group.type.scope.name
#
# external.kafka.statsd.metrics.exclude_regex=
#
# Each metric provides multiple dimensions: min, max, meanRate, etc
# This might be too much data.
# It is possible to disable some metric dimensions with the following properties:
# By default all dimenstions are enabled.
#
# external.kafka.statsd.dimension.enabled.count=true
# external.kafka.statsd.dimension.enabled.meanRate=true
# external.kafka.statsd.dimension.enabled.rate1m=true
# external.kafka.statsd.dimension.enabled.rate5m=true
# external.kafka.statsd.dimension.enabled.rate15m=true
# external.kafka.statsd.dimension.enabled.min=true
# external.kafka.statsd.dimension.enabled.max=true
# external.kafka.statsd.dimension.enabled.mean=true
# external.kafka.statsd.dimension.enabled.stddev=true
# external.kafka.statsd.dimension.enabled.median=true
# external.kafka.statsd.dimension.enabled.p75=true
# external.kafka.statsd.dimension.enabled.p95=true
# external.kafka.statsd.dimension.enabled.p98=true
# external.kafka.statsd.dimension.enabled.p99=true
# external.kafka.statsd.dimension.enabled.p999=true
You can check your configuration in different ways:
"Kafka Statsd metrics reporter is enabled"kafka:type=com.airbnb.kafka.kafka08.StatsdMetricsReporter should also exist. # assuming the Statsd server has been stopped...
$ nc -ul 8125
kafka.controller.ControllerStats.LeaderElectionRateAndTimeMs.samples:1|gkafka.controller.ControllerStats
.LeaderElectionRateAndTimeMs.meanRate:0.05|gkafka.controller.ControllerStats.LeaderElectionRateAndTimeMs.
1MinuteRate:0.17|gkafka.controller.ControllerStats.LeaderElectionRateAndTimeMs.5MinuteRate:0.19|g....
Below are the metrics in Kafka 0.8.2
```bash +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Metrics kind | Metric Name | Metric Tags | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ReplicaManager.LeaderCount | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ReplicaManager.PartitionCount | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ReplicaManager.UnderReplicatedPartitions | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.controller.KafkaController.ActiveControllerCount | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.controller.KafkaController.OfflinePartitionsCount | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.controller.KafkaController.PreferredReplicaImbalanceCount | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.network.RequestChannel.RequestQueueSize | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ReplicaFetcherManager.Replica_MaxLag | {"clientId" -> clientId} | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ReplicaFetcherManager.Replica_MinFetchRate | {"clientId" -> clientId} | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.FetchRequestPurgatory.PurgatorySize | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.FetchRequestPurgatory.NumDelayedRequests | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ProducerRequestPurgatory.PurgatorySize | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.server.ProducerRequestPurgatory.NumDelayedRequests | | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.consumer.ConsumerFetcherManager.MaxLag | {"clientId" -> clientId} | +--------------+-----------------------------------------------------------------------------+-------------------------------------------------------------------------------------------------------------+ | Gauge | kafka.consumer.ConsumerFetcherManager.MinFetchRate | {"clientId" -> clientId} | +--------------+-----------------------------------------------------------------------
$ claude mcp add kafka-statsd-metrics2 \
-- python -m otcore.mcp_server <graph>