-
Notifications
You must be signed in to change notification settings - Fork 18
/
prometheus.go
57 lines (52 loc) · 1.39 KB
/
prometheus.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"log"
"net/http"
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promhttp"
)
var (
// OffsetLag is a Prometheus gauge of kafka offset lag
OffsetLag = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "kafka_consumer_group_lag",
Help: "How far behind the consumer group is from the topic head.",
},
[]string{
"topic",
"group",
"partition",
},
)
//Current state of offset by consumer group
CurrentOffset = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "kafka_consumer_group_current_offset",
Help: "Current state of offset by consumer group.",
},
[]string{
"topic",
"group",
"partition",
},
)
// LookupHist is a Prometheus histogram of our kafka offset lookup time
LookupHist = prometheus.NewHistogram(
prometheus.HistogramOpts{
Name: "kafka_consumer_group_lag_lookup_duration_seconds",
Help: "Histogram for the runtime of the offset request.",
Buckets: []float64{.1, .25, .5, 1, 2.5, 5, 10, 15, 30, 60, 120},
},
)
)
func init() {
// Metrics have to be registered to be exposed:
prometheus.MustRegister(CurrentOffset)
prometheus.MustRegister(OffsetLag)
prometheus.MustRegister(LookupHist)
}
func prometheusListen(addr string) {
// Expose the registered metrics via HTTP.
http.Handle("/metrics", promhttp.Handler())
log.Fatal(http.ListenAndServe(addr, nil))
}