content, fontsize=8, horizontalalignment='left', verticalalignment='top') parser = OptionParser() parser.add_option("-i", "--interval", dest="interval", help="The interval", metavar="INTEGER", default=1) (options, args) = parser.parse_args() (input_path, output_path) = args sar = Sar(input_path, int(options.interval)) metric_names = sorted(sar.get_metric_names()) fig, axes = plt.subplots(nrows=metric_names.__len__(), sharex=True) fig.set_size_inches(10, 24) fig.subplots_adjust(top=0.98, left=0.45, right=0.92, bottom=0.01) for i, ax in enumerate(axes): t, x = sar.get_metric2(metric_names[i]) ax.fill_between(t, [0] * t.__len__(), x, linewidth=0, color="purple") ax.set_axis_off() put_text(fig, ax, metric_names[i], x) fig.savefig(output_path)
- DATETIME: %(start)s - %(stop)s - H/W - CPU: %(cpucount)d - RAM: %(ramsize).2f GB - SWAP: %(swapsize).2f GB - DISC: %(iodevs)s - NETWORK: %(ifaces)s - METRICS SUMMARY: %(summary)s ============================================================================== """ if __name__ == '__main__': import sys s = Sar(sys.argv[1]) print hostname = s.hostname start = s.start.strftime("%Y-%m-%d %H:%M:%S") stop = s.stop.strftime("%Y-%m-%d %H:%M:%S") cpucount = s.cpucount ifaces = ", ".join(s.ifaces) iodevs = ", ".join(s.iodevs) ramsize = s.ramsize_gb swapsize = s.swapsize_gb summary = "" data = s.get_averages() keys = sorted(data.keys()) for k in keys:
- DATETIME: %(start)s - %(stop)s - H/W - CPU: %(cpucount)d - RAM: %(ramsize).2f GB - SWAP: %(swapsize).2f GB - DISC: %(iodevs)s - NETWORK: %(ifaces)s - METRICS SUMMARY: %(summary)s ============================================================================== """ if __name__ == '__main__': import sys s = Sar(sys.argv[1]) print hostname = s.hostname start = s.start.strftime("%Y-%m-%d %H:%M:%S") stop = s.stop.strftime("%Y-%m-%d %H:%M:%S") cpucount = s.cpucount ifaces = ", ".join(s.ifaces) iodevs = ", ".join(s.iodevs) ramsize = s.ramsize_gb swapsize = s.swapsize_gb summary="" data = s.get_averages() keys = sorted(data.keys()) for k in keys:
from optparse import OptionParser def put_text(fig,ax,target,data): label_ypos = ax.get_position().y1 av = np.average(data) median =np.median(data) max = np.max(data) content = "%(target)s(med: %(median).1f max: %(max).1f $\mu$: %(av).1f)" %locals() fig.text(0.01, label_ypos, content, fontsize=8, horizontalalignment='left', verticalalignment='top') parser = OptionParser() parser.add_option("-i", "--interval", dest="interval", help="The interval", metavar="INTEGER", default=1) (options, args) = parser.parse_args() (input_path, output_path) = args sar = Sar(input_path, int(options.interval)) metric_names = sorted(sar.get_metric_names()) fig, axes = plt.subplots(nrows=metric_names.__len__(), sharex=True) fig.set_size_inches(10,24) fig.subplots_adjust(top=0.98, left=0.45, right=0.92, bottom=0.01) for i,ax in enumerate(axes): t,x = sar.get_metric2(metric_names[i]) ax.fill_between(t,[0]*t.__len__(),x, linewidth=0, color="purple") ax.set_axis_off() put_text(fig,ax,metric_names[i],x) fig.savefig(output_path)
self.__put_text(fig, ax, "Network[%(iface)s]" % locals()) if __name__ == '__main__': parser = OptionParser() parser.add_option("-i", "--interval", dest="interval", help="The interval", metavar="INTEGER", default=1) parser.add_option("-f", "--font-size", dest="font_size", help="The font size", metavar="INTEGER", default=10) (options, args) = parser.parse_args() (input_path, output_path) = args font = {'family': 'normal', 'size': 10} plt.rc('font', **font) sar = Sar(input_path, int(options.interval)) g = SarGraph([ sar, ], targets=["LOAD", "CPU", "MEM", "DISK", "NET"]) g.dump(output_path)