Skip to content

Commit d655bde

Browse files
kafka: Add topic partition size metric (DataDog#23028)
* kafka: Add topic partition size metric Add kafka.log.partition.size metric from the kafka.log:type=Log,name=Size JMX bean, tagged with topic and partition. Reports the on-disk size in bytes of each topic partition log per broker. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * kafka: Rename excluded version tag to request_version for RequestsPerSec beans Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 5761ec1 commit d655bde

5 files changed

Lines changed: 56 additions & 5 deletions

File tree

kafka/changelog.d/23028.added

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add kafka.log.partition.size metric for topic partition disk usage.

kafka/datadog_checks/kafka/data/metrics.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ jmx_metrics:
469469
- include:
470470
domain: 'kafka.network'
471471
bean_regex: 'kafka.network:type=RequestMetrics,name=RequestsPerSec,request=Produce(?:,version=.*)?'
472+
exclude_tags:
473+
- version
474+
tags:
475+
request_version: $version
472476
attribute:
473477
Count:
474478
metric_type: rate
@@ -494,6 +498,10 @@ jmx_metrics:
494498
- include:
495499
domain: 'kafka.network'
496500
bean_regex: 'kafka.network:type=RequestMetrics,name=RequestsPerSec,request=FetchConsumer(?:,version=.*)?'
501+
exclude_tags:
502+
- version
503+
tags:
504+
request_version: $version
497505
attribute:
498506
Count:
499507
metric_type: rate
@@ -505,6 +513,10 @@ jmx_metrics:
505513
- include:
506514
domain: 'kafka.network'
507515
bean_regex: 'kafka.network:type=RequestMetrics,name=RequestsPerSec,request=FetchFollower(?:,version=.*)?'
516+
exclude_tags:
517+
- version
518+
tags:
519+
request_version: $version
508520
attribute:
509521
Count:
510522
metric_type: rate
@@ -932,3 +944,21 @@ jmx_metrics:
932944
- tag_name: kafka_cluster_id
933945
bean_name: kafka.server:type=KafkaServer,name=ClusterId
934946
attribute: Value
947+
948+
#
949+
# Topic partition size
950+
#
951+
- include:
952+
domain: 'kafka.log'
953+
bean_regex: 'kafka\.log:type=Log,name=Size,topic=(.*),partition=(.*)'
954+
attribute:
955+
Value:
956+
metric_type: gauge
957+
alias: kafka.log.partition.size
958+
tags:
959+
topic: $1
960+
partition: $2
961+
dynamic_tags:
962+
- tag_name: kafka_cluster_id
963+
bean_name: kafka.server:type=KafkaServer,name=ClusterId
964+
attribute: Value

kafka/metadata.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ kafka.expires_sec,gauge,10,eviction,second,Rate of delayed producer request expi
1717
kafka.follower.expires_per_second,gauge,10,eviction,second,Rate of request expiration on followers.,-1,kafka,follow expire rate,,
1818
kafka.log.directory.offline,gauge,10,,,Whether a Kafka log directory is offline. 0 means healthy.,0,kafka,log dir offline,,
1919
kafka.log.flush_rate.rate,gauge,10,flush,second,Log flush rate.,0,kafka,log flush rate,memory,
20+
kafka.log.partition.size,gauge,10,byte,,The size in bytes of a topic partition log on disk.,0,kafka,partition size,,
2021
kafka.messages_in.rate,gauge,10,message,,Incoming message rate.,0,kafka,messages in,cpu,
2122
kafka.net.bytes_in.rate,gauge,10,byte,second,Incoming byte rate.,0,kafka,bytes in,cpu,
2223
kafka.net.bytes_out,gauge,,byte,second,Outgoing byte total.,0,kafka,bytes out total,,

kafka/tests/common.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313

1414

1515
"""
16-
Metrics that do not work in our e2e:
16+
Metrics that require a consumer in our e2e:
1717
"kafka.consumer.bytes_in",
1818
"kafka.consumer.kafka_commits",
1919
"kafka.consumer.messages_in",
2020
"kafka.consumer.zookeeper_commits",
21-
"kafka.request.produce.rate",
22-
"kafka.request.fetch_follower.rate",
23-
"kafka.request.fetch_consumer.rate",
2421
"kafka.consumer.fetch_rate",
22+
"kafka.request.fetch_consumer.rate",
23+
"kafka.request.fetch_follower.rate",
2524
"""
2625

2726
KAFKA_E2E_METRICS = [
@@ -60,6 +59,7 @@
6059
"kafka.replication.unclean_leader_elections.rate",
6160
"kafka.request.fetch.failed.rate",
6261
"kafka.request.produce.failed.rate",
62+
"kafka.request.produce.rate",
6363
"kafka.session.zookeeper.disconnect.rate",
6464
"kafka.session.zookeeper.expire.rate",
6565
"kafka.session.zookeeper.readonly.rate",
@@ -73,4 +73,9 @@
7373
"kafka.broker.start_time",
7474
# Log directory
7575
"kafka.log.directory.offline",
76+
# Topic partition size
77+
"kafka.log.partition.size",
78+
# Topic metrics
79+
"kafka.topic.messages_in.rate",
80+
"kafka.topic.net.bytes_in.rate",
7681
]

kafka/tests/compose/docker-compose.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,24 @@ services:
2323
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://localhost:9092
2424
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
2525
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
26-
KAFKA_CREATE_TOPICS: "marvel:2:1,dc:2:1"
2726
KAFKA_JMX_PORT: 9999
2827
KAFKA_JMX_HOSTNAME: localhost
2928
depends_on:
3029
zookeeper:
3130
condition: service_healthy
31+
kafka-init:
32+
image: confluentinc/cp-kafka:${CONFLUENT_VERSION}
33+
network_mode: "service:kafka"
34+
depends_on:
35+
- kafka
36+
entrypoint: ["/bin/bash", "-c"]
37+
command:
38+
- |
39+
echo "Waiting for Kafka to be ready..."
40+
while ! kafka-topics --bootstrap-server localhost:9092 --list > /dev/null 2>&1; do sleep 1; done
41+
kafka-topics --create --if-not-exists --topic marvel --partitions 2 --replication-factor 1 --bootstrap-server localhost:9092
42+
kafka-topics --create --if-not-exists --topic dc --partitions 2 --replication-factor 1 --bootstrap-server localhost:9092
43+
echo "test" | kafka-console-producer --bootstrap-server localhost:9092 --topic marvel
44+
echo "test" | kafka-console-producer --bootstrap-server localhost:9092 --topic dc
45+
echo "Topics created and seeded."
3246

0 commit comments

Comments
 (0)