-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisklatency.py
More file actions
74 lines (62 loc) · 1.71 KB
/
disklatency.py
File metadata and controls
74 lines (62 loc) · 1.71 KB
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
import os
import time
import sys
import operator
import getopt
tbl = {}
def usage():
print 'usage:\n', sys.argv[0], '[-h|--help] [-r|--read] [-w|--write] [-o|--ops]'
try:
opts, args = getopt.getopt(sys.argv[1:], 'horw', ['help', 'read', 'write', 'ops'])
except getopt.GetoptError, err:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
help = False
read_enable = False
write_enable = False
ops = 0
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-r", "--read"):
read_enable = True
elif o in ("-w", "--write"):
write_enable = True
elif o in ('-o', '--ops'):
ops = -2
else:
assert False, "unhandled option"
if not read_enable and not write_enable:
read_enable = True
write_enable = True
read_col = 4 + ops
write_col = 7 + ops
try:
while True:
#raw = os.popen("cat data | sed '1,2d' | grep -v da0s").read().split('\n')
raw = os.popen("gstat -b | sed '1,2d' | grep -v da0s").read().split('\n')
for count in range(0,len(raw)-1):
disk = raw[count].split()[9]
r = raw[count].split()[read_col]
w = raw[count].split()[write_col]
if disk in tbl:
if read_enable:
tbl[disk] += float(r)
if write_enable:
tbl[disk] += float(w)
else:
if read_enable and write_enable:
tbl[disk] = float(r) + float(w)
elif write_enable:
tbl[disk] = float(w)
elif read_enable:
tbl[disk] = float(r)
os.system('clear')
for k, v in sorted(tbl.iteritems(), key=operator.itemgetter(1), reverse=True):
print k, " = ", v
time.sleep(1)
except KeyboardInterrupt:
print
sys.exit(0)