Skip to content

Instantly share code, notes, and snippets.

@gswallow
Created September 30, 2015 03:27
Show Gist options
  • Save gswallow/26c1d8139dd1b1ffff5c to your computer and use it in GitHub Desktop.
Save gswallow/26c1d8139dd1b1ffff5c to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
import sys
import string
import datetime
import matplotlib.pyplot as plt
with open(sys.argv[1], 'r') as f:
metrics = f.readlines()
labels = metrics[2].split()[2:]
m, d, y = metrics[0].split()[3].split('/')
# ['DEV', 'tps', 'rd_sec/s', 'wr_sec/s', 'avgrq-sz', 'avgqu-sz', 'await', 'svctm', '%util']
devs = {}
for l in metrics[3:]:
metrics_line = l.split()
dev = metrics_line[2]
t = metrics_line[0]
ampm = metrics_line[1]
data = metrics_line[3:]
#We have to convert the timestamps to python datetime objects, and comma
#separated floats to point separated floats
if ampm == "AM":
if int(t.split(':')[0]) == 12:
t = datetime.datetime(int(y), int(m), int(d), 0, int(t.split(':')[1]), int(t.split(':')[2]))
else:
t = datetime.datetime(int(y), int(m), int(d), int(t.split(':')[0]), int(t.split(':')[1]), int(t.split(':')[2]))
else:
if int(t.split(':')[0]) == 12:
t = datetime.datetime(int(y), int(m), int(d), int(t.split(':')[0]), int(t.split(':')[1]), int(t.split(':')[2]))
else:
t = datetime.datetime(int(y), int(m), int(d), int(t.split(':')[0]) + 12, int(t.split(':')[1]), int(t.split(':')[2]))
for i in range(len(data)):
data[i] = string.atof(data[i].replace(',', '.'))
#And then we save it
if devs.has_key(dev):
devs[dev].append((t, data))
else:
devs[dev] = [(t, data)]
for dev in devs.iterkeys():
fig = plt.figure(figsize=[8.5,14])
fig.subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=1.1)
for i in range(len(labels[1:])): #We do not count the DEV label
dates = []
times = []
values = []
# Note that there may be a need for two separate for loops here:
for t, v in devs[dev]:
dates.append(t)
times.append(t.strftime('%H:%H:%S'))
values.append(v[i])
axes = fig.add_subplot(8,1,i+1)
axes.grid(True)
axes.set_title(str(dev), fontsize=12)
axes.set_xlabel(dates[0].strftime('%m/%d/%y'), fontsize=12)
axes.set_xticklabels(range(2, 24, 2), rotation='vertical', ha='left', va='top')
axes.set_ylabel(labels[1+i])
axes.tick_params(axis='both', which='major', labelsize=8)
axes.tick_params(axis='both', which='minor', labelsize=7)
axes.plot(dates, values, linestyle='-')
fig.savefig(str(dev).replace('/', '_') + '-' + dates[0].strftime('%m%d%Y'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment