Skip to content

Commit

Permalink
[INTERNAL] Export numerical kafka_topic_info parameters/labels as ind…
Browse files Browse the repository at this point in the history
…ividual 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
  • Loading branch information
amuraru committed Dec 22, 2021
1 parent 1b852fe commit bd76176
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 5 deletions.
32 changes: 32 additions & 0 deletions prometheus/collect_topic_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,38 @@ func (e *Exporter) collectTopicInfo(ctx context.Context, ch chan<- prometheus.Me
float64(1),
labelsValues...,
)
ch <- prometheus.MustNewConstMetric(
e.topicInfoPartitionsCount,
prometheus.GaugeValue,
float64(partitionCount),
*topic.Topic,
)
ch <- prometheus.MustNewConstMetric(
e.topicInfoReplicationFactor,
prometheus.GaugeValue,
float64(replicationFactor),
*topic.Topic,
)
if parameter, exists := configsByTopic[*topic.Topic]["min.insync.replicas"]; exists {
if value, err := strconv.ParseFloat(parameter, 64); err == nil {
ch <- prometheus.MustNewConstMetric(
e.topicInfoMinInsyncReplicas,
prometheus.GaugeValue,
value,
*topic.Topic,
)
}
}
if parameter, exists := configsByTopic[*topic.Topic]["retention.ms"]; exists {
if value, err := strconv.ParseFloat(parameter, 64); err == nil {
ch <- prometheus.MustNewConstMetric(
e.topicInfoRetentionMs,
prometheus.GaugeValue,
value,
*topic.Topic,
)
}
}
}
return isOk
}
Expand Down
38 changes: 33 additions & 5 deletions prometheus/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,15 @@ type Exporter struct {
topicLogDirSize *prometheus.Desc

// Topic / Partition
topicInfo *prometheus.Desc
topicHighWaterMarkSum *prometheus.Desc
partitionHighWaterMark *prometheus.Desc
topicLowWaterMarkSum *prometheus.Desc
partitionLowWaterMark *prometheus.Desc
topicInfo *prometheus.Desc
topicInfoPartitionsCount *prometheus.Desc
topicInfoReplicationFactor *prometheus.Desc
topicInfoMinInsyncReplicas *prometheus.Desc
topicInfoRetentionMs *prometheus.Desc
topicHighWaterMarkSum *prometheus.Desc
partitionHighWaterMark *prometheus.Desc
topicLowWaterMarkSum *prometheus.Desc
partitionLowWaterMark *prometheus.Desc

// Consumer Groups
consumerGroupInfo *prometheus.Desc
Expand Down Expand Up @@ -114,6 +118,30 @@ func (e *Exporter) InitializeMetrics() {
labels,
nil,
)
e.topicInfoPartitionsCount = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_partitions_count"),
"Partitions configuration for a given topic",
[]string{"topic_name"},
nil,
)
e.topicInfoReplicationFactor = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_replication_factor"),
"Replication factor configuration for a given topic",
[]string{"topic_name"},
nil,
)
e.topicInfoMinInsyncReplicas = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_min_insync_replicas"),
"Min in-sync replicas configuration for a given topic",
[]string{"topic_name"},
nil,
)
e.topicInfoRetentionMs = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_info_retention_ms"),
"Retention time for a given topic",
[]string{"topic_name"},
nil,
)
// Partition Low Water Mark
e.partitionLowWaterMark = prometheus.NewDesc(
prometheus.BuildFQName(e.cfg.Namespace, "kafka", "topic_partition_low_water_mark"),
Expand Down

0 comments on commit bd76176

Please sign in to comment.