@@ -13,6 +13,7 @@ for [segmentio/kafka-go](github.com/segmentio/kafka-go) native go client.
1313* [ Blue-Green for segmentio Kafka client] ( #blue-green-for-segmentio-kafka-client- )
1414 * [ Usage examples] ( #usage-examples )
1515 * [ Simple consumer creation and polling] ( #simple-consumer-creation-and-polling )
16+ * [ Metrics] ( #metrics )
1617 * [ Migration to Blue Green 2] ( #migration-to-blue-green-2 )
1718<!-- TOC -->
1819
@@ -96,5 +97,35 @@ func processMsg(ctx context.Context, consumer *bgKafka.BgConsumer, message bgKaf
9697}
9798~~~
9899
100+ ### Metrics
101+
102+ Blue-green kafka consumer collects own metrics set.
103+ Metrics are updating on messages poll and offset commit (interaction with message broker).
104+
105+ Values of each metric are split by partitions and contains data only from partitions assigned to this consumer.
106+
107+ Metrics usage example:
108+
109+ ``` go
110+ // Use Stats() method to receive metrics snapshot.
111+ metrics := consumer.Stats ()
112+
113+ // Call GetByPartitions() method for required metric to get map[int]in64, where key is a partition number
114+ lags := metrics.Lag .GetByPartitions ()
115+ for partition , lag := range lags {
116+ logger.Info (" Lag on partition %d : %d " , partition, lag)
117+ }
118+
119+ // Be aware that metric for each partition is updating on poll or commit.
120+ // It means that before that after consumer init metrics may be empty
121+ _ , commitOffsetExists := metrics.CommitOffset .GetByPartitions ()[0 ]
122+ if !commitOffsetExists {
123+ logger.Info (" No offest has been commited for partition 0 yet" )
124+ }
125+ ```
126+
127+ You can find full list of supported metrics and its description
128+ in [ metrics.go] ( https://github.com/Netcracker/qubership-core-lib-go-bg-kafka/blob/main/metrics.go#L43 )
129+
99130## Migration to Blue Green 2
100131See details [ here] ( docs/migration.md )
0 commit comments