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
26 font-family: "Roboto", "Helvetica", "Arial", sans-serif;
28 color: rgba(0, 0, 0, 0.87);
33 box-shadow: 0px 1px 5px 0px rgba(0,0,0,0.2),0px 2px 2px 0px rgba(0,0,0,0.14),0px 3px 1px -2px rgba(0,0,0,0.12);
38 padding: 2px 16px 8px 16px;
49 border-top: 1px solid rgba(224, 224, 224, 1);
53 border-top: 1px solid rgba(224, 224, 224, 1);
60 def __init__(self, label, summarizers):
62 self.summarizers = summarizers
64 def html(self, beforechart='', afterchart=''):
65 return '''<!doctype html><html><head>
66 <title>{} stats</title>
67 <script type="text/javascript" src="{}"></script>
68 <script type="text/javascript">{}</script>
81 <div class="content" id="tophtml">
89 <div id="chart"></div>
93 <div class="content" id="bottomhtml">
100 '''.format(escape(self.label),
110 return 'var chartdata = {};\n{}'.format(
111 json.dumps(self.sections()),
112 '\n'.join([pkg_resources.resource_string('crunchstat_summary', jsa).decode('utf-8') for jsa in self.JSASSETS]))
117 'label': s.long_label(),
119 self.chartdata(s.label, s.tasks, stat)
120 for stat in (('cpu', ['user+sys__rate', 'user__rate', 'sys__rate']),
122 ('net:eth0', ['tx+rx__rate','rx__rate','tx__rate']),
123 ('net:keep0', ['tx+rx__rate','rx__rate','tx__rate']),
124 ('statfs', ['used', 'total']),
128 for s in self.summarizers]
130 def chartdata(self, label, tasks, stat):
131 """Return chart data for the given tasks.
133 The returned value will be available on the client side as an
134 element of the "chartdata" array.
136 raise NotImplementedError()
139 """Return extra HTML text to include in HEAD."""