-
Notifications
You must be signed in to change notification settings - Fork 211
/
metrics.go
100 lines (94 loc) · 3.13 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
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
package server
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/spacemeshos/go-spacemesh/metrics"
)
const (
namespace = "server"
protoLabel = "protocol"
)
var (
targetQueue = metrics.NewGauge(
"target_queue",
namespace,
"target size of the queue",
[]string{protoLabel},
)
queue = metrics.NewGauge(
"queue",
namespace,
"actual size of the queue",
[]string{protoLabel},
)
targetRps = metrics.NewGauge(
"rps",
namespace,
"target requests per second",
[]string{protoLabel},
)
requests = metrics.NewCounter(
"requests",
namespace,
"requests counter",
[]string{protoLabel, "state"},
)
clientRequests = metrics.NewCounter(
"client_requests",
namespace,
"client request counter",
[]string{protoLabel, "state"})
clientLatency = metrics.NewHistogramWithBuckets(
"client_latency_seconds",
namespace,
"latency since initiating a request",
[]string{protoLabel, "result"},
prometheus.ExponentialBuckets(0.01, 2, 20),
)
serverLatency = metrics.NewHistogramWithBuckets(
"server_latency_seconds",
namespace,
"latency since accepting new stream",
[]string{protoLabel},
prometheus.ExponentialBuckets(0.01, 2, 20),
)
inQueueLatency = metrics.NewHistogramWithBuckets(
"in_queue_latency_seconds",
namespace,
"latency spent in queue",
[]string{protoLabel},
prometheus.ExponentialBuckets(0.01, 2, 20),
)
)
func newTracker(protocol string) *tracker {
return &tracker{
targetQueue: targetQueue.WithLabelValues(protocol),
queue: queue.WithLabelValues(protocol),
targetRps: targetRps.WithLabelValues(protocol),
completed: requests.WithLabelValues(protocol, "completed"),
failed: requests.WithLabelValues(protocol, "failed"),
accepted: requests.WithLabelValues(protocol, "accepted"),
dropped: requests.WithLabelValues(protocol, "dropped"),
clientSucceeded: clientRequests.WithLabelValues(protocol, "succeeded"),
clientFailed: clientRequests.WithLabelValues(protocol, "failed"),
clientServerError: clientRequests.WithLabelValues(protocol, "server_error"),
inQueueLatency: inQueueLatency.WithLabelValues(protocol),
serverLatency: serverLatency.WithLabelValues(protocol),
clientLatency: clientLatency.WithLabelValues(protocol, "success"),
clientLatencyFailure: clientLatency.WithLabelValues(protocol, "failure"),
}
}
type tracker struct {
targetQueue prometheus.Gauge
queue prometheus.Gauge
targetRps prometheus.Gauge
completed prometheus.Counter
failed prometheus.Counter
accepted prometheus.Counter
dropped prometheus.Counter
clientSucceeded prometheus.Counter
clientFailed prometheus.Counter
clientServerError prometheus.Counter
inQueueLatency prometheus.Observer
serverLatency prometheus.Observer
clientLatency, clientLatencyFailure prometheus.Observer
}