-
Notifications
You must be signed in to change notification settings - Fork 4
/
stats.go
133 lines (107 loc) · 2.49 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package xk6_dns
import (
"context"
"fmt"
"time"
"go.k6.io/k6/lib"
"go.k6.io/k6/lib/metrics"
"go.k6.io/k6/stats"
)
var (
DialCount = stats.New("dns.dial.count", stats.Counter)
DialError = stats.New("dns.dial.error", stats.Counter)
RequestCount = stats.New("dns.request.count", stats.Counter)
RequestError = stats.New("dns.request.error", stats.Counter)
ResponseTime = stats.New("dns.response.time", stats.Trend, stats.Time)
)
func reportDial(ctx context.Context) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: DialCount,
Time: now,
Value: float64(1),
})
return nil
}
func reportDialError(ctx context.Context) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: DialError,
Time: now,
Value: float64(1),
})
return nil
}
func reportRequest(ctx context.Context) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RequestCount,
Time: now,
Value: float64(1),
})
return nil
}
func reportRequestError(ctx context.Context) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: RequestError,
Time: now,
Value: float64(1),
})
return nil
}
func reportResponseTime(ctx context.Context, rtt time.Duration) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: ResponseTime,
Time: now,
Value: float64(rtt.Milliseconds()),
})
return nil
}
func reportDataSent(ctx context.Context, value float64) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: metrics.DataSent,
Time: now,
Value: value,
})
return nil
}
func reportDataReceived(ctx context.Context, value float64) error {
state := lib.GetState(ctx)
if state == nil {
return fmt.Errorf("state is nil")
}
now := time.Now()
stats.PushIfNotDone(ctx, state.Samples, stats.Sample{
Metric: metrics.DataReceived,
Time: now,
Value: value,
})
return nil
}