feat(go): expose kafka consumer lag metrics

This commit is contained in:
lingniu
2026-07-02 19:23:01 +08:00
parent 41ff0bcef4
commit 1f4a23ff69
9 changed files with 63 additions and 3 deletions

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"net/http"
"sort"
"strconv"
"strings"
"sync"
)
@@ -69,6 +70,17 @@ func (r *Registry) AddGauge(name string, labels Labels, value float64) {
r.gauges[name][key] += value
}
func (r *Registry) SetKafkaLag(name string, topic string, partition int, offset int64, highWaterMark int64) {
lag := highWaterMark - offset - 1
if lag < 0 {
lag = 0
}
r.SetGauge(name, Labels{
"topic": topic,
"partition": strconv.Itoa(partition),
}, float64(lag))
}
func (r *Registry) Render() string {
if r == nil {
return ""