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

Source Code for Module starcluster.balancers.sge.visualizer

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