-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgpfs-perf-old.py
executable file
·443 lines (357 loc) · 15.8 KB
/
gpfs-perf-old.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
#!/usr/bin/python
import sys
import time
from socket import *
import re
import json
import argparse
import os
##########################################################################################################################
Debug=False
##########################################################################################################################
metrics_ops = {
'nsdfs': ['gpfs_nsdfs_bytes_read', 'gpfs_nsdfs_bytes_written','gpfs_nsdfs_read_ops','gpfs_nsdfs_write_ops'],
'nsdds': ['gpfs_nsdds_max_disk_wait_rd', 'gpfs_nsdds_max_disk_wait_wr', 'gpfs_nsdds_max_queue_wait_rd', 'gpfs_nsdds_max_queue_wait_wr', 'gpfs_nsdds_tot_disk_wait_rd', 'gpfs_nsdds_tot_disk_wait_wr', 'gpfs_nsdds_tot_queue_wait_rd', 'gpfs_nsdds_tot_queue_wait_wr'],
'gpfsfs': ['gpfs_fs_bytes_read', 'gpfs_fs_bytes_written', 'gpfs_fs_max_disk_wait_rd', 'gpfs_fs_max_disk_wait_wr', 'gpfs_fs_max_queue_wait_rd', 'gpfs_fs_max_queue_wait_wr', 'gpfs_fs_read_ops', 'gpfs_fs_write_ops','gpfs_fs_tot_disk_wait_rd','gpfs_fs_tot_disk_wait_wr','gpfs_fs_tot_queue_wait_rd','gpfs_fs_tot_queue_wait_wr'],
'cpu': ['cpu_user', 'cpu_system', 'cpu_iowait', 'cpu_context', 'cpu_idle', 'cpu_interrupts', 'cpu_nice'],
'mem': ['mem_active', 'mem_buffers', 'mem_cached', 'mem_dirty', 'mem_memfree', 'mem_memtotal'],
'net': ['netdev_bytes_r', 'netdev_bytes_s', 'netdev_errors_r', 'netdev_errors_s', 'netdev_packets_r', 'netdev_packets_s', 'netdev_drop_r', 'netdev_drop_s'],
'netstat': ['ns_closewait', 'ns_established', 'ns_listen', 'ns_local_bytes_r', 'ns_local_bytes_s', 'ns_localconn', 'ns_remote_bytes_r', 'ns_remote_bytes_s', 'ns_remoteconn', 'ns_timewait'],
'load': ['load1', 'load5', 'load15', 'jobs'],
'df': ['df_free', 'df_total', 'df_used' ],
'afm': ['gpfs_afm_bytes_pending', 'gpfs_afm_num_queued_msgs', 'gpfs_afm_longest_time', 'gpfs_afm_avg_time', 'gpfs_afm_used_q_memory','gpfs_afm_bytes_read','gpfs_afm_bytes_written', 'gpfs_afm_shortest_time', 'gpfs_afm_longest_time', 'gpfs_afm_avg_time', 'gpfs_afm_conn_esta', 'gpfs_afm_conn_broken', 'gpfs_afm_fset_expired', 'gpfs_afm_tot_read_time', 'gpfs_afm_tot_write_time'],
'nfs': ['nfs_read', 'nfs_write', 'nfs_read_ops', 'nfs_write_ops', 'nfs_read_lat', 'nfs_write_lat'],
'smb': ['op_outbytes', 'op_inbytes', 'request_count', 'current_connections'],
'waiters': ['gpfs_wt_count_all','gpfs_wt_count_local_io','gpfs_wt_count_network_io','gpfs_wt_count_thcond','gpfs_wt_count_thmutex','gpfs_wt_count_delay','gpfs_wt_count_syscall']
}
metrics_filters = {
'nsdfs': ['gpfs_fs_name'],
'nsdds': [],
'gpfsfs': ['gpfs_fs_name', 'cluster_name'],
'cpu': [],
'mem': [],
'net': [],
'load': [],
'df': [],
'afm': ['node'],
'netstat': [],
'nfs': [],
'smb': [],
'waiters': [],
}
rowInfoFunctions = {
'nsdfs': 'nsdfs',
'nsdds': 'nsdds',
'gpfsfs': 'gpfsfs',
'cpu': 'cpu',
'mem': 'mem',
'net': 'net',
'netstat': 'netstat',
'load': 'load',
'df': 'df',
'afm': 'afm',
'smb': 'smb',
'nfs': 'nfs',
'waiters': 'waiters',
}
tagqueries = {
'nsdfs': 'nsdfs_query',
'gpfsfs': 'gpfsfs_query',
'nsdds': 'nsdds_query',
'cpu': 'cpu_query',
'mem': 'mem_query',
'net': 'net_query',
'netstat': 'netstat_query',
'load': 'load_query',
'df': 'df_query',
'afm': 'afm_query',
'nfs': 'nfs_query',
'smb': 'smb_query',
'waiters': 'waiters_query',
}
##########################################################################################################################
def RepresentsInt(s):
try:
int(s)
return True
except ValueError:
return False
def RepresentsFloat(s):
try:
float(s)
return True
except ValueError:
return False
##########################################################################################################################
def queryInfo(client, query):
client.sendQuery( query )
answer = client.receiveAnswer()
parsed_json = json.loads(answer)
legend = parsed_json['legend']
keys = []
for leg in legend:
keys.append(leg['keys'][0])
return (keys, parsed_json['rows'])
##########################################################################################################################
class rowInfo_gpfsfs():
def __init__(self, host, fs, metric, cluster):
self.host = host
self.filesystem = fs
self.metric = metric
self.cluster=cluster
class rowInfo_nsdfs():
def __init__(self, host, fs, metric):
self.host = host
self.filesystem = fs
self.metric = metric
class rowInfo_nsdds():
def __init__(self, host, nsd, metric):
self.nsd = nsd
self.host = host
self.metric = metric
class rowInfo_net():
def __init__(self, host, nic, metric):
self.host = host
self.nic = nic
self.metric = metric
class rowInfo_waiters():
def __init__(self, host, threshold, waiter):
self.host = host
self.threshold_time = threshold
self.waiter = waiter
class rowInfo():
def __init__(self, host, metric):
self.host = host
self.metric = metric
##########################################################################################################################
class Funcs():
def gpfsfs(self, array):
return rowInfo_gpfsfs(array[0], array[3], array[4], array[2])
def nsdfs(self, array):
return rowInfo_nsdfs(array[0], array[2], array[3])
def nsdds(self, array):
#print array
return rowInfo_nsdds(array[0], array[2], array[3])
def cpu(self, array):
return rowInfo(array[0], array[2])
def load(self, array):
return rowInfo(array[0], array[2])
def df(self, array):
return rowInfo_nsdfs(array[0], array[2], array[3])
def net(self, array):
return rowInfo_net(array[0], array[2], array[3])
def netstat(self, array):
return rowInfo(array[0], array[2])
def afm(self, array):
return rowInfo(array[0], array[2])
def mem(self, array):
return rowInfo(array[0], array[2])
def nfs(self, array):
return rowInfo(array[0], array[2])
def smb(self, array):
return rowInfo(array[0], array[2])
def waiters(self, array):
return rowInfo_waiters(array[0], array[2], array[3])
def nsdfs_query(self, rowinfo):
return "filesystem=%s,host=%s,operation=%s" % (rowinfo.filesystem, rowinfo.host, rowinfo.metric)
def nsdds_query(self, rowinfo):
#print(array)
return "host=%s,nsd=%s,operation=%s" % (rowinfo.host, rowinfo.nsd, rowinfo.metric)
def gpfsfs_query(self, rowinfo):
return "filesystem=%s,host=%s,operation=%s,cluster=%s" % (rowinfo.filesystem, rowinfo.host, rowinfo.metric, rowinfo.cluster)
def cpu_query(self, rowinfo):
return "type=%s,host=%s" % (rowinfo.metric, rowinfo.host)
def mem_query(self, rowinfo):
return "type=%s,host=%s" % (rowinfo.metric, rowinfo.host)
def load_query(self, rowinfo):
return "type=%s,host=%s" % (rowinfo.metric, rowinfo.host)
def net_query(self, rowinfo):
return "interface=%s,host=%s,operation=%s" % (rowinfo.nic, rowinfo.host, rowinfo.metric)
def df_query(self, rowinfo):
return "mountpoint=%s,host=%s,info=%s" % (rowinfo.filesystem, rowinfo.host, rowinfo.metric)
def afm_query(self, rowinfo):
return "host=%s,metrics=%s" % (rowinfo.host, rowinfo.metric)
def netstat_query(self, rowinfo):
return "host=%s,operation=%s" % (rowinfo.host, rowinfo.metric)
def nfs_query(self, rowinfo):
return "host=%s,operation=%s" % (rowinfo.host, rowinfo.metric)
def smb_query(self, rowinfo):
return "host=%s,operation=%s" % (rowinfo.host, rowinfo.metric)
def waiters_query(self, rowinfo):
return "host=%s,threshold_time=%s,waiter=%s" % (rowinfo.host, rowinfo.threshold_time, rowinfo.waiter)
##########################################################################################################################
class CollectorClient():
def __init__(self, server, socketname, Debug, port=9084, maxChunkSize=16384):
self.chunk = maxChunkSize
self.unix_socket = socketname
if os.path.exists(socketname):
self.address = socketname
family = AF_UNIX
if Debug:
print "Connecting to collector at endpoint: %s" % (self.address)
else:
family = AF_INET
self.address = (server, port)
if Debug:
print "Connecting to collector at endpoint: %s:%s" % (self.address)
self.s = socket(family, SOCK_STREAM)
self.answer = ""
def connect(self):
try:
self.s.connect((self.address))
self.s.settimeout( 1 )
except error as err:
print("Error: " + str(err))
sys.exit(1)
def disconnect(self):
self.s.close()
def sendQuery(self, query):
try:
self.s.send(query.encode(encoding='UTF-8'))
except error as err:
print "Error: " + str(err)
sys.exit(1)
def receiveAnswerOLD(self):
self.answer = ""
while True:
try:
out = self.s.recv(self.chunk)
except:
break
if len(out) <= 0:
self.answer = re.sub(r'\n\.',r'',self.answer)
return self.answer
self.answer += out
self.answer = re.sub(r'\n\.',r'',self.answer)
return self.answer
def receiveAnswer(self):
self.answer = ""
while True:
out = ""
try:
out = self.s.recv(self.chunk.decode(encoding='UTF-8'))
if len(out) == 0:
if self.answer.endswith("}\n.\n") == True or self.answer.endswith("}\n.") == True:
self.answer = re.sub(r'\n\.\n',r'',self.answer)
self.answer = re.sub(r'\n\.',r'',self.answer)
self.s.close()
return self.answer
except:
self.answer += out
if self.answer.endswith("}\n.\n") == True or self.answer.endswith("}\n.") == True:
break
self.answer += out
self.answer = re.sub(r'\n\.\n',r'',self.answer)
self.s.close()
return self.answer
##########################################################################################################################
def zimon_metrics(metric_group, table, query_filter, numbuckets, period, cli, Debug):
global metrics_ops
global metrics_filters
query = "get -j metrics %s last %d bucket_size %d %s\n" % (','.join(metrics_ops[metric_group]), numbuckets, period, query_filter)
if Debug:
print "Query to Collector : %s" %query
try:
(keys, rows) = queryInfo(cli, query)
except ValueError as e:
print e
return
f = Funcs()
parsefunc = getattr( f, rowInfoFunctions[metric_group])
gettagsquery = getattr( f, tagqueries[metric_group])
InfoRows = {}
index=0
for key in keys:
pieces = key.split('|')
InfoRows[index] = parsefunc( pieces )
index += 1
timestamp = 0
filename = ""
queries = []
for x in range(0,numbuckets):
row = rows[x]
if sum(row['nsamples']) != 0:
timestamp = row['tstamp']
index = 0
for val in row['values']:
if RepresentsInt(str(val)) or RepresentsFloat(str(val)):
_val = float(str(val))
influxQuery = table + "," + gettagsquery(InfoRows[index]) + " value=" + str(_val) + " " + str( timestamp * 1000000000 )
queries.append(influxQuery)
index += 1
for p in queries:
print p
############################################################################################
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--metric', type=str, required=True,
help='name of the metric. Possible metrics: %s'%", ".join(metrics_ops.keys()))
parser.add_argument('--collector', type=str, required=False, default='localhost',
help='hostname or ip of the host running the pmcollector process')
parser.add_argument('--collsocket', type=str, required=False,
help='UNIX socket for the pmcollector process')
parser.add_argument('--collport', type=int, required=False, default=9084,
help='TCP port number of the pmcollector process')
parser.add_argument('metric_arguments', nargs='*',
help='additional arguments required by specific metrics in the form of key=value')
parser.add_argument('--delay', type=int, required=False, default=5,
help='This is how often a caller invokes this script. This value is internally used to calculate the size of buckets to query to PMCollector')
parser.add_argument('--period', type=int, required=False, default=1,
help='This value must match the ZiMon period for the selected metric (according to output of the command \'mmperfmon config show\'')
parser.add_argument('--table', type=str, required=False,
help='This name of the table (\'measurement\' in the Influx terminology) where insert data into. Default is the metrics\'s name itself')
parser.add_argument('--debug', action='store_true', required=False, default=False,
help='print out debug information')
args = parser.parse_args()
metric_arguments={}
for arg in args.metric_arguments:
try:
(key,value)=arg.split('=')
metric_arguments[key]=value
except ValueError:
print("Invalid format for %s. Should be key=value"%arg)
sys.exit(1)
metric=args.metric
if metric not in metrics_ops.keys():
print("Metric %s not available"%metric)
sys.exit(1)
missing_params=set(metrics_filters[metric])-set(metric_arguments)
if len(missing_params)>0:
for p in missing_params:
print "Parameter %s missing"%p
sys.exit(1)
missing_params=set(metric_arguments)-set(metrics_filters[metric])
if len(missing_params)>0:
for p in missing_params:
print "Parameter %s not supported"%p
sys.exit(1)
Debug = args.debug
collectorhost = args.collector or 'localhost'
collectorsocket = args.collsocket or '/var/run/perfmon/pmcollector.socket'
cli = CollectorClient(collectorhost, collectorsocket, Debug, args.collport)
cli.connect()
delay = args.delay
period = args.period
numbuckets = int( delay / period )
if numbuckets < 1:
numbuckets = 1
received_params = metric_arguments
query_filter=""
array_filter=[]
for p in received_params.keys():
array_filter.append("%s=%s" % (p, received_params[p]) )
if len(array_filter)>0:
query_filter = "from " + ",".join( array_filter )
table = metric
if args.table:
table = args.table
if Debug:
print "Will insert data into measurement : %s" %table
print "Size of bucket : %d" %period
print "Num of buckets to collect : %d" %numbuckets
print "Metric to query : %s" %metric
print "Filters : %s" %(query_filter or 'None')
zimon_metrics(metric, table, query_filter, numbuckets, period, cli, Debug)
##########################################################################################################################
if __name__ == "__main__":
main()