-
Notifications
You must be signed in to change notification settings - Fork 24
/
metrics.go
166 lines (139 loc) · 4.82 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package pusher
import (
"strconv"
"github.com/prometheus/client_golang/prometheus"
)
const (
LabelValueMetrics = "metrics"
LabelValueLogs = "logs"
LabelValueClient = "client"
LabelValueRetryExhausted = "retry_exhausted"
LabelValueTenant = "tenant"
)
// Metrics contains the prometheus Metrics for a publisher.
type Metrics struct {
PushCounter *prometheus.CounterVec
ErrorCounter *prometheus.CounterVec
BytesOut *prometheus.CounterVec
FailedCounter *prometheus.CounterVec
RetriesCounter *prometheus.CounterVec
// For experimental publisher only
DroppedCounter *prometheus.CounterVec
ResponseCounter *prometheus.CounterVec
InstalledHandlers prometheus.Gauge
}
var (
labelsWithTenantType = []string{"regionID", "tenantID", "type"}
labelsWithTenantTypeStatus = []string{"regionID", "tenantID", "type", "status"}
labelsWithTenantTypeReason = []string{"regionID", "tenantID", "type", "reason"}
)
// NewMetrics returns a new set of publisher metrics registered in the given registerer.
func NewMetrics(promRegisterer prometheus.Registerer) (m Metrics) {
m.PushCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "push_total",
Help: "Total number of push events by type.",
},
labelsWithTenantType)
promRegisterer.MustRegister(m.PushCounter)
m.ErrorCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "push_errors_total",
Help: "Total number of push errors by type and status.",
},
labelsWithTenantTypeStatus)
promRegisterer.MustRegister(m.ErrorCounter)
m.FailedCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "push_failed_total",
Help: "Total number of push failures by type.",
},
labelsWithTenantTypeReason)
promRegisterer.MustRegister(m.FailedCounter)
m.BytesOut = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "push_bytes",
Help: "Total number of bytes pushed by type.",
},
labelsWithTenantType)
promRegisterer.MustRegister(m.BytesOut)
m.RetriesCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "retries_total",
Help: "Total number of retries performed by type.",
},
labelsWithTenantType)
promRegisterer.MustRegister(m.RetriesCounter)
m.DroppedCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "drop_total",
Help: "Total number of results dropped by type.",
},
labelsWithTenantType)
promRegisterer.MustRegister(m.DroppedCounter)
m.ResponseCounter = prometheus.NewCounterVec(
prometheus.CounterOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "responses_total",
Help: "Total number of responses received by type and status code.",
},
labelsWithTenantTypeStatus)
promRegisterer.MustRegister(m.ResponseCounter)
m.InstalledHandlers = prometheus.NewGauge(
prometheus.GaugeOpts{
Namespace: "sm_agent",
Subsystem: "publisher",
Name: "handlers_total",
Help: "Total number of installed publisher handlers.",
},
)
promRegisterer.MustRegister(m.InstalledHandlers)
return m
}
// WithTenant returns a new set of Metrics with the local and region ID labels
// already included.
func (m Metrics) WithTenant(localID int64, regionID int) Metrics {
labels := prometheus.Labels{
"regionID": strconv.FormatInt(int64(regionID), 10),
"tenantID": strconv.FormatInt(localID, 10),
}
return Metrics{
PushCounter: m.PushCounter.MustCurryWith(labels),
ErrorCounter: m.ErrorCounter.MustCurryWith(labels),
BytesOut: m.BytesOut.MustCurryWith(labels),
FailedCounter: m.FailedCounter.MustCurryWith(labels),
RetriesCounter: m.RetriesCounter.MustCurryWith(labels),
DroppedCounter: m.DroppedCounter.MustCurryWith(labels),
ResponseCounter: m.ResponseCounter.MustCurryWith(labels),
InstalledHandlers: m.InstalledHandlers,
}
}
// WithType returns a new set of Metrics with the given type label.
func (m Metrics) WithType(t string) Metrics {
var typeLabels = prometheus.Labels{
"type": t,
}
return Metrics{
PushCounter: m.PushCounter.MustCurryWith(typeLabels),
ErrorCounter: m.ErrorCounter.MustCurryWith(typeLabels),
BytesOut: m.BytesOut.MustCurryWith(typeLabels),
FailedCounter: m.FailedCounter.MustCurryWith(typeLabels),
RetriesCounter: m.RetriesCounter.MustCurryWith(typeLabels),
DroppedCounter: m.DroppedCounter.MustCurryWith(typeLabels),
ResponseCounter: m.ResponseCounter.MustCurryWith(typeLabels),
InstalledHandlers: m.InstalledHandlers,
}
}