Skip to content

Commit 6d325ff

Browse files
committed
[INTERNAL] Export numerical kafka_topic_info parameters/labels as individual metrics
Export as numerical metrics: - topic_info_partitions_count - topic_info_replication_factor - topic_info_min_insync_replicas - topic_info_retention_ms Partial fix for redpanda-data#116
1 parent 2c8b711 commit 6d325ff

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

prometheus/collect_topic_info.go

+32
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,38 @@ func (e *Exporter) collectTopicInfo(ctx context.Context, ch chan<- prometheus.Me
7979
float64(1),
8080
labelsValues...,
8181
)
82+
ch <- prometheus.MustNewConstMetric(
83+
e.topicInfoPartitionsCount,
84+
prometheus.GaugeValue,
85+
float64(partitionCount),
86+
*topic.Topic,
87+
)
88+
ch <- prometheus.MustNewConstMetric(
89+
e.topicInfoReplicationFactor,
90+
prometheus.GaugeValue,
91+
float64(replicationFactor),
92+
*topic.Topic,
93+
)
94+
if parameter, exists := configsByTopic[*topic.Topic]["min.insync.replicas"]; exists {
95+
if value, err := strconv.ParseFloat(parameter, 64); err == nil {
96+
ch <- prometheus.MustNewConstMetric(
97+
e.topicInfoMinInsyncReplicas,
98+
prometheus.GaugeValue,
99+
value,
100+
*topic.Topic,
101+
)
102+
}
103+
}
104+
if parameter, exists := configsByTopic[*topic.Topic]["retention.ms"]; exists {
105+
if value, err := strconv.ParseFloat(parameter, 64); err == nil {
106+
ch <- prometheus.MustNewConstMetric(
107+
e.topicInfoRetentionMs,
108+
prometheus.GaugeValue,
109+
value,
110+
*topic.Topic,
111+
)
112+
}
113+
}
82114
}
83115
return isOk
84116
}

prometheus/exporter.go

+33-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,15 @@ type Exporter struct {
3232
topicLogDirSize *prometheus.Desc
3333

3434
// Topic / Partition
35-
topicInfo *prometheus.Desc
36-
topicHighWaterMarkSum *prometheus.Desc
37-
partitionHighWaterMark *prometheus.Desc
38-
topicLowWaterMarkSum *prometheus.Desc
39-
partitionLowWaterMark *prometheus.Desc
35+
topicInfo *prometheus.Desc
36+
topicInfoPartitionsCount *prometheus.Desc
37+
topicInfoReplicationFactor *prometheus.Desc
38+
topicInfoMinInsyncReplicas *prometheus.Desc
39+
topicInfoRetentionMs *prometheus.Desc
40+
topicHighWaterMarkSum *prometheus.Desc
41+
partitionHighWaterMark *prometheus.Desc
42+
topicLowWaterMarkSum *prometheus.Desc
43+
partitionLowWaterMark *prometheus.Desc
4044

4145
// Consumer Groups
4246
consumerGroupInfo *prometheus.Desc
@@ -114,6 +118,30 @@ func (e *Exporter) InitializeMetrics() {
114118
labels,
115119
nil,
116120
)
121+
e.topicInfoPartitionsCount = prometheus.NewDesc(
122+
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_partitions_count"),
123+
"Partitions configuration for a given topic",
124+
[]string{"topic_name"},
125+
nil,
126+
)
127+
e.topicInfoReplicationFactor = prometheus.NewDesc(
128+
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_replication_factor"),
129+
"Replication factor configuration for a given topic",
130+
[]string{"topic_name"},
131+
nil,
132+
)
133+
e.topicInfoMinInsyncReplicas = prometheus.NewDesc(
134+
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_min_insync_replicas"),
135+
"Min in-sync replicas configuration for a given topic",
136+
[]string{"topic_name"},
137+
nil,
138+
)
139+
e.topicInfoRetentionMs = prometheus.NewDesc(
140+
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_retention_ms"),
141+
"Retention time for a given topic",
142+
[]string{"topic_name"},
143+
nil,
144+
)
117145
// Partition Low Water Mark
118146
e.partitionLowWaterMark = prometheus.NewDesc(
119147
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_partition_low_water_mark"),

0 commit comments

Comments
 (0)