Import some stuff


In [16]:
from lib import MongoBackend
from matplotlib import pyplot as plt
from matplotlib.pyplot import show
from collections import defaultdict
from pprint import pprint
backend = MongoBackend('master')

In [20]:
def get_timelines(experiment, query):
    get_timeline=lambda d: d[0][1]
    raw_timeline_data = backend.query(experiment, query )
    metrics_timeline = get_timeline(raw_timeline_data)
    metrics= defaultdict(list)
    
    for m in metrics_timeline:
        metrics['time'].append(m[0])
        master_metrics = m[1]['master']
        for k,v in master_metrics.iteritems():
                metrics[k].append(v)
        
    print metrics.keys()    
    # special cases
    metrics['cpu']= map(lambda i: 100-i, metrics['cpu_idle'])
    return metrics

def plot_timeline(subplot, x,y, title=None, xlabel=None, ylabel=None):
    subplot.plot(x,y)
    if title: subplot.set_title(title)
    if ylabel: subplot.set_ylabel(ylabel)
    if xlabel: subplot.set_xlabel(xlabel)
    

def plot_timelines(experiment, query):
    tm = get_timelines(experiment,query)
    f, (ax1,ax2) = plt.subplots(2, sharex=True)
    plot_timeline(ax1,tm['time'], tm['mem_free'], "Free Memory", 'Time (sec)', 'GB')
    plot_timeline(ax2, tm['time'], tm['cpu'],"CPU Utilization", None, '%')
    plt.show()

plot_timelines('imr_w2v_vectorize',({"lines":1001000},{'metrics_timeline':1}) ) #failed

plot_timelines('imr_w2v_vectorize',({"lines":251000},{'metrics_timeline':1}) )


[u'pkts_out', u'cpu_idle', u'cpu_num', u'os_release', u'cpu_wio', u'cpu_user', u'load_fifteen', u'gexec', u'io_read', u'mem_total', u'cpu_speed', u'mem_cached', u'swap_total', u'bytes_in', u'cpu_aidle', u'boottime', u'io_write', u'cpu_nice', u'os_name', u'part_max_used', u'swap_free', u'bytes_out', u'mem_buffers', u'pkts_in', u'load_five', u'load_one', u'disk_free', u'machine_type', u'proc_total', u'mem_free', u'disk_total', u'mem_shared', u'cpu_system', u'proc_run', 'time']
[u'pkts_out', u'cpu_idle', u'cpu_num', u'os_release', u'cpu_wio', u'cpu_user', u'load_fifteen', u'gexec', u'io_read', u'mem_total', u'cpu_speed', u'mem_cached', u'swap_total', u'bytes_in', u'cpu_aidle', u'boottime', u'io_write', u'cpu_nice', u'os_name', u'part_max_used', u'swap_free', u'bytes_out', u'mem_buffers', u'pkts_in', u'load_five', u'load_one', u'disk_free', u'machine_type', u'proc_total', u'mem_free', u'disk_total', u'mem_shared', u'cpu_system', u'proc_run', 'time']

In [48]:


In [38]:
#backend.plot_query('imr_w2v_vectorize', ({},{'lines':1, 'time':1}))

In [ ]: