-
Notifications
You must be signed in to change notification settings - Fork 211
/
metrics.go
78 lines (72 loc) · 2.17 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
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"},
)
clientLatency = metrics.NewHistogramWithBuckets(
"client_latency_seconds",
namespace,
"latency since initiating a request",
[]string{protoLabel, "result"},
prometheus.ExponentialBuckets(0.01, 2, 10),
)
serverLatency = metrics.NewHistogramWithBuckets(
"server_latency_seconds",
namespace,
"latency since accepting new stream",
[]string{protoLabel},
prometheus.ExponentialBuckets(0.01, 2, 10),
)
)
func newTracker(protocol string) *tracker {
return &tracker{
targetQueue: targetQueue.WithLabelValues(protocol),
queue: queue.WithLabelValues(protocol),
targetRps: targetRps.WithLabelValues(protocol),
completed: requests.WithLabelValues(protocol, "completed"),
accepted: requests.WithLabelValues(protocol, "accepted"),
dropped: requests.WithLabelValues(protocol, "dropped"),
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
accepted prometheus.Counter
dropped prometheus.Counter
serverLatency prometheus.Observer
clientLatency, clientLatencyFailure prometheus.Observer
}