forked from pmalhaire/xk6-mqtt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstats.go
More file actions
53 lines (46 loc) · 1.19 KB
/
Copy pathstats.go
File metadata and controls
53 lines (46 loc) · 1.19 KB
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 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
}
// registerMetrics registers the metrics for the mqtt module in the metrics registry
func registerMetrics(vu modules.VU) (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("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
}
m.TagsAndMeta = &metrics.TagsAndMeta{
Tags: registry.RootTagSet(),
}
return m, nil
}