-
Notifications
You must be signed in to change notification settings - Fork 5
/
exporter.go
323 lines (290 loc) · 6.95 KB
/
exporter.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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
package main
import (
"github.com/aliyun/alibaba-cloud-sdk-go/services/cms"
"github.com/prometheus/client_golang/prometheus"
)
const (
namespace = "cloudmonitor"
)
// CloudmonitorExporter collects metrics from Aliyun via cms API
type CloudmonitorExporter struct {
client *cms.Client
// nat gateway
netTxRate *prometheus.Desc
netTxRatePercent *prometheus.Desc
snatConnections *prometheus.Desc
// slb dashbaord
activeConnection *prometheus.Desc
packetRX *prometheus.Desc
packetTX *prometheus.Desc
trafficRX *prometheus.Desc
trafficTX *prometheus.Desc
newConnection *prometheus.Desc
maxConnection *prometheus.Desc
dropConnection *prometheus.Desc
dropPacketRX *prometheus.Desc
dropPacketTX *prometheus.Desc
dropTrafficRX *prometheus.Desc
dropTrafficTX *prometheus.Desc
qps *prometheus.Desc
rt *prometheus.Desc
statusCode5xx *prometheus.Desc
upstreamCode4xx *prometheus.Desc
upstreamCode5xx *prometheus.Desc
upstreamRt *prometheus.Desc
// rds dashbaord
cpuUsage *prometheus.Desc
connectionUsage *prometheus.Desc
activeSessions *prometheus.Desc
}
// NewExporter instantiate an CloudmonitorExport
func NewExporter(c *cms.Client) *CloudmonitorExporter {
return &CloudmonitorExporter{
client: c,
// nat gateway
netTxRate: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "net_tx_rate", "bytes"),
"Outbound bandwith of gateway in bits/s",
[]string{
"id",
},
nil,
),
netTxRatePercent: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "net_tx_rate", "percent"),
"Outbound bandwith of gateway used in percentage",
[]string{
"id",
},
nil,
),
snatConnections: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "snat", "connections"),
"Max number of snat connections per minute",
[]string{
"id",
},
nil,
),
// slb dashboard
activeConnection: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "active_connection"),
"Number of active connections per minute",
[]string{
"id",
"port",
"vip",
},
nil,
),
packetRX: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "packet_rx_average"),
"Average packets received per second",
[]string{
"id",
"port",
"vip",
},
nil,
),
packetTX: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "packet_tx_average"),
"Average packets sent per second",
[]string{
"id",
"port",
"vip",
},
nil,
),
trafficRX: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "traffic_rx_average"),
"Average traffic received per second",
[]string{
"id",
"port",
"vip",
},
nil,
),
trafficTX: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "traffic_tx_average"),
"Average traffic sent per second",
[]string{
"id",
"port",
"vip",
},
nil,
),
newConnection: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "slb", "new_connection_average"),
"Average number of new connections created per second",
[]string{
"id",
"port",
"vip",
},
nil,
),
// rds dashbaord
cpuUsage: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "rds", "cpu_usage_average"),
"CPU usage per minute",
[]string{
"id",
},
nil,
),
connectionUsage: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "rds", "connection_usage"),
"Connection usage per minute",
[]string{
"id",
},
nil,
),
activeSessions: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "rds", "active_sessions"),
"Active Sessions per minute",
[]string{
"id",
},
nil,
),
}
}
// Describe describes all the metrics exported by the cloudmonitor exporter.
// It implements prometheus.Collector.
func (e *CloudmonitorExporter) Describe(ch chan<- *prometheus.Desc) {
// nat gateway
ch <- e.netTxRate
ch <- e.netTxRatePercent
ch <- e.snatConnections
// slb dashboard
ch <- e.activeConnection
ch <- e.packetRX
ch <- e.packetTX
ch <- e.trafficRX
ch <- e.trafficTX
ch <- e.newConnection
// rds dashbaord
ch <- e.cpuUsage
ch <- e.connectionUsage
ch <- e.activeSessions
}
// Collect fetches the metrics from Aliyun cms
// It implements prometheus.Collector.
func (e *CloudmonitorExporter) Collect(ch chan<- prometheus.Metric) {
natGateway := NewNatGateway(e.client)
slbDashboard := NewSLBDashboard(e.client)
rdsDashboard := NewRDSDashboard(e.client)
for _, point := range natGateway.retrieveNetTxRate() {
ch <- prometheus.MustNewConstMetric(
e.netTxRate,
prometheus.GaugeValue,
float64(point.Value),
point.InstanceId,
)
}
for _, point := range natGateway.retrieveNetTxRatePercent() {
ch <- prometheus.MustNewConstMetric(
e.netTxRatePercent,
prometheus.GaugeValue,
float64(point.Value),
point.InstanceId,
)
}
for _, point := range natGateway.retrieveSnatConn() {
ch <- prometheus.MustNewConstMetric(
e.snatConnections,
prometheus.GaugeValue,
float64(point.Maximum),
point.InstanceId,
)
}
for _, point := range slbDashboard.retrieveActiveConnection() {
ch <- prometheus.MustNewConstMetric(
e.activeConnection,
prometheus.GaugeValue,
float64(point.Maximum),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range slbDashboard.retrievePacketRX() {
ch <- prometheus.MustNewConstMetric(
e.packetRX,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range slbDashboard.retrievePacketTX() {
ch <- prometheus.MustNewConstMetric(
e.packetTX,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range slbDashboard.retrieveTrafficRX() {
ch <- prometheus.MustNewConstMetric(
e.trafficRX,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range slbDashboard.retrieveTrafficTX() {
ch <- prometheus.MustNewConstMetric(
e.trafficTX,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range slbDashboard.retrieveNewConnection() {
ch <- prometheus.MustNewConstMetric(
e.newConnection,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
point.Port,
point.Vip,
)
}
for _, point := range rdsDashboard.retrieveCPUUsage() {
ch <- prometheus.MustNewConstMetric(
e.cpuUsage,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
)
}
for _, point := range rdsDashboard.retrieveConnectionUsage() {
ch <- prometheus.MustNewConstMetric(
e.connectionUsage,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
)
}
for _, point := range rdsDashboard.retrieveActiveSessions() {
ch <- prometheus.MustNewConstMetric(
e.activeSessions,
prometheus.GaugeValue,
float64(point.Average),
point.InstanceId,
)
}
}