1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 from __future__ import print_function
12 from crunchstat_summary import logger
15 class ChartJS(object):
16 JSLIB = 'https://cdnjs.cloudflare.com/ajax/libs/canvasjs/1.7.0/canvasjs.min.js'
18 def __init__(self, label, summarizers):
20 self.summarizers = summarizers
23 return '''<!doctype html><html><head>
24 <title>{} stats</title>
25 <script type="text/javascript" src="{}"></script>
26 <script type="text/javascript">{}</script>
27 </head><body></body></html>
28 '''.format(cgi.escape(self.label), self.JSLIB, self.js())
31 return 'var sections = {};\n{}'.format(
32 json.dumps(self.sections()),
33 pkg_resources.resource_string('crunchstat_summary', 'chartjs.js'))
38 'label': s.long_label(),
39 'charts': self.charts(s.label, s.tasks),
41 for s in self.summarizers]
43 def _axisY(self, tasks, stat):
45 for task in tasks.itervalues():
46 for pt in task.series[stat]:
47 ymax = max(ymax, pt[1])
48 ytick = math.exp((1+math.floor(math.log(ymax, 2)))*math.log(2))/4
50 'gridColor': '#cccccc',
55 'valueFormatString': "''",
58 def charts(self, label, tasks):
61 'axisY': self._axisY(tasks=tasks, stat=stat),
66 'dataPoints': self._datapoints(
67 label=uuid, task=task, series=task.series[stat]),
69 for uuid, task in tasks.iteritems()
72 'text': '{}: {} {}'.format(label, stat[0], stat[1]),
76 for stat in (('cpu', 'user+sys__rate'),
78 ('net:eth0', 'tx+rx__rate'),
79 ('net:keep0', 'tx+rx__rate'))]
81 def _datapoints(self, label, task, series):
83 {'x': pt[0].total_seconds(), 'y': pt[1]}
86 points[-1]['markerType'] = 'cross'
87 points[-1]['markerSize'] = 12