This repository has been archived by the owner on Nov 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
metrics.go
107 lines (94 loc) · 3.31 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
101
102
103
104
105
106
107
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
)
const (
// Counters & CounterVectors
CntGatewayIncomingHttpMessage = "gateway_incoming_http_message"
CntGatewayIncomingWebsocketMessage = "gateway_incoming_websocket_message"
CntGatewayOutgoingHttpMessage = "gateway_outgoing_http_message"
CntGatewayOutgoingWebsocketMessage = "gateway_outgoing_websocket_message"
CntTunnelIncomingMessage = "tunnel_incoming_message"
CntTunnelOutgoingMessage = "tunnel_outgoing_message"
// Gauges & GaugeVectors
GaugeActiveWebsocketConnections = "gateway_active_websocket_conns"
// Histograms
HistGatewayRequestTime = "gateway_request_time"
HistTunnelRequestTime = "tunnel_request_time"
HistTunnelRoundtripTime = "tunnel_roundtrip_time"
)
var (
_Prom *Prometheus
SizeBucketKB = []float64{1, 5, 10, 20, 40, 80, 160, 320, 640, 1280, 2560}
TimeBucketMS = []float64{0.1, 0.5, 1, 10, 20, 50, 100, 500, 1000, 2000, 3000, 5000}
TimeBucketMicroS = []float64{1, 2, 5, 10, 20, 50, 100, 200, 300, 400, 500, 1000, 2000, 5000, 10000}
)
func Init(constLabels map[string]string) {
if _Prom != nil {
return
}
_Prom = NewPrometheus("rony", constLabels)
_Prom.RegisterCounter(CntGatewayIncomingHttpMessage, "number of incoming http messages", nil)
_Prom.RegisterCounter(CntGatewayOutgoingHttpMessage, "number of outgoing http messages", nil)
_Prom.RegisterCounter(CntGatewayIncomingWebsocketMessage, "number of incoming websocket messages", nil)
_Prom.RegisterCounter(CntGatewayOutgoingWebsocketMessage, "number of outgoing websocket messages", nil)
_Prom.RegisterCounter(CntTunnelIncomingMessage, "number of incoming messages", nil)
_Prom.RegisterCounter(CntTunnelOutgoingMessage, "number of outgoing messages", nil)
_Prom.RegisterGauge(GaugeActiveWebsocketConnections, "number of gateway active websocket connections", nil)
_Prom.RegisterHistogram(HistGatewayRequestTime, "the amount of process time for gateway requests", TimeBucketMS, nil)
_Prom.RegisterHistogram(HistTunnelRequestTime, "the amount of process time for tunnel requests", TimeBucketMS, nil)
_Prom.RegisterHistogram(HistTunnelRoundtripTime, "the roundtrip of a execute remote command", TimeBucketMS, nil)
}
func Register(registerer prometheus.Registerer) {
for _, m := range _Prom.counters {
registerer.MustRegister(m)
}
for _, m := range _Prom.counterVectors {
registerer.MustRegister(m)
}
for _, m := range _Prom.gauges {
registerer.MustRegister(m)
}
for _, m := range _Prom.gaugeVectors {
registerer.MustRegister(m)
}
for _, m := range _Prom.histograms {
registerer.MustRegister(m)
}
}
func IncCounter(name string) {
if _Prom == nil {
return
}
_Prom.Counter(name).Inc()
}
func InCounterVec(name string, labelValues ...string) {
if _Prom == nil {
return
}
_Prom.CounterVec(name).WithLabelValues(labelValues...).Inc()
}
func AddCounter(name string, v float64) {
if _Prom == nil {
return
}
_Prom.Counter(name).Add(v)
}
func AddCounterVec(name string, v float64, labelValues ...string) {
if _Prom == nil {
return
}
_Prom.CounterVec(name).WithLabelValues(labelValues...).Add(v)
}
func SetGauge(name string, v float64) {
if _Prom == nil {
return
}
_Prom.Gauge(name).Set(v)
}
func ObserveHistogram(name string, v float64) {
if _Prom == nil {
return
}
_Prom.Histogram(name).Observe(v)
}