Newer
Older
Chris Hines
committed
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
#!/usr/bin/python
xprtudpcounters="proto,port,bind_count,rpcsends,rpcreceives,badxids,inflightsends,backlogutil".split(',')
xprttcpcounters="proto,port,bind_count,connect_count,connect_time,idle_time,rpcsends,rpcreceives,badxids,inflightsends,backlogutil".split(',')
xprtrdmacounters="proto,port,bind_count,connect_count,idle_time,rpcsends,rpcreceives,badxids,backlogutil,read_chunks,write_chunks,reply_chunks,total_rdma_req',total_rdma_rep,pullup,fixup,hardway,failed_marshal,bad_reply".split(',')
NfsOpCounters="operations,transmissions,major_timeouts,bytes_sent,bytes_recv,queue_time,response_time,request_time".split(',')
OPS="WRITE,OPEN,CLOSE,ACCESS,RENAME,SYMLINK,CREATE".split(',')
NfsEventCounters = [
'inoderevalidates',
'dentryrevalidates',
'datainvalidates',
'attrinvalidates',
'vfsopen',
'vfslookup',
'vfspermission',
'vfsupdatepage',
'vfsreadpage',
'vfsreadpages',
'vfswritepage',
'vfswritepages',
'vfsreaddir',
'vfssetattr',
'vfsflush',
'vfsfsync',
'vfslock',
'vfsrelease',
'congestionwait',
'setattrtrunc',
'extendwrite',
'sillyrenames',
'shortreads',
'shortwrites',
'delay'
]
NfsByteCounters = [
'normalreadbytes',
'normalwritebytes',
'directreadbytes',
'directwritebytes',
'serverreadbytes',
'serverwritebytes',
'readpages',
'writepages'
]
class DeviceData:
"""DeviceData objects provide methods for parsing and displaying
data for a single mount grabbed from /proc/self/mountstats
"""
def __init__(self):
self.__nfs = dict()
self.__nfs_device = dict()
def fstype(self):
return self.__nfs_device['fstype']
def tags(self):
return ",".join(["{}={}".format(key,value) for key,value in self.__nfs_device.items()])
def values(self):
try:
values = ",".join(["{}={}".format(key,value) for key,value in self.__nfs['bytes']])
values +=","
values += ",".join(["{}={}".format(key,value) for key,value in self.__nfs['events']])
values +=","
opvalues = []
for op in OPS:
opvalues.append(",".join(["{}_{}={}".format(op,key,value) for key,value in self.__nfs[op]]))
values += ",".join(opvalues)
except KeyError as e:
# key error occurs if we haven't filtered the lustre mount points from the NFS mount points yet
return None
return values
def __parse_device_line(self, words):
if words[0] == 'device':
self.__nfs_device['export'] = words[1]
self.__nfs_device['mountpoint'] = words[4]
self.__nfs_device['fstype'] = words[7]
def __parse_bytes_line(self, words):
if words[0] == 'bytes:':
self.__nfs['bytes'] = zip(NfsByteCounters,[ int(x) for x in words[1:]])
def __parse_events_line(self,words):
if words[0] == 'events:':
self.__nfs['events'] = zip(NfsEventCounters,[int(x) for x in words[1:]])
def __parse_ops_line(self,words):
if words[0][:-1] in OPS:
self.__nfs[words[0][:-1]] = zip(NfsOpCounters, [ int(x) for x in words[1:]])
def __parse_xprt_line(self, words):
if words[0] == 'xprt:':
if words[1] == 'udp':
self._rpc = zip(xprtudpcounters, words[1:11])
if words[1] == 'tcp':
self._rpc = zip(xprttcpcounters, words[1:11])
if words[1] == 'rdma':
self._rpc = zip(xprtrdmacounters, words[1:11])
def parse_stats(self, lines):
"""Turn a list of lines from a mount stat file into a
dictionary full of stats, keyed by name
"""
foundnfs = False
foundrpc = False
for line in lines:
words = line.split()
if len(words) == 0:
continue
self.__parse_device_line(words)
self.__parse_bytes_line(words)
self.__parse_events_line(words)
self.__parse_ops_line(words)
self.__parse_xprt_line(words)
def parse_stats_file(filename):
"""pop the contents of a mountstats file into a dictionary,
keyed by mount point. each value object is a list of the
lines in the mountstats file corresponding to the mount
point named in the key.
"""
ms_dict = dict()
key = ''
f = open(filename)
for line in f.readlines():
words = line.split()
if len(words) == 0:
continue
if line.startswith("no device mounted") :
continue
if words[0] == 'device':
key = words[4]
new = [ line.strip() ]
elif 'nfs' in words or 'nfs4' in words:
key = words[3]
new = [ line.strip() ]
else:
new += [ line.strip() ]
ms_dict[key] = new
f.close
return ms_dict
def iostats(mountstats):
stats = {}
for device in mountstats:
stats[device] = DeviceData()
stats[device].parse_stats(mountstats[device])
return stats
def print_influx_line_proto(device,stats):
try:
if not 'nfs' in stats.fstype():
return
print("mountstats,{} {}".format(stats.tags(), stats.values()))
except:
return
mountstats = parse_stats_file("/proc/self/mountstats")
stats = iostats(mountstats)
for device in stats:
print_influx_line_proto(device,stats[device])