forked from pmalhaire/xk6-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.go
41 lines (34 loc) · 959 Bytes
/
stats.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
package mqtt
import (
"go.k6.io/k6/js/modules"
"go.k6.io/k6/metrics"
)
type mqttMetrics struct {
SentBytes *metrics.Metric
ReceivedBytes *metrics.Metric
SentMessages *metrics.Metric
ReceivedMessages *metrics.Metric
}
// registerMetrics registers the metrics for the mqtt module in the metrics registry
func registerMetrics(vu modules.VU) (mqttMetrics, error) {
var err error
registry := vu.InitEnv().Registry
m := mqttMetrics{}
m.SentBytes, err = registry.NewMetric("mqtt.sent.bytes", metrics.Counter)
if err != nil {
return m, err
}
m.ReceivedBytes, err = registry.NewMetric("mqtt.received.bytes", metrics.Counter)
if err != nil {
return m, err
}
m.SentMessages, err = registry.NewMetric("mqtt.sent.messages.count", metrics.Counter)
if err != nil {
return m, err
}
m.ReceivedMessages, err = registry.NewMetric("mqtt.received.messages.count", metrics.Counter)
if err != nil {
return m, err
}
return m, nil
}