1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
6 from html import escape
14 class WebChart(object):
15 """Base class for a web chart.
17 Subclasses must assign JSLIB and JSASSETS, and override the
23 def __init__(self, label, summarizers):
25 self.summarizers = summarizers
28 return '''<!doctype html><html><head>
29 <title>{} stats</title>
30 <script type="text/javascript" src="{}"></script>
31 <script type="text/javascript">{}</script>
33 </head><body></body></html>
34 '''.format(escape(self.label),
35 self.JSLIB, self.js(), self.headHTML())
38 return 'var chartdata = {};\n{}'.format(
39 json.dumps(self.sections()),
40 '\n'.join([pkg_resources.resource_string('crunchstat_summary', jsa).decode('utf-8') for jsa in self.JSASSETS]))
45 'label': s.long_label(),
47 self.chartdata(s.label, s.tasks, stat)
48 for stat in (('cpu', ['user+sys__rate', 'user__rate', 'sys__rate']),
50 ('net:eth0', ['tx+rx__rate','rx__rate','tx__rate']),
51 ('net:keep0', ['tx+rx__rate','rx__rate','tx__rate']),
52 ('statfs', ['used', 'total']),
56 for s in self.summarizers]
58 def chartdata(self, label, tasks, stat):
59 """Return chart data for the given tasks.
61 The returned value will be available on the client side as an
62 element of the "chartdata" array.
64 raise NotImplementedError()
67 """Return extra HTML text to include in HEAD."""