@@ -8,20 +8,43 @@ import (
8
8
9
9
const Name = "kafka_konsumer"
10
10
11
- type metricCollector struct {
11
+ type MetricCollector struct {
12
12
consumerMetric * ConsumerMetric
13
13
14
14
totalUnprocessedMessagesCounter * prometheus.Desc
15
15
totalProcessedMessagesCounter * prometheus.Desc
16
16
}
17
17
18
- func (s * metricCollector ) Describe (ch chan <- * prometheus.Desc ) {
18
+ func NewMetricCollector (metricPrefix string , consumerMetric * ConsumerMetric ) * MetricCollector {
19
+ if metricPrefix == "" {
20
+ metricPrefix = Name
21
+ }
22
+
23
+ return & MetricCollector {
24
+ consumerMetric : consumerMetric ,
25
+
26
+ totalProcessedMessagesCounter : prometheus .NewDesc (
27
+ prometheus .BuildFQName (metricPrefix , "processed_messages_total" , "current" ),
28
+ "Total number of processed messages." ,
29
+ emptyStringList ,
30
+ nil ,
31
+ ),
32
+ totalUnprocessedMessagesCounter : prometheus .NewDesc (
33
+ prometheus .BuildFQName (metricPrefix , "unprocessed_messages_total" , "current" ),
34
+ "Total number of unprocessed messages." ,
35
+ emptyStringList ,
36
+ nil ,
37
+ ),
38
+ }
39
+ }
40
+
41
+ func (s * MetricCollector ) Describe (ch chan <- * prometheus.Desc ) {
19
42
prometheus .DescribeByCollect (s , ch )
20
43
}
21
44
22
45
var emptyStringList []string
23
46
24
- func (s * metricCollector ) Collect (ch chan <- prometheus.Metric ) {
47
+ func (s * MetricCollector ) Collect (ch chan <- prometheus.Metric ) {
25
48
ch <- prometheus .MustNewConstMetric (
26
49
s .totalProcessedMessagesCounter ,
27
50
prometheus .CounterValue ,
@@ -37,31 +60,12 @@ func (s *metricCollector) Collect(ch chan<- prometheus.Metric) {
37
60
)
38
61
}
39
62
40
- func newMetricCollector (consumerMetric * ConsumerMetric ) * metricCollector {
41
- return & metricCollector {
42
- consumerMetric : consumerMetric ,
43
-
44
- totalProcessedMessagesCounter : prometheus .NewDesc (
45
- prometheus .BuildFQName (Name , "processed_messages_total" , "current" ),
46
- "Total number of processed messages." ,
47
- emptyStringList ,
48
- nil ,
49
- ),
50
- totalUnprocessedMessagesCounter : prometheus .NewDesc (
51
- prometheus .BuildFQName (Name , "unprocessed_messages_total" , "current" ),
52
- "Total number of unprocessed messages." ,
53
- emptyStringList ,
54
- nil ,
55
- ),
56
- }
57
- }
58
-
59
63
func NewMetricMiddleware (cfg * ConsumerConfig ,
60
64
app * fiber.App ,
61
65
consumerMetric * ConsumerMetric ,
62
66
metricCollectors ... prometheus.Collector ,
63
67
) (func (ctx * fiber.Ctx ) error , error ) {
64
- prometheus .DefaultRegisterer .MustRegister (newMetricCollector ( consumerMetric ))
68
+ prometheus .DefaultRegisterer .MustRegister (NewMetricCollector ( cfg . MetricPrefix , consumerMetric ))
65
69
prometheus .DefaultRegisterer .MustRegister (metricCollectors ... )
66
70
67
71
fiberPrometheus := fiberprometheus .New (cfg .Reader .GroupID )
0 commit comments