From c6ff6e6eec04befbc60287d0366767282235d8f7 Mon Sep 17 00:00:00 2001 From: Albin Kauffmann Date: Mon, 30 Jan 2023 17:12:20 +0100 Subject: [PATCH] Add an account_id label in prometheus metrics --- collector/jsz.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/collector/jsz.go b/collector/jsz.go index 15d3184..0f405bd 100644 --- a/collector/jsz.go +++ b/collector/jsz.go @@ -67,6 +67,7 @@ func newJszCollector(system, endpoint string, servers []*CollectedServer) promet var streamLabels []string streamLabels = append(streamLabels, serverLabels...) streamLabels = append(streamLabels, "account") + streamLabels = append(streamLabels, "account_id") streamLabels = append(streamLabels, "stream_name") streamLabels = append(streamLabels, "stream_leader") streamLabels = append(streamLabels, "is_stream_leader") @@ -292,6 +293,7 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) { var consumerName, consumerDesc, consumerLeader string var isMetaLeader, isStreamLeader, isConsumerLeader string var accountName string + var accountId string serverID = server.ID serverName = varz.Name @@ -327,6 +329,7 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) { for _, account := range resp.AccountDetails { accountName = account.Name + accountId = account.Id for _, stream := range account.Streams { streamName = stream.Name if stream.Cluster != nil { @@ -344,7 +347,7 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) { // Server Labels serverID, serverName, clusterName, jsDomain, clusterLeader, isMetaLeader, // Stream Labels - accountName, streamName, streamLeader, isStreamLeader) + accountName, accountId, streamName, streamLeader, isStreamLeader) } ch <- streamMetric(nc.streamMessages, float64(stream.State.Msgs)) ch <- streamMetric(nc.streamBytes, float64(stream.State.Bytes)) @@ -373,7 +376,7 @@ func (nc *jszCollector) Collect(ch chan<- prometheus.Metric) { // Server Labels serverID, serverName, clusterName, jsDomain, clusterLeader, isMetaLeader, // Stream Labels - accountName, streamName, streamLeader, isStreamLeader, + accountName, accountId, streamName, streamLeader, isStreamLeader, // Consumer Labels consumerName, consumerLeader, isConsumerLeader, consumerDesc, )