forked from bcui6611/healthchecker
/
diskqueue_stats.py
executable file
·431 lines (411 loc) · 20.5 KB
/
diskqueue_stats.py
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
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
import stats_buffer
import util_cli as util
class AvgDiskQueue:
def run(self, accessor, scale, threshold=None):
result = {}
if threshold.has_key("DiskQueueDiagnosis"):
threshold_val = threshold["DiskQueueDiagnosis"][accessor["name"]]
else:
threshold_val = accessor["threshold"]
for bucket, stats_info in stats_buffer.buckets.iteritems():
#print bucket, stats_info
disk_queue_avg_error = []
disk_queue_avg_warn = []
res = []
values = stats_info[scale][accessor["counter"][0]]
curr_values = stats_info[scale][accessor["counter"][1]]
cmdset_values = stats_info[scale][accessor["counter"][2]]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
timestamps = values["timestamp"]
total = []
for node, vals in nodeStats.iteritems():
curr_vals = curr_values["nodeStats"][node]
cmdset_vals = cmdset_values["nodeStats"][node]
if samplesCount > 0:
node_avg_dwq = sum(vals) / samplesCount
node_avg_curr = sum(curr_vals) / samplesCount
node_avg_cmdset = sum(cmdset_vals) / samplesCount
else:
node_avg_curr = 0
node_avg_cmdest = 0
abnormal_segs = util.abnormal_extract(vals, threshold_val["disk_write_queue"]["low"])
abnormal_vals = []
for seg in abnormal_segs:
begin_index = seg[0]
seg_total = seg[1]
if seg_total < threshold_val["recurrence"]:
continue
end_index = begin_index + seg_total
cmdset_avg = sum(cmdset_vals[begin_index : end_index]) / seg_total
curr_avg = sum(curr_vals[begin_index : end_index]) / seg_total
dwq_avg = sum(vals[begin_index : end_index]) / seg_total
if curr_avg > node_avg_curr and cmdset_avg > node_avg_cmdset:
symptom = accessor["symptom"] % (util.pretty_datetime(timestamps[begin_index]),
util.pretty_datetime(timestamps[end_index-1]),
util.number_label(int(cmdset_avg)),
util.number_label(int(curr_avg)),
util.number_label(dwq_avg))
abnormal_vals.append(dwq_avg)
if dwq_avg > threshold_val["disk_write_queue"]["high"]:
disk_queue_avg_error.append({"node":node, "value":symptom})
else:
disk_queue_avg_warn.append({"node":node, "level":"yellow", "value":symptom})
if len(abnormal_vals) > 0:
res.append((node, {"value":util.number_label(dwq_avg), "raw":abnormal_vals}))
total.append(node_avg_dwq)
if len(disk_queue_avg_error) > 0:
res.append(("error", disk_queue_avg_error))
if len(disk_queue_avg_warn) > 0:
res.append(("warn", disk_queue_avg_warn))
if len(nodeStats) > 0:
rate = sum(total) / len(nodeStats)
res.append(("total", {"value" : util.number_label(rate),
"raw" : total}))
result[bucket] = res
return result
class DiskQueueTrend:
def run(self, accessor, scale, threshold=None):
result = {}
if threshold.has_key("DiskQueueDiagnosis"):
threshold_val = threshold["DiskQueueDiagnosis"][accessor["name"]]
else:
threshold_val = accessor["threshold"]
for bucket, stats_info in stats_buffer.buckets.iteritems():
trend_error = []
trend_warn = []
res = []
values = stats_info[scale][accessor["counter"]]
timestamps = values["timestamp"]
timestamps = [x - timestamps[0] for x in timestamps]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
a, b = util.linreg(timestamps, vals)
if a > threshold_val["high"]:
symptom = accessor["symptom"] % (util.pretty_float(a, 3), threshold_val["high"])
trend_error.append({"node":node, "level":"red", "value":symptom})
res.append((node, util.pretty_float(a)))
elif a > threshold_val["low"]:
symptom = accessor["symptom"] % (util.pretty_float(a, 3), threshold_val["low"])
trend_warn.append({"node":node, "level":"yellow", "value":symptom})
res.append((node, util.pretty_float(a)))
if len(trend_error) > 0:
res.append(("error", trend_error))
if len(trend_warn) > 0:
res.append(("warn", trend_warn))
result[bucket] = res
return result
class ReplicationTrend:
def run(self, accessor, scale, threshold=None):
result = {}
cluster = 0
if threshold.has_key(accessor["name"]):
threshold_val = threshold[accessor["name"]]
else:
threshold_val = accessor["threshold"]
for bucket, stats_info in stats_buffer.buckets.iteritems():
item_avg = {
"curr_items": [],
"ep_tap_total_total_backlog_size": [],
}
num_error = []
num_warn = []
for counter in accessor["counter"]:
values = stats_info[scale][counter]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
if samplesCount > 0:
avg = sum(vals) / samplesCount
else:
avg = 0
item_avg[counter].append((node, avg))
res = []
active_total = replica_total = 0
for active, replica in zip(item_avg['curr_items'], item_avg['ep_tap_total_total_backlog_size']):
if active[1] == 0:
res.append((active[0], 0))
else:
ratio = 100.0 * replica[1] / active[1]
delta = int(replica[1])
if accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["high"]:
symptom = accessor["symptom"] % (util.pretty_float(ratio), threshold_val["percentage"]["high"])
num_error.append({"node":active[0], "value": symptom})
res.append((active[0], util.pretty_float(ratio) + "%"))
elif accessor["type"] == "number" and delta > threshold_val["number"]["high"]:
symptom = accessor["symptom"] % (util.number_label(delta), util.number_label(threshold_val["number"]["high"]))
num_error.append({"node":active[0], "value": symptom})
res.append((active[0], util.number_label(delta)))
elif accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["low"]:
symptom = accessor["symptom"] % (util.pretty_float(ratio), threshold_val["percentage"]["low"])
num_warn.append({"node":active[0], "value": symptom})
res.append((active[0], util.pretty_float(ratio) + "%"))
elif accessor["type"] == "number" and delta > threshold_val["number"]["low"]:
symptom = accessor["symptom"] % (util.number_label(delta), util.number_label(threshold_val["number"]["low"]))
num_warn.append({"node":active[0], "value": symptom})
res.append((active[0], util.number_label(delta)))
active_total += active[1]
replica_total += replica[1]
if active_total > 0:
ratio = replica_total * 100.0 / active_total
cluster += ratio
if accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["high"]:
symptom = accessor["symptom"] % (util.pretty_float(ratio), threshold_val["percentage"]["high"])
num_error.append({"node":"total", "value": symptom})
res.append(("total", util.pretty_float(ratio) + "%"))
elif accessor["type"] == "percentage" and ratio > threshold_val["percentage"]["low"]:
symptom = accessor["symptom"] % (util.pretty_float(ratio), threshold_val["percentage"]["low"])
num_warn.append({"node":"total", "value": symptom})
res.append(("total", util.pretty_float(ratio) + "%"))
if len(num_error) > 0:
res.append(("error", num_error))
if len(num_warn) > 0:
res.append(("warn", num_warn))
result[bucket] = res
if len(stats_buffer.buckets) > 0:
result["cluster"] = util.pretty_float(cluster / len(stats_buffer.buckets))
return result
class DiskQueueDrainingRate:
def run(self, accessor, scale, threshold=None):
result = {}
if threshold.has_key("DiskQueueDrainingAnalysis"):
threshold_val = threshold["DiskQueueDrainingAnalysis"][accessor["name"]]
else:
threshold_val = accessor["threshold"]
for bucket, stats_info in stats_buffer.buckets.iteritems():
res = []
disk_queue_avg_error = []
drain_values = stats_info[scale][accessor["counter"][0]]
len_values = stats_info[scale][accessor["counter"][1]]
nodeStats = drain_values["nodeStats"]
samplesCount = drain_values["samplesCount"]
for node, vals in nodeStats.iteritems():
if samplesCount > 0:
avg = sum(vals) / samplesCount
else:
avg = 0
if node in len_values["nodeStats"]:
disk_len_vals = len_values["nodeStats"][node]
else:
continue
if samplesCount > 0:
len_avg = sum(disk_len_vals) / samplesCount
else:
len_avg = 0
if avg < threshold_val["drainRate"] and len_avg > threshold_val["diskLength"]:
symptom = accessor["symptom"] % (util.pretty_float(avg), threshold_val["drainRate"], int(len_avg), threshold_val["diskLength"])
disk_queue_avg_error.append({"node":node, "level":"red", "value":symptom})
res.append((node, (util.pretty_float(avg), int(len_avg))))
if len(disk_queue_avg_error) > 0:
res.append(("error", disk_queue_avg_error))
result[bucket] = res
return result
class PerformanceDiagnosis_diskread:
def run(self, accessor, scale, threshold=None):
result = {}
thresholdval = accessor["threshold"]
if threshold.has_key("PerformanceDiagnosis_diskread"):
thresholdval = threshold["PerformanceDiagnosis_diskread"]
for bucket, stats_info in stats_buffer.buckets.iteritems():
if stats_info[scale].get(accessor["counter"][0], None) is None:
return result
diskRead_values = stats_info[scale][accessor["counter"][0]]
cacheMissRate_values = stats_info[scale][accessor["counter"][1]]
arr_values = stats_info[scale][accessor["counter"][2]]
memUsed_values = stats_info[scale][accessor["counter"][3]]
curr_values = stats_info[scale][accessor["counter"][4]]
cmdSet_values = stats_info[scale][accessor["counter"][5]]
timestamps = diskRead_values["timestamp"]
samplesCount = diskRead_values["samplesCount"]
trend = []
num_warn = []
for node, vals in diskRead_values["nodeStats"].iteritems():
diskRead_vals = diskRead_values["nodeStats"][node]
cacheMissRate_vals = cacheMissRate_values["nodeStats"][node]
arr_vals = arr_values["nodeStats"][node]
memUsed_vals = memUsed_values["nodeStats"][node]
curr_vals = curr_values["nodeStats"][node]
cmdSet_vals = cmdSet_values["nodeStats"][node]
if samplesCount > 0:
node_avg_mem = sum(memUsed_vals) / samplesCount
node_avg_curr = sum(curr_vals) / samplesCount
node_avg_cmdset = sum(cmdSet_vals) / samplesCount
else:
node_avg_curr = 0
# Fine grained analysis
abnormal_segs = util.abnormal_extract(diskRead_vals, thresholdval["ep_bg_fetched"])
abnormal_vals = []
for seg in abnormal_segs:
begin_index = seg[0]
seg_total = seg[1]
if seg_total < thresholdval["recurrence"]:
continue
end_index = begin_index + seg_total
diskread_avg = sum(diskRead_vals[begin_index : end_index]) / seg_total
cmr_avg = sum(cacheMissRate_vals[begin_index : end_index]) / seg_total
arr_avg = sum(arr_vals[begin_index : end_index]) / seg_total
mem_avg = sum(memUsed_vals[begin_index : end_index]) / seg_total
curr_avg = sum(curr_vals[begin_index : end_index]) / seg_total
cmdSet_avg = sum(cmdSet_vals[begin_index : end_index]) / seg_total
if cmr_avg > thresholdval["ep_cache_miss_rate"] and \
arr_avg < thresholdval["vb_active_resident_items_ratio"] and \
mem_avg > node_avg_mem and \
curr_avg > node_avg_curr and \
cmdSet_avg > node_avg_cmdset:
symptom = accessor["symptom"] % (util.pretty_datetime(timestamps[begin_index]),
util.pretty_datetime(timestamps[end_index-1]),
util.number_label(int(curr_avg)),
util.size_label(int(mem_avg)),
util.pretty_float(cmr_avg),
util.pretty_float(arr_avg),
util.number_label(int(diskread_avg)))
num_warn.append({"node":node, "value":symptom})
abnormal_vals.append(diskread_avg)
if len(abnormal_vals) > 0:
trend.append((node, {"value" : util.pretty_float(sum(abnormal_vals)/len(abnormal_vals)),
"raw" : abnormal_vals}
))
if len(num_warn) > 0:
trend.append(("warn", num_warn))
result[bucket] = trend
return result
DiskQueueCapsule = [
{"name" : "DiskQueueDiagnosis",
"description" : "",
"ingredients" : [
{
"name" : "avgDiskQueueLength",
"description" : "Average disk write queue length",
"counter" : ["disk_write_queue", "curr_items", "cmd_set"],
"scale" : "minute",
"code" : "AvgDiskQueue",
"threshold" : {
"disk_write_queue" : {"low" : 500000, "high" : 1000000 },
"recurrence" : 10,
},
"symptom" : "From %s to %s, a higher set/sec '%s' leads to high item count '%s' and long disk write queue length '%s'",
"formula" : "Avg(disk_write_queue) > threshold"
},
{
"name" : "diskQueueTrend",
"description" : "Persistence severely behind - disk write queue continues growing",
"counter" : "disk_write_queue",
"scale" : "hour",
"code" : "DiskQueueTrend",
"threshold" : {
"low" : 0.01,
"high" : 0.25
},
"symptom" : "Disk write queue growing trend '%s' is above threshold '%s'",
"formula" : "Linear(disk_write_queue) > threshold",
},
],
"indicator" : True,
"perBucket" : True,
"perNode" : True,
},
{"name" : "ReplicationPercentageTrend",
"ingredients" : [
{
"name" : "replicationPercentageTrend",
"description" : "Replication backlog size to active item ratio",
"counter" : ["curr_items", "ep_tap_total_total_backlog_size"],
"scale" : "hour",
"code" : "ReplicationTrend",
"type" : "percentage",
"threshold" : {
"percentage" : {
"low" : 10.0,
"high" : 30.0,
},
},
"symptom" : "Number of backlog item to active item ratio '%s%%' is above threshold '%s%%'",
"formula" : "Avg(ep_tap_total_total_backlog_size) / Avg(curr_items) > threshold",
}
],
"perBucket" : True,
"indicator" : True,
},
{"name" : "ReplicationNumTrend",
"ingredients" : [
{
"name" : "replicationNumTrend",
"description" : "Replication backlog size",
"counter" : ["curr_items", "ep_tap_total_total_backlog_size"],
"scale" : "hour",
"code" : "ReplicationTrend",
"type" : "number",
"threshold" : {
"number" : {
"low" : 50000,
"high" : 100000,
},
},
"symptom" : "Number of backlog items '%s' is above threshold '%s'",
"formula" : "Avg(ep_tap_total_total_backlog_size) > threshold",
}
],
"perBucket" : True,
"indicator" : True,
},
{"name" : "DiskQueueDrainingAnalysis",
"description" : "",
"ingredients" : [
{
"name" : "activeDiskQueueDrainRate",
"description" : "Persistence severely behind ",
"counter" : ["vb_active_queue_drain", "disk_write_queue"],
"pernode" : True,
"scale" : "minute",
"code" : "DiskQueueDrainingRate",
"threshold" : {
"drainRate" : 0,
"diskLength" : 100000,
},
"symptom" : "Active disk queue draining rate '%s' is below threshold '%s' and length '%s' is bigger than '%s'",
"formula" : "Avg(vb_active_queue_drain) < threshold AND Avg(disk_write_queue) > threshold",
},
{
"name" : "replicaDiskQueueDrainRate",
"description" : "Replication severely behind ",
"counter" : ["vb_replica_queue_drain", "disk_write_queue"],
"pernode" : True,
"scale" : "minute",
"code" : "DiskQueueDrainingRate",
"threshold" : {
"drainRate" : 0,
"diskLength" : 100000,
},
"symptom" : "Replica disk queue draining rate '%s' is below threshold '%s' and length '%s' is bigger than '%s'",
"formula" : "Avg(vb_replica_queue_drain) < threshold AND Avg(disk_write_queue) > threshold"
},
],
"indicator" : True,
"perBucket" : True,
},
{"name" : "PerformanceDiagnosis_diskread",
"ingredients" : [
{
"name" : "performanceDiagnosis_diskread",
"description" : "Lots of disk reads",
"symptom" : "From %s to %s, a high item count '%s', high memory used '%s', " \
"high cache miss ratio '%s%%', and low residential ratio '%s%%' lead to above average disk reads '%s'.",
"counter" : ["ep_bg_fetched","ep_cache_miss_rate", "vb_active_resident_items_ratio", "mem_used", "curr_items", "cmd_set"],
"code" : "PerformanceDiagnosis_diskread",
"threshold" : {
"ep_bg_fetched" : 10, # lots of disk reads
"ep_cache_miss_rate" : 2, # 2% high
"vb_active_resident_items_ratio" : 30, # low
"recurrence" : 10
},
"formula" : "Avg(ep_bg_fetched)",
},
],
"clusterwise" : False,
"perNode" : True,
"perBucket" : True,
"indicator" : True,
"nodeDisparate" : True,
},
]