-
Notifications
You must be signed in to change notification settings - Fork 38
/
stats.go
61 lines (52 loc) · 1.4 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package mqtt
import (
"errors"
"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
TagsAndMeta *metrics.TagsAndMeta
}
type mqttMetricsLabels struct {
SentBytesLabel string
ReceivedBytesLabel string
SentMessagesCountLabel string
ReceivedMessagesCountLabel string
}
// registerMetrics registers the metrics for the mqtt module in the metrics registry
func registerMetrics(vu modules.VU, labels mqttMetricsLabels) (mqttMetrics, error) {
var err error
m := mqttMetrics{}
env := vu.InitEnv()
if env == nil {
return m, errors.New("missing env")
}
registry := env.Registry
if registry == nil {
return m, errors.New("missing registry")
}
m.SentBytes, err = registry.NewMetric(labels.SentBytesLabel, metrics.Counter)
if err != nil {
return m, err
}
m.ReceivedBytes, err = registry.NewMetric(labels.ReceivedBytesLabel, metrics.Counter)
if err != nil {
return m, err
}
m.SentMessages, err = registry.NewMetric(labels.SentMessagesCountLabel, metrics.Counter)
if err != nil {
return m, err
}
m.ReceivedMessages, err = registry.NewMetric(labels.ReceivedMessagesCountLabel, metrics.Counter)
if err != nil {
return m, err
}
m.TagsAndMeta = &metrics.TagsAndMeta{
Tags: registry.RootTagSet(),
}
return m, nil
}