1 from __future__ import print_function
7 from crunchstat_summary import logger
10 class ChartJS(object):
11 JSLIB = 'https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js'
13 def __init__(self, label, summarizers):
15 self.summarizers = summarizers
18 return '''<!doctype html><html><head>
19 <title>{} stats</title>
20 <script type="text/javascript" src="{}"></script>
21 <script type="text/javascript">{}</script>
22 </head><body></body></html>
23 '''.format(cgi.escape(self.label), self.JSLIB, self.js())
26 return 'var sections = {};\n{}'.format(
27 json.dumps(self.sections()),
28 pkg_resources.resource_string('crunchstat_summary', 'chartjs.js'))
33 'label': s.long_label(),
34 'charts': self.charts(s.label, s.tasks),
36 for s in self.summarizers]
38 def charts(self, label, tasks):
48 'dataPoints': self._datapoints(
49 label=uuid, task=task, series=task.series[stat]),
51 for uuid, task in tasks.iteritems()
54 'text': '{}: {} {}'.format(label, stat[0], stat[1]),
58 for stat in (('cpu', 'user+sys__rate'),
60 ('net:eth0', 'tx+rx__rate'),
61 ('net:keep0', 'tx+rx__rate'))]
63 def _datapoints(self, label, task, series):
65 {'x': pt[0].total_seconds(), 'y': pt[1]}
68 points[-1]['markerType'] = 'cross'
69 points[-1]['markerSize'] = 12