Package starcluster :: Package balancers :: Package sge :: Module visualizer
[hide private]
[frames] | no frames]

Source Code for Module starcluster.balancers.sge.visualizer

 1  """ 
 2  StarCluster SunGrinEngine stats visualizer module 
 3  """ 
 4  import os 
 5  import numpy as np 
 6  from datetime import datetime 
 7  import matplotlib.pyplot as plt 
 8   
 9  from starcluster.logger import log 
10   
11   
12 -class SGEVisualizer(object):
13 """ 14 Stats Visualizer for SGE Load Balancer 15 stats_file - file containing SGE load balancer stats 16 pngpath - directory to dump the stat plots to 17 """
18 - def __init__(self, stats_file, pngpath):
19 self.pngpath = pngpath 20 self.stats_file = stats_file 21 self.records = None
22
23 - def read(self):
24 list = [] 25 file = open(self.stats_file, 'r') 26 for line in file: 27 parts = line.rstrip().split(',') 28 a = [datetime.strptime(parts[0], '%Y-%m-%d %H:%M:%S.%f'), 29 int(parts[1]), int(parts[2]), int(parts[3]), int(parts[4]), 30 int(parts[5]), int(parts[6]), float(parts[7])] 31 list.append(a) 32 file.close() 33 names = ['dt', 'hosts', 'running_jobs', 'queued_jobs', 34 'slots', 'avg_duration', 'avg_wait', 'avg_load'] 35 self.records = np.rec.fromrecords(list, names=','.join(names))
36
37 - def graph(self, yaxis, title):
38 if self.records is None: 39 log.error("ERROR: File hasn't been read() yet.") 40 return -1 41 fig = plt.figure() 42 ax = fig.add_subplot(111) 43 ax.plot(self.records.dt, yaxis) 44 ax.grid(True) 45 fig.autofmt_xdate() 46 filename = os.path.join(self.pngpath, title + '.png') 47 plt.savefig(filename, dpi=100) 48 log.debug("saved graph %s." % title) 49 plt.close(fig) # close it when its done
50
51 - def graph_all(self):
52 self.read() 53 vals = {'queued': self.records.queued_jobs, 54 'running': self.records.running_jobs, 55 'num_hosts': self.records.hosts, 56 #'slots': self.records.slots, 57 'avg_duration': self.records.avg_duration, 58 'avg_wait': self.records.avg_wait, 59 'avg_load': self.records.avg_load} 60 for sub in vals: 61 self.graph(vals[sub], sub) 62 log.info("Done making graphs.")
63