-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.go
68 lines (58 loc) · 1.46 KB
/
monitor.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
58
59
60
61
62
63
64
65
66
67
68
package delayq
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
subsystem = "status"
)
type statsGetter interface {
Status() Status
}
type Collector = prometheus.Collector
type statsCollector struct {
getter statsGetter
queueLengthDesc *prometheus.Desc
opts *Options
}
func newCollector(getter statsGetter, opts *Options) Collector {
return &statsCollector{
getter: getter,
opts: opts,
queueLengthDesc: prometheus.NewDesc(
prometheus.BuildFQName(opts.GetName(), subsystem, "queue_length"),
"Length of topic queue.",
[]string{"queue"},
prometheus.Labels{},
),
}
}
func (c statsCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- c.queueLengthDesc
}
func (c statsCollector) Collect(ch chan<- prometheus.Metric) {
stats := c.getter.Status()
for k, v := range stats.QueueLength {
ch <- prometheus.MustNewConstMetric(
c.queueLengthDesc,
prometheus.GaugeValue,
float64(v),
k,
)
}
}
func monitorCount(metric string, topic string, opts *Options, values ...int) {
if opts.GetMonitorCounter() == nil {
return
}
var value int64 = 1
if len(values) > 0 {
value = int64(values[0])
}
opts.GetMonitorCounter()(metric, value, map[string]string{"Queue": topic})
}
func (q *baseQueue) monitorCount(metric string, values ...int) {
monitorCount(metric, q.topic, q.opts, values...)
}
func (q *queue) monitorCounter(metric, topic string, values ...int) {
monitorCount(metric, topic, q.opts, values...)
}