-
Notifications
You must be signed in to change notification settings - Fork 13
/
collector.go
53 lines (44 loc) · 1.32 KB
/
collector.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
package internal
import "github.com/prometheus/client_golang/prometheus"
type Collector struct {
cronsumerMetric *CronsumerMetric
totalRetriedMessagesCounter *prometheus.Desc
totalDiscardedMessagesCounter *prometheus.Desc
}
func NewCollector(metricPrefix string, cronsumerMetric *CronsumerMetric) *Collector {
if metricPrefix == "" {
metricPrefix = Name
}
return &Collector{
cronsumerMetric: cronsumerMetric,
totalRetriedMessagesCounter: prometheus.NewDesc(
prometheus.BuildFQName(metricPrefix, "retried_messages_total", "current"),
"Total number of retried messages.",
[]string{},
nil,
),
totalDiscardedMessagesCounter: prometheus.NewDesc(
prometheus.BuildFQName(metricPrefix, "discarded_messages_total", "current"),
"Total number of discarded messages.",
[]string{},
nil,
),
}
}
func (s *Collector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(s, ch)
}
func (s *Collector) Collect(ch chan<- prometheus.Metric) {
ch <- prometheus.MustNewConstMetric(
s.totalRetriedMessagesCounter,
prometheus.CounterValue,
float64(s.cronsumerMetric.TotalRetriedMessagesCounter),
[]string{}...,
)
ch <- prometheus.MustNewConstMetric(
s.totalDiscardedMessagesCounter,
prometheus.CounterValue,
float64(s.cronsumerMetric.TotalDiscardedMessagesCounter),
[]string{}...,
)
}