Skip to content

Commit

Permalink
[INTERNAL] - Export numerical kafka_topic_info parameters/labels as i…
Browse files Browse the repository at this point in the history
…ndividual 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 Sep 20, 2021
1 parent 734cb59 commit 6872cdb
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 6 deletions.
35 changes: 34 additions & 1 deletion prometheus/collect_topic_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,47 @@ func (e *Exporter) collectTopicInfo(ctx context.Context, ch chan<- prometheus.Me
labelsValues = append(labelsValues, strconv.Itoa(partitionCount))
labelsValues = append(labelsValues, strconv.Itoa(replicationFactor))
for _, key := range e.minionSvc.Cfg.Topics.InfoMetric.ConfigKeys {
labelsValues = append(labelsValues, getOrDefault(configsByTopic[topic.Topic], key, "N/A"))
labelsValues = append(labelsValues, getOrDefault(configsByTopic[topic.Topic], key, "N/A"))
}
ch <- prometheus.MustNewConstMetric(
e.topicInfo,
prometheus.GaugeValue,
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 6872cdb

Please sign in to comment.