@@ -10,6 +10,7 @@ import (
10
10
"time"
11
11
12
12
"github.com/prometheus/client_golang/prometheus"
13
+ "github.com/prometheus/client_golang/prometheus/promauto"
13
14
14
15
"errors"
15
16
@@ -37,6 +38,20 @@ type MessageBatch struct {
37
38
Messages []Message `json:"messages"`
38
39
}
39
40
41
+ // Pmx
42
+ type Pmx struct {
43
+ Processed prometheus.Counter
44
+ Queued prometheus.Gauge
45
+ TxBatches prometheus.Counter
46
+ TxFail prometheus.Counter
47
+ DbErr prometheus.Counter
48
+ MsgError prometheus.Counter
49
+ ResponseTime prometheus.Summary
50
+ ResponseTimeAsync prometheus.Summary
51
+ ProcessingTime prometheus.Summary
52
+ ProcessingErrors prometheus.Counter
53
+ }
54
+
40
55
// Config options for rxtx
41
56
type Config struct {
42
57
Interval time.Duration
@@ -45,12 +60,7 @@ type Config struct {
45
60
Logger * zap.Logger
46
61
Receiver string
47
62
Path string
48
- Processed prometheus.Counter
49
- Queued prometheus.Gauge
50
- TxBatches prometheus.Counter
51
- TxFail prometheus.Counter
52
- DbErr prometheus.Counter
53
- MsgError prometheus.Counter
63
+ Pmx Pmx
54
64
}
55
65
56
66
// rtQ private struct see NewQ
@@ -81,6 +91,57 @@ func NewQ(name string, cfg Config) (*rtQ, error) {
81
91
return nil , err
82
92
}
83
93
94
+ // Prometheus Metrics
95
+ cfg .Pmx .Processed = promauto .NewCounter (prometheus.CounterOpts {
96
+ Name : "rxtx_total_messages_received" ,
97
+ Help : "Total number of messages received." ,
98
+ })
99
+
100
+ cfg .Pmx .Queued = promauto .NewGauge (prometheus.GaugeOpts {
101
+ Name : "rxtx_messages_in_queue" ,
102
+ Help : "Number os messages in the queue." ,
103
+ })
104
+
105
+ cfg .Pmx .TxBatches = promauto .NewCounter (prometheus.CounterOpts {
106
+ Name : "rxtx_tx_batches" ,
107
+ Help : "Total number of batch transmissions." ,
108
+ })
109
+
110
+ cfg .Pmx .TxFail = promauto .NewCounter (prometheus.CounterOpts {
111
+ Name : "rxtx_tx_fails" ,
112
+ Help : "Total number of transaction errors." ,
113
+ })
114
+
115
+ cfg .Pmx .DbErr = promauto .NewCounter (prometheus.CounterOpts {
116
+ Name : "rxtx_db_errors" ,
117
+ Help : "Total number database errors." ,
118
+ })
119
+
120
+ cfg .Pmx .MsgError = promauto .NewCounter (prometheus.CounterOpts {
121
+ Name : "rxtx_msg_errors" ,
122
+ Help : "Total number message errors." ,
123
+ })
124
+
125
+ cfg .Pmx .ResponseTime = promauto .NewSummary (prometheus.SummaryOpts {
126
+ Name : "rxtx_response_time" ,
127
+ Help : "Time it took to respond to a post." ,
128
+ })
129
+
130
+ cfg .Pmx .ResponseTimeAsync = promauto .NewSummary (prometheus.SummaryOpts {
131
+ Name : "rxtx_response_time_async" ,
132
+ Help : "Time it took to respond to a async post." ,
133
+ })
134
+
135
+ cfg .Pmx .ProcessingTime = promauto .NewSummary (prometheus.SummaryOpts {
136
+ Name : "rxtx_processing_time" ,
137
+ Help : "Time it took to process a post." ,
138
+ })
139
+
140
+ cfg .Pmx .ProcessingErrors = promauto .NewCounter (prometheus.CounterOpts {
141
+ Name : "rxtx_processing_errors" ,
142
+ Help : "Total number of processing errors." ,
143
+ })
144
+
84
145
mq := make (chan Message , 0 )
85
146
remove := make (chan int , 0 )
86
147
@@ -131,7 +192,7 @@ func (rt *rtQ) getMessageBatch() *MessageBatch {
131
192
stats := bucket .Stats ()
132
193
133
194
// metric: messages_in_queue
134
- rt .cfg .Queued .Set (float64 (stats .KeyN ))
195
+ rt .cfg .Pmx . Queued .Set (float64 (stats .KeyN ))
135
196
136
197
rt .status ("QueueState" , zapcore.Field {
137
198
Key : "TotalRecords" ,
@@ -175,7 +236,7 @@ func (rt *rtQ) getMessageBatch() *MessageBatch {
175
236
176
237
if err != nil {
177
238
// increment metric db_errors
178
- rt .cfg .DbErr .Inc ()
239
+ rt .cfg .Pmx . DbErr .Inc ()
179
240
180
241
rt .cfg .Logger .Error ("bbolt db View error: " + err .Error ())
181
242
}
@@ -251,7 +312,7 @@ func (rt *rtQ) tx() {
251
312
if err != nil {
252
313
253
314
// increment metric tx_fails
254
- rt .cfg .TxFail .Inc ()
315
+ rt .cfg .Pmx . TxFail .Inc ()
255
316
256
317
// transmission failed
257
318
rt .status ("Transmission" , zapcore.Field {
@@ -268,7 +329,7 @@ func (rt *rtQ) tx() {
268
329
}
269
330
270
331
// increment metric tx_batches
271
- rt .cfg .TxBatches .Inc ()
332
+ rt .cfg .Pmx . TxBatches .Inc ()
272
333
273
334
rt .status ("TransmissionComplete" , zapcore.Field {
274
335
Key : "RemovingMessages" ,
@@ -282,7 +343,7 @@ func (rt *rtQ) tx() {
282
343
func (rt * rtQ ) QWrite (msg Message ) error {
283
344
284
345
// increment metric
285
- rt .cfg .Processed .Inc ()
346
+ rt .cfg .Pmx . Processed .Inc ()
286
347
287
348
rt .mq <- msg
288
349
@@ -313,7 +374,7 @@ func messageHandler(db *bolt.DB, mq chan Message, remove chan int) {
313
374
if err != nil {
314
375
return err
315
376
}
316
- b .Put ([]byte (msg .Seq ), buf )
377
+ _ = b .Put ([]byte (msg .Seq ), buf )
317
378
318
379
return nil
319
380
})
@@ -330,7 +391,7 @@ func messageHandler(db *bolt.DB, mq chan Message, remove chan int) {
330
391
// get the first rt.cfg.Batch
331
392
i := 1
332
393
for k , _ := c .First (); k != nil ; k , _ = c .Next () {
333
- c .Delete ()
394
+ _ = c .Delete ()
334
395
i ++
335
396
if i > rmi {
336
397
break
0 commit comments