-
Notifications
You must be signed in to change notification settings - Fork 137
/
metrics.go
39 lines (33 loc) · 917 Bytes
/
metrics.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
package job
import "github.com/prometheus/client_golang/prometheus"
type workersQueuesCollector struct {
prometheus.Desc
}
func newWorkersQueuesCollector() prometheus.Collector {
desc := prometheus.NewDesc(
prometheus.BuildFQName("workers", "queues", "len"),
`Len of the workers queues by worker type`,
[]string{"worker_type"},
prometheus.Labels{},
)
return &workersQueuesCollector{*desc}
}
func (i *workersQueuesCollector) Describe(ch chan<- *prometheus.Desc) {
ch <- &i.Desc
}
func (i *workersQueuesCollector) Collect(ch chan<- prometheus.Metric) {
broker := globalJobSystem
for _, workerType := range broker.WorkersTypes() {
count, err := broker.WorkerQueueLen(workerType)
if err != nil {
continue
}
ch <- prometheus.MustNewConstMetric(
&i.Desc, prometheus.GaugeValue, float64(count),
workerType,
)
}
}
func init() {
prometheus.MustRegister(newWorkersQueuesCollector())
}