1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
10 class WebChart(object):
11 """Base class for a web chart.
13 Subclasses must assign JSLIB and JSASSET, and override the
19 def __init__(self, label, summarizers):
21 self.summarizers = summarizers
24 return '''<!doctype html><html><head>
25 <title>{} stats</title>
26 <script type="text/javascript" src="{}"></script>
27 <script type="text/javascript">{}</script>
29 </head><body></body></html>
30 '''.format(cgi.escape(self.label),
31 self.JSLIB, self.js(), self.headHTML())
34 return 'var chartdata = {};\n{}'.format(
35 json.dumps(self.sections()),
36 pkg_resources.resource_string('crunchstat_summary', self.JSASSET))
41 'label': s.long_label(),
43 self.chartdata(s.label, s.tasks, stat)
44 for stat in (('cpu', 'user+sys__rate'),
46 ('net:eth0', 'tx+rx__rate'),
47 ('net:keep0', 'tx+rx__rate'))],
49 for s in self.summarizers]
51 def chartdata(self, label, tasks, stat):
52 """Return chart data for the given tasks.
54 The returned value will be available on the client side as an
55 element of the "chartdata" array.
57 raise NotImplementedError()
60 """Return extra HTML text to include in HEAD."""