-
Notifications
You must be signed in to change notification settings - Fork 8
/
cluster_stats.py
executable file
·510 lines (494 loc) · 18.2 KB
/
cluster_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
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
import stats_buffer
import util_cli as util
class BucketSummary:
def run(self, accessor):
return stats_buffer.bucket_info
class DGMRatio:
def run(self, accessor):
result = []
hdd_total = 0
ram_total = 0
for node, nodeinfo in stats_buffer.nodes.iteritems():
if nodeinfo["StorageInfo"].has_key("hdd"):
hdd_total += nodeinfo['StorageInfo']['hdd']['usedByData']
if nodeinfo["StorageInfo"].has_key("ram"):
ram_total += nodeinfo['StorageInfo']['ram']['usedByData']
if ram_total > 0:
ratio = hdd_total / ram_total
else:
ratio = 0
return ratio
class ARRatio:
def run(self, accessor):
result = {}
cluster = 0
for bucket, stats_info in stats_buffer.buckets.iteritems():
item_avg = {
"curr_items": [],
"vb_replica_curr_items": [],
}
num_error = []
for counter in accessor["counter"]:
values = stats_info[accessor["scale"]][counter]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
avg = sum(vals) / samplesCount
item_avg[counter].append((node, avg))
res = []
active_total = replica_total = 0
for active, replica in zip(item_avg['curr_items'], item_avg['vb_replica_curr_items']):
if replica[1] == 0:
res.append((active[0], "No replica"))
else:
ratio = 1.0 * active[1] / replica[1]
res.append((active[0], util.pretty_float(ratio)))
if ratio < accessor["threshold"]:
num_error.append({"node":active[0], "value": ratio})
active_total += active[1]
replica_total += replica[1]
if replica_total == 0:
res.append(("total", "no replica"))
else:
ratio = active_total * 1.0 / replica_total
cluster += ratio
res.append(("total", util.pretty_float(ratio)))
if ratio != accessor["threshold"]:
num_error.append({"node":"total", "value": ratio})
#if len(num_error) > 0:
# result[bucket] = {"error" : num_error}
#else:
result[bucket] = res
if len(stats_buffer.buckets) > 0:
result["cluster"] = util.pretty_float(cluster / len(stats_buffer.buckets))
return result
class OpsRatio:
def run(self, accessor):
result = {}
for bucket, stats_info in stats_buffer.buckets.iteritems():
ops_avg = {
"cmd_get": [],
"cmd_set": [],
"delete_hits" : [],
}
for counter in accessor["counter"]:
values = stats_info[accessor["scale"]][counter]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
for node, vals in nodeStats.iteritems():
avg = sum(vals) / samplesCount
ops_avg[counter].append((node, avg))
res = []
read_total = write_total = del_total = 0
for read, write, delete in zip(ops_avg['cmd_get'], ops_avg['cmd_set'], ops_avg['delete_hits']):
count = read[1] + write[1] + delete[1]
if count == 0:
res.append((read[0], "0:0:0"))
else:
read_ratio = read[1] *100 / count
read_total += read_ratio
write_ratio = write[1] * 100 / count
write_total += write_ratio
del_ratio = delete[1] * 100 / count
del_total += del_ratio
res.append((read[0], "{0}:{1}:{2}".format(int(read_ratio+.5), int(write_ratio+.5), int(del_ratio+.5))))
read_total /= len(ops_avg['cmd_get'])
write_total /= len(ops_avg['cmd_set'])
del_total /= len(ops_avg['delete_hits'])
res.append(("total", "{0}:{1}:{2}".format(int(read_total+.5), int(write_total+.5), int(del_total+.5))))
result[bucket] = res
return result
class CacheMissRatio:
def run(self, accessor):
result = {}
cluster = 0
for bucket, stats_info in stats_buffer.buckets.iteritems():
values = stats_info[accessor["scale"]][accessor["counter"]]
timestamps = values["timestamp"]
timestamps = [x - timestamps[0] for x in timestamps]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
trend = []
total = 0
data = []
for node, vals in nodeStats.iteritems():
#a, b = util.linreg(timestamps, vals)
value = sum(vals) / samplesCount
#value = a * timestamps[-1] + b
total += value
trend.append((node, util.pretty_float(value)))
data.append(value)
total /= len(nodeStats)
trend.append(("total", util.pretty_float(total)))
trend.append(("variance", util.two_pass_variance(data)))
cluster += total
result[bucket] = trend
if len(stats_buffer.buckets) > 0:
result["cluster"] = util.pretty_float(cluster / len(stats_buffer.buckets))
return result
class MemUsed:
def run(self, accessor):
result = {}
cluster = 0
for bucket, stats_info in stats_buffer.buckets.iteritems():
values = stats_info[accessor["scale"]][accessor["counter"]]
timestamps = values["timestamp"]
timestamps = [x - timestamps[0] for x in timestamps]
nodeStats = values["nodeStats"]
samplesCount = values["samplesCount"]
trend = []
total = 0
data = []
for node, vals in nodeStats.iteritems():
avg = sum(vals) / samplesCount
trend.append((node, util.size_label(avg)))
data.append(avg)
#print data
trend.append(("variance", util.two_pass_variance(data)))
result[bucket] = trend
return result
class ItemGrowth:
def run(self, accessor):
result = {}
for bucket, stats_info in stats_buffer.buckets.iteritems():
trend = []
values = stats_info[accessor["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 b < 1:
trend.append((node, 0))
else:
start_val = b
end_val = a * timestamps[-1] + b
rate = (end_val * 1.0 / b - 1.0) * 100
trend.append((node, util.pretty_float(rate)))
result[bucket] = trend
return result
class NumVbuckt:
def run(self, accessor):
result = {}
for bucket, stats_info in stats_buffer.buckets.iteritems():
num_error = []
values = stats_info[accessor["scale"]][accessor["counter"]]
nodeStats = values["nodeStats"]
for node, vals in nodeStats.iteritems():
if vals[-1] < accessor["threshold"]:
num_error.append({"node":node, "value":vals[-1]})
if len(num_error) > 0:
result[bucket] = {"error" : num_error}
return result
class RebalanceStuck:
def run(self, accessor):
result = {}
for bucket, bucket_stats in stats_buffer.node_stats.iteritems():
num_error = []
for node, stats_info in bucket_stats.iteritems():
for key, value in stats_info.iteritems():
if key.find(accessor["counter"]) >= 0:
if accessor.has_key("threshold"):
if int(value) > accessor["threshold"]:
num_error.append({"node":node, "value": (key, value)})
else:
num_error.append({"node":node, "value": (key, value)})
if len(num_error) > 0:
result[bucket] = {"error" : num_error}
return result
class MemoryFramentation:
def run(self, accessor):
result = {}
for bucket, bucket_stats in stats_buffer.node_stats.iteritems():
num_error = []
for node, stats_info in bucket_stats.iteritems():
for key, value in stats_info.iteritems():
if key.find(accessor["counter"]) >= 0:
if accessor.has_key("threshold"):
if int(value) > accessor["threshold"]:
if accessor.has_key("unit"):
if accessor["unit"] == "time":
num_error.append({"node":node, "value": (key, util.time_label(value))})
elif accessor["unit"] == "size":
num_error.append({"node":node, "value": (key, util.size_label(value))})
else:
num_error.append({"node":node, "value": (key, value)})
else:
num_error.append({"node":node, "value": (key, value)})
if len(num_error) > 0:
result[bucket] = {"error" : num_error}
return result
class EPEnginePerformance:
def run(self, accessor):
result = {}
for bucket, bucket_stats in stats_buffer.node_stats.iteritems():
num_error = []
for node, stats_info in bucket_stats.iteritems():
for key, value in stats_info.iteritems():
if key.find(accessor["counter"]) >= 0:
if accessor.has_key("threshold"):
if accessor["counter"] == "flusherState" and value != accessor["threshold"]:
num_error.append({"node":node, "value": (key, value)})
elif accessor["counter"] == "flusherCompleted" and value == accessor["threshold"]:
num_error.append({"node":node, "value": (key, value)})
else:
if value > accessor["threshold"]:
num_error.append({"node":node, "value": (key, value)})
if len(num_error) > 0:
result[bucket] = {"error" : num_error}
return result
class TotalDataSize:
def run(self, accessor):
result = []
total = 0
for node, nodeinfo in stats_buffer.nodes.iteritems():
if nodeinfo["StorageInfo"].has_key("hdd"):
total += nodeinfo['StorageInfo']['hdd']['usedByData']
result.append(util.size_label(total))
return result
class AvailableDiskSpace:
def run(self, accessor):
result = []
total = 0
for node, nodeinfo in stats_buffer.nodes.iteritems():
if nodeinfo["StorageInfo"].has_key("hdd"):
total += nodeinfo['StorageInfo']['hdd']['free']
result.append(util.size_label(total))
return result
ClusterCapsule = [
{"name" : "TotalDataSize",
"ingredients" : [
{
"name" : "totalDataSize",
"description" : "Total Data Size across cluster",
"code" : "TotalDataSize",
}
],
"clusterwise" : True,
"perNode" : False,
"perBucket" : False,
},
{"name" : "AvailableDiskSpace",
"ingredients" : [
{
"name" : "availableDiskSpace",
"description" : "Available disk space",
"code" : "AvailableDiskSpace",
}
],
"clusterwise" : True,
"perNode" : False,
"perBucket" : False,
},
{"name" : "CacheMissRatio",
"ingredients" : [
{
"name" : "cacheMissRatio",
"description" : "Cache miss ratio",
"counter" : "ep_cache_miss_rate",
"scale" : "hour",
"code" : "CacheMissRatio",
"unit" : "percentage",
"threshold" : 2,
},
],
"clusterwise" : True,
"perNode" : True,
"perBucket" : True,
"indicator" : False,
"nodeDisparate" : True,
},
{"name" : "DGM",
"ingredients" : [
{
"name" : "dgm",
"description" : "Disk to Memory Ratio",
"code" : "DGMRatio"
},
],
"clusterwise" : True,
"perNode" : False,
"perBucket" : False,
},
{"name" : "BucketSummary",
"ingredients" : [
{
"name" : "bucketSummary",
"description" : "Bucket performance summary",
"code" : "BucketSummary",
},
],
"clusterwise" : True,
},
{"name" : "ActiveReplicaResidentRatio",
"ingredients" : [
{
"name" : "activeReplicaResidencyRatio",
"description" : "Active and Replica Resident Ratio",
"counter" : ["curr_items", "vb_replica_curr_items"],
"scale" : "minute",
"code" : "ARRatio",
"threshold" : 1,
},
],
"clusterwise" : True,
"perNode" : True,
"perBucket" : True,
"indicator" : True,
},
{"name" : "OPSPerformance",
"ingredients" : [
{
"name" : "opsPerformance",
"description" : "Read/Write/Delete ops ratio",
"scale" : "minute",
"counter" : ["cmd_get", "cmd_set", "delete_hits"],
"code" : "OpsRatio",
},
],
"perBucket" : True,
},
{"name" : "GrowthRate",
"ingredients" : [
{
"name" : "dataGrowthRateForItems",
"description" : "Data Growth rate for items",
"counter" : "curr_items",
"scale" : "day",
"code" : "ItemGrowth",
"unit" : "percentage",
},
]
},
{"name" : "VBucketNumber",
"ingredients" : [
{
"name" : "activeVbucketNumber",
"description" : "Active VBucket number is less than expected",
"counter" : "vb_active_num",
"scale" : "hour",
"code" : "NumVbuckt",
"threshold" : 1024,
},
{
"name" : "replicaVBucketNumber",
"description" : "Replica VBucket number is less than expected",
"counter" : "vb_replica_num",
"scale" : "hour",
"code" : "NumVbuckt",
"threshold" : 1024,
},
],
"indicator" : True,
},
{"name" : "MemoryUsage",
"ingredients" : [
{
"name" : "memoryUsage",
"description" : "Check memory usage",
"counter" : "mem_used",
"scale" : "hour",
"code" : "MemUsed",
},
],
"nodeDisparate" : True,
},
{"name" : "RebalancePerformance",
"ingredients" : [
{
"name" : "rebalanceStuck",
"description" : "Check if rebalance is stuck",
"counter" : "idle",
"code" : "RebalanceStuck",
},
{
"name" : "highBackfillRemaing",
"description" : "Tap queue backfilll remaining is too high",
"counter" : "ep_tap_queue_backfillremaining",
"code" : "RebalanceStuck",
"threshold" : 1000,
},
],
"indicator" : True,
},
{"name" : "MemoryFragmentation",
"ingredients" : [
{
"name" : "totalFragmentation",
"description" : "Total memory fragmentation",
"counter" : "total_fragmentation_bytes",
"code" : "MemoryFramentation",
"unit" : "size",
"threshold" : 1073741824, # 1GB
},
{
"name" : "diskDelete",
"description" : "Averge disk delete time",
"counter" : "disk_del",
"code" : "MemoryFramentation",
"unit" : "time",
"threshold" : 1000 #1ms
},
{
"name" : "diskUpdate",
"description" : "Averge disk update time",
"counter" : "disk_update",
"code" : "MemoryFramentation",
"unit" : "time",
"threshold" : 1000 #1ms
},
{
"name" : "diskInsert",
"description" : "Averge disk insert time",
"type" : "python",
"counter" : "disk_insert",
"code" : "MemoryFramentation",
"unit" : "time",
"threshold" : 1000 #1ms
},
{
"name" : "diskInsert",
"description" : "Averge disk insert time",
"counter" : "disk_commit",
"code" : "MemoryFramentation",
"unit" : "time",
"threshold" : 5000000 #10s
},
],
"indicator" : True,
},
{"name" : "EPEnginePerformance",
"ingredients" : [
{
"name" : "flusherState",
"description" : "Engine flusher state",
"counter" : "ep_flusher_state",
"code" : "EPEnginePerformance",
"threshold" : "running",
},
{
"name" : "flusherCompleted",
"description" : "Flusher completed",
"counter" : "ep_flusher_num_completed",
"code" : "EPEnginePerformance",
"threshold" : 0
},
{
"name" : "avgItemLoadTime",
"description" : "Average item loaded time",
"counter" : "ep_bg_load_avg",
"code" : "EPEnginePerformance",
"threshold" : 100,
},
{
"name" : "avgItemWaitTime",
"description" : "Averge item waited time",
"counter" : "ep_bg_wait_avg",
"code" : "EPEnginePerformance",
"threshold" : 100
},
],
"indicator" : True,
},
]