forked from elubow/mesos_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
slave.go
274 lines (266 loc) · 8.72 KB
/
slave.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
package main
import (
"github.com/prometheus/client_golang/prometheus"
)
func newSlaveCollector(httpClient *httpClient) prometheus.Collector {
metrics := map[prometheus.Collector]func(metricMap, prometheus.Collector) error{
// CPU/Disk/Mem resources in free/used
gauge("slave", "cpus", "Current CPU resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/cpus_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/cpus_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "cpus_revocable", "Current revocable CPU resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/cpus_revocable_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/cpus_revocable_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "mem", "Current memory resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/mem_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/mem_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "mem_revocable", "Current revocable memory resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/mem_revocable_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/mem_revocable_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "gpus", "Current GPU resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/gpus_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/gpus_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "gpus_revocable", "Current revocable GPUS resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/gpus_revocable_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/gpus_revocable_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "disk", "Current disk resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/disk_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/disk_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("slave", "disk_revocable", "Current disk resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["slave/disk_revocable_total"]
if !ok {
return errNotFoundInMap
}
used, ok := m["slave/disk_revocable_used"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
// Slave stats about uptime and connectivity
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "slave",
Name: "registered",
Help: "1 if slave is registered with master, 0 if not.",
}): func(m metricMap, c prometheus.Collector) error {
registered, ok := m["slave/registered"]
if !ok {
return errNotFoundInMap
}
c.(prometheus.Gauge).Set(registered)
return nil
},
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "slave",
Name: "uptime_seconds",
Help: "Number of seconds the master process is running.",
}): func(m metricMap, c prometheus.Collector) error {
uptime, ok := m["slave/uptime_secs"]
if !ok {
return errNotFoundInMap
}
c.(prometheus.Gauge).Set(uptime)
return nil
},
// Slave stats about frameworks and executors
gauge("slave", "executor_state", "Current number of executors by state.", "state"): func(m metricMap, c prometheus.Collector) error {
registering, ok := m["slave/executors_registering"]
if !ok {
return errNotFoundInMap
}
running, ok := m["slave/executors_running"]
if !ok {
return errNotFoundInMap
}
terminating, ok := m["slave/executors_terminating"]
if !ok {
return errNotFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("registering").Set(registering)
c.(*prometheus.GaugeVec).WithLabelValues("running").Set(running)
c.(*prometheus.GaugeVec).WithLabelValues("terminating").Set(terminating)
return nil
},
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "slave",
Name: "frameworks_active",
Help: "Current number of active frameworks",
}): func(m metricMap, c prometheus.Collector) error {
active, ok := m["slave/frameworks_active"]
if !ok {
return errNotFoundInMap
}
c.(prometheus.Gauge).Set(active)
return nil
},
newSettableCounter("slave",
"executors_terminated",
"Total number of executor terminations."): func(m metricMap, c prometheus.Collector) error {
terminated, ok := m["slave/executors_terminated"]
if !ok {
return errNotFoundInMap
}
c.(*settableCounter).Set(terminated)
return nil
},
newSettableCounter("slave",
"executors_preempted",
"Total number of executor preemptions."): func(m metricMap, c prometheus.Collector) error {
preempted, ok := m["slave/executors_preempted"]
if !ok {
return errNotFoundInMap
}
c.(*settableCounter).Set(preempted)
return nil
},
// Slave stats about tasks
counter("slave", "task_states_exit_total", "Total number of tasks processed by exit state.", "state"): func(m metricMap, c prometheus.Collector) error {
errored, ok := m["slave/tasks_error"]
if !ok {
return errNotFoundInMap
}
failed, ok := m["slave/tasks_failed"]
if !ok {
return errNotFoundInMap
}
finished, ok := m["slave/tasks_finished"]
if !ok {
return errNotFoundInMap
}
killed, ok := m["slave/tasks_killed"]
if !ok {
return errNotFoundInMap
}
lost, ok := m["slave/tasks_lost"]
if !ok {
return errNotFoundInMap
}
c.(*settableCounterVec).Set(errored, "errored")
c.(*settableCounterVec).Set(failed, "failed")
c.(*settableCounterVec).Set(finished, "finished")
c.(*settableCounterVec).Set(killed, "killed")
c.(*settableCounterVec).Set(lost, "lost")
return nil
},
counter("slave", "task_states_current", "Current number of tasks by state.", "state"): func(m metricMap, c prometheus.Collector) error {
running, ok := m["slave/tasks_running"]
if !ok {
return errNotFoundInMap
}
staging, ok := m["slave/tasks_staging"]
if !ok {
return errNotFoundInMap
}
starting, ok := m["slave/tasks_starting"]
if !ok {
return errNotFoundInMap
}
c.(*settableCounterVec).Set(running, "running")
c.(*settableCounterVec).Set(staging, "staging")
c.(*settableCounterVec).Set(starting, "starting")
return nil
},
// Slave stats about messages
counter("slave", "messages_outcomes_total",
"Total number of messages by outcome of operation",
"type", "outcome"): func(m metricMap, c prometheus.Collector) error {
frameworkMessagesValid, ok := m["slave/valid_framework_messages"]
if !ok {
return errNotFoundInMap
}
frameworkMessagesInvalid, ok := m["slave/invalid_framework_messages"]
if !ok {
return errNotFoundInMap
}
statusUpdateValid, ok := m["slave/valid_status_updates"]
if !ok {
return errNotFoundInMap
}
statusUpdateInvalid, ok := m["slave/invalid_status_updates"]
if !ok {
return errNotFoundInMap
}
c.(*settableCounterVec).Set(frameworkMessagesValid, "framework", "valid")
c.(*settableCounterVec).Set(frameworkMessagesInvalid, "framework", "invalid")
c.(*settableCounterVec).Set(statusUpdateValid, "status", "valid")
c.(*settableCounterVec).Set(statusUpdateInvalid, "status", "invalid")
return nil
},
}
return newMetricCollector(httpClient, metrics)
}