forked from mesos/mesos_exporter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
master.go
280 lines (263 loc) · 11.5 KB
/
master.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
package main
import (
"strings"
"github.com/prometheus/client_golang/prometheus"
)
func newMasterCollector(httpClient *httpClient) prometheus.Collector {
metrics := map[prometheus.Collector]func(metricMap, prometheus.Collector) error{
// CPU/Disk/Mem resources in free/used
gauge("master", "cpus", "Current CPU resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/cpus_total"]
used, ok := m["master/cpus_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("master", "cpus_revocable", "Current revocable CPU resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/cpus_revocable_total"]
used, ok := m["master/cpus_revocable_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("master", "mem", "Current memory resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/mem_total"]
used, ok := m["master/mem_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("master", "mem_revocable", "Current revocable memory resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/mem_revocable_total"]
used, ok := m["master/mem_revocable_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("master", "disk", "Current disk resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/disk_total"]
used, ok := m["master/disk_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
gauge("master", "disk_revocable", "Current disk resources in cluster.", "type"): func(m metricMap, c prometheus.Collector) error {
total, ok := m["master/disk_revocable_total"]
used, ok := m["master/disk_revocable_used"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("free").Set(total - used)
c.(*prometheus.GaugeVec).WithLabelValues("used").Set(used)
return nil
},
// Master stats about uptime and election state
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "master",
Name: "elected",
Help: "1 if master is elected leader, 0 if not",
}): func(m metricMap, c prometheus.Collector) error {
elected, ok := m["master/elected"]
if !ok {
return notFoundInMap
}
c.(prometheus.Gauge).Set(elected)
return nil
},
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "master",
Name: "uptime_seconds",
Help: "Number of seconds the master process is running.",
}): func(m metricMap, c prometheus.Collector) error {
uptime, ok := m["master/uptime_secs"]
if !ok {
return notFoundInMap
}
c.(prometheus.Gauge).Set(uptime)
return nil
},
// Master stats about agents
counter("master", "slave_registration_events_total", "Total number of registration events on this master since it booted.", "event"): func(m metricMap, c prometheus.Collector) error {
registrations, ok := m["master/slave_registrations"]
reregistrations, ok := m["master/slave_reregistrations"]
if !ok {
return notFoundInMap
}
c.(*settableCounterVec).Set(registrations, "register")
c.(*settableCounterVec).Set(reregistrations, "reregister")
return nil
},
counter("master", "slave_removal_events_total", "Total number of removal events on this master since it booted.", "event"): func(m metricMap, c prometheus.Collector) error {
scheduled, ok := m["master/slave_shutdowns_scheduled"]
canceled, ok := m["master/slave_shutdowns_canceled"]
completed, ok := m["master/slave_shutdowns_completed"]
removals, ok := m["master/slave_removals"]
if !ok {
return notFoundInMap
}
c.(*settableCounterVec).Set(scheduled, "scheduled")
c.(*settableCounterVec).Set(canceled, "canceled")
c.(*settableCounterVec).Set(completed, "completed")
c.(*settableCounterVec).Set(removals-completed, "died")
return nil
},
gauge("master", "slaves_state", "Current number of slaves known to the master per connection and registration state.", "connection_state", "registration_state"): func(m metricMap, c prometheus.Collector) error {
active, ok := m["master/slaves_active"]
inactive, ok := m["master/slaves_inactive"]
disconnected, ok := m["master/slaves_disconnected"]
if !ok {
return notFoundInMap
}
// FIXME: Make sure those assumptions are right
// Every "active" node is connected to the master
c.(*prometheus.GaugeVec).WithLabelValues("connected", "active").Set(active)
// Every "inactive" node is connected but node sending offers
c.(*prometheus.GaugeVec).WithLabelValues("connected", "inactive").Set(inactive)
// Every "disconnected" node is "inactive"
c.(*prometheus.GaugeVec).WithLabelValues("disconnected", "inactive").Set(disconnected)
// Every "connected" node is either active or inactive
return nil
},
// Master stats about frameworks
gauge("master", "frameworks_state", "Current number of frames known to the master per connection and registration state.", "connection_state", "registration_state"): func(m metricMap, c prometheus.Collector) error {
active, ok := m["master/frameworks_active"]
inactive, ok := m["master/frameworks_inactive"]
disconnected, ok := m["master/frameworks_disconnected"]
if !ok {
return notFoundInMap
}
// FIXME: Make sure those assumptions are right
// Every "active" framework is connected to the master
c.(*prometheus.GaugeVec).WithLabelValues("connected", "active").Set(active)
// Every "inactive" framework is connected but framework sending offers
c.(*prometheus.GaugeVec).WithLabelValues("connected", "inactive").Set(inactive)
// Every "disconnected" framework is "inactive"
c.(*prometheus.GaugeVec).WithLabelValues("disconnected", "inactive").Set(disconnected)
// Every "connected" framework is either active or inactive
return nil
},
prometheus.NewGauge(prometheus.GaugeOpts{
Namespace: "mesos",
Subsystem: "master",
Name: "offers_pending",
Help: "Current number of offers made by the master which aren't yet accepted or declined by frameworks.",
}): func(m metricMap, c prometheus.Collector) error {
offers, ok := m["master/outstanding_offers"]
if !ok {
return notFoundInMap
}
c.(prometheus.Gauge).Set(offers)
// c.(*prometheus.Gauge).Set(offers)
return nil
},
// Master stats about tasks
counter("master", "task_states_exit_total", "Total number of tasks processed by exit state.", "state"): func(m metricMap, c prometheus.Collector) error {
errored, ok := m["master/tasks_error"]
failed, ok := m["master/tasks_failed"]
finished, ok := m["master/tasks_finished"]
killed, ok := m["master/tasks_killed"]
lost, ok := m["master/tasks_lost"]
if !ok {
return notFoundInMap
}
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("master", "task_states_current", "Current number of tasks by state.", "state"): func(m metricMap, c prometheus.Collector) error {
running, ok := m["master/tasks_running"]
staging, ok := m["master/tasks_staging"]
starting, ok := m["master/tasks_starting"]
if !ok {
return notFoundInMap
}
c.(*settableCounterVec).Set(running, "running")
c.(*settableCounterVec).Set(staging, "staging")
c.(*settableCounterVec).Set(starting, "starting")
return nil
},
// Master stats about messages
counter("master", "messages_outcomes_total",
"Total number of messages by outcome of operation and direction.",
"source", "destination", "type", "outcome"): func(m metricMap, c prometheus.Collector) error {
frameworkToExecutorValid, ok := m["master/valid_framework_to_executor_messages"]
frameworkToExecutorInvalid, ok := m["master/invalid_framework_to_executor_messages"]
executorToFrameworkValid, ok := m["master/valid_executor_to_framework_messages"]
executorToFrameworkInvalid, ok := m["master/invalid_executor_to_framework_messages"]
// status updates are sent from framework?(FIXME) to slave
// status update acks are sent from slave to framework?
statusUpdateAckValid, ok := m["master/valid_status_update_acknowledgements"]
statusUpdateAckInvalid, ok := m["master/invalid_status_update_acknowledgements"]
statusUpdateValid, ok := m["master/valid_status_updates"]
statusUpdateInvalid, ok := m["master/invalid_status_updates"]
if !ok {
return notFoundInMap
}
c.(*settableCounterVec).Set(frameworkToExecutorValid, "framework", "executor", "", "valid")
c.(*settableCounterVec).Set(frameworkToExecutorInvalid, "framework", "executor", "", "invalid")
c.(*settableCounterVec).Set(executorToFrameworkValid, "executor", "framework", "", "valid")
c.(*settableCounterVec).Set(executorToFrameworkInvalid, "executor", "framework", "", "invalid")
// We consider a ack message simply as a message from slave to framework
c.(*settableCounterVec).Set(statusUpdateValid, "framework", "slave", "status_update", "valid")
c.(*settableCounterVec).Set(statusUpdateInvalid, "framework", "slave", "status_update", "invalid")
c.(*settableCounterVec).Set(statusUpdateAckValid, "slave", "framework", "status_update", "valid")
c.(*settableCounterVec).Set(statusUpdateAckInvalid, "slave", "framework", "status_update", "invalid")
return nil
},
counter("master", "messages_type_total", "Total number of valid messages by type.", "type"): func(m metricMap, c prometheus.Collector) error {
for k, v := range m {
i := strings.Index("master/messages_", k)
if i == -1 {
continue
}
// FIXME: We expose things like messages_framework_to_executor twice
c.(*settableCounterVec).Set(v, k[i:])
}
return nil
},
// Master stats about events
gauge("master", "event_queue_length", "Current number of elements in event queue by type", "type"): func(m metricMap, c prometheus.Collector) error {
dispatches, ok := m["master/event_queue_dispatches"]
httpRequests, ok := m["master/event_queue_http_requests"]
messages, ok := m["master/event_queue_messages"]
if !ok {
return notFoundInMap
}
c.(*prometheus.GaugeVec).WithLabelValues("message").Set(messages)
c.(*prometheus.GaugeVec).WithLabelValues("http_request").Set(httpRequests)
c.(*prometheus.GaugeVec).WithLabelValues("dispatches").Set(dispatches)
return nil
},
// Master stats about registrar
prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "mesos",
Subsystem: "master",
Name: "state_store_seconds",
Help: "Registry write latency in seconds",
}): func(m metricMap, c prometheus.Collector) error {
// c.(*prometheus.Histogram).Buckets //FIXME
return nil
},
}
return newMetricCollector(httpClient, metrics)
}