-
Notifications
You must be signed in to change notification settings - Fork 6
/
metrics.go
41 lines (35 loc) · 1.08 KB
/
metrics.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 diameter
import (
"time"
"go.k6.io/k6/js/modules"
"go.k6.io/k6/metrics"
)
type DiameterMetrics struct {
RequestDuration *metrics.Metric
RequestCount *metrics.Metric
FailedRequestCount *metrics.Metric
}
func registerMetrics(vu modules.VU) DiameterMetrics {
registry := vu.InitEnv().Registry
metrics := DiameterMetrics{
RequestDuration: registry.MustNewMetric("diameter_req_duration", metrics.Trend, metrics.Time),
RequestCount: registry.MustNewMetric("diameter_req_count", metrics.Counter, metrics.Default),
FailedRequestCount: registry.MustNewMetric("diameter_req_failed", metrics.Rate, metrics.Default),
}
return metrics
}
func (c *DiameterClient) reportMetric(metric *metrics.Metric, now time.Time, value float64, tags map[string]string) {
state := c.vu.State()
ctx := c.vu.Context()
if state == nil || ctx == nil {
return
}
metrics.PushIfNotDone(ctx, state.Samples, metrics.Sample{
Time: now,
TimeSeries: metrics.TimeSeries{
Metric: metric,
Tags: metrics.NewRegistry().RootTagSet().WithTagsFromMap(tags),
},
Value: value,
})
}