-
Notifications
You must be signed in to change notification settings - Fork 3
/
not_scrubbed_in_time_OSDs_text.py
executable file
·74 lines (62 loc) · 2.9 KB
/
not_scrubbed_in_time_OSDs_text.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
#!/usr/bin/env python3
import argparse,re,sys
from datetime import datetime
from collections import Counter
parser = argparse.ArgumentParser()
parser.add_argument("-f", "--file", default = "", required=True, help="Filename of the 'ceph pg dump --format=json' output")
parser.add_argument("-d", "--deep", default = 7, type=int, help="Deep Scrub Interval ( days ) - Default: 7")
parser.add_argument("-s", "--scrub", default = 1, type=int, help="Scrub Interval ( days ) - Default: 1")
parser.add_argument("-e", "--deepwarnratio", default = 0.75, type=float, help="Deep Scrub Warn Ratio - Default: 0.75")
parser.add_argument("-t", "--scrubwarnratio", default = 0.5, type=float, help="Scrub Warn Ratio - Default: 0.5")
args = parser.parse_args()
scrub_interval=args.scrub * 86400 * ( 1 + args.scrubwarnratio )
deep_scrub_interval=args.deep * 86400 * ( 1 + args.deepwarnratio )
scrub_osds = {}
deep_scrub_osds = {}
nowtime = None
scrub_pgs = []
deep_scrub_pgs = []
try:
f = open(args.file,'r')
except:
print("Failed to open {}. Does it exist?".format(args.file))
exit(1)
lines = f.readlines()
for line in lines:
line = line.rstrip()
if nowtime is None and re.match('^stamp ', line):
line_split=line.split()
nowtime=datetime.strptime(' '.join(line_split[1:3]), '%Y-%m-%d %H:%M:%S.%f')
elif re.match('^[0-9][0-9]*\.[0-9a-f][0-9a-f]* ',line):
line_split = line.split()
last_scrub_delta = ( nowtime - datetime.strptime(' '.join(line_split[21:23]), '%Y-%m-%d %H:%M:%S.%f') ).total_seconds()
last_deep_scrub_delta = ( nowtime - datetime.strptime(' '.join(line_split[24:26]), '%Y-%m-%d %H:%M:%S.%f') ).total_seconds()
if last_scrub_delta >= scrub_interval:
scrub_pgs.append(line_split[0])
osd_csv = re.sub('[^0-9,]','',line_split[16])
osd_split = osd_csv.split(',')
for osd in osd_split:
try:
scrub_osds[str(osd)] += 1
except:
scrub_osds[str(osd)] = 1
if last_deep_scrub_delta >= deep_scrub_interval:
deep_scrub_pgs.append(line_split[0])
osd_csv = re.sub('[^0-9,]','',line_split[16])
osd_split = osd_csv.split(',')
for osd in osd_split:
try:
deep_scrub_osds[str(osd)] += 1
except:
deep_scrub_osds[str(osd)] = 1
if len(scrub_osds) > 0:
print('{} Not Scrubbed PGs:\n{}\n\nTop OSDs: '.format(len(scrub_pgs)," ".join(scrub_pgs)))
for osdid in sorted(scrub_osds, key=scrub_osds.get)[-10:]:
print(f'osd.{osdid},{scrub_osds[osdid]}')
print()
if len(deep_scrub_osds) > 0:
print('{} Not Deep Scrubbed PGs:\n{}\n\nTop OSDs: '.format(len(deep_scrub_pgs)," ".join(deep_scrub_pgs)))
for osdid in sorted(deep_scrub_osds, key=deep_scrub_osds.get)[-10:]:
print(f'osd.{osdid},{deep_scrub_osds[osdid]}')
print()
f.close()