-
Notifications
You must be signed in to change notification settings - Fork 6
/
metrics.go
119 lines (103 loc) · 2.63 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
108
109
110
111
112
113
114
115
116
117
118
119
package prometheus
import (
"time"
"github.com/prometheus/client_golang/prometheus"
)
type QProxyMetrics struct {
APILatency *prometheus.SummaryVec
APIHits *prometheus.CounterVec
APIErrors *prometheus.CounterVec
Acknowledged *prometheus.CounterVec
Published *prometheus.CounterVec
Received *prometheus.CounterVec
Queued *prometheus.GaugeVec
Inflight *prometheus.GaugeVec
}
// Same as DefObjectives from the golang package, but adding 1.0 as an objective
var SummaryVecObjectives = map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001, 1.0: 0.0}
func NewQProxyMetrics() (QProxyMetrics, error) {
m := QProxyMetrics{}
m.APILatency = prometheus.NewSummaryVec(
prometheus.SummaryOpts{
Namespace: "qproxy",
Name: "api_latency",
Objectives: SummaryVecObjectives,
MaxAge: time.Minute,
},
[]string{"api", "namespace", "name"},
)
if err := prometheus.Register(m.APILatency); err != nil {
return m, err
}
m.APIHits = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "qproxy",
Name: "api_hits",
},
[]string{"api", "namespace", "name"},
)
if err := prometheus.Register(m.APIHits); err != nil {
return m, err
}
m.APIErrors = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "qproxy",
Name: "api_errors",
},
[]string{"api", "namespace", "name", "reason"},
)
if err := prometheus.Register(m.APIErrors); err != nil {
return m, err
}
m.Acknowledged = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "qproxy",
Name: "acknowledged",
},
[]string{"namespace", "name", "true_name"},
)
if err := prometheus.Register(m.Acknowledged); err != nil {
return m, err
}
m.Published = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "qproxy",
Name: "published",
},
[]string{"namespace", "name", "true_name"},
)
if err := prometheus.Register(m.Published); err != nil {
return m, err
}
m.Received = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "qproxy",
Name: "received",
},
[]string{"namespace", "name"},
)
if err := prometheus.Register(m.Received); err != nil {
return m, err
}
m.Queued = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "qproxy",
Name: "queued",
},
[]string{"namespace", "name", "true_name"},
)
if err := prometheus.Register(m.Queued); err != nil {
return m, err
}
m.Inflight = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Namespace: "qproxy",
Name: "inflight",
},
[]string{"namespace", "name", "true_name" },
)
if err := prometheus.Register(m.Inflight); err != nil {
return m, err
}
return m, nil
}