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);
57 def __init__(self, label, summarizers):
59 self.summarizers = summarizers
61 def html(self, beforechart='', afterchart=''):
62 return '''<!doctype html><html><head>
63 <title>{} stats</title>
64 <script type="text/javascript" src="{}"></script>
65 <script type="text/javascript">{}</script>
78 <div class="content" id="tophtml">
86 <div id="chart"></div>
90 <div class="content" id="bottomhtml">
97 '''.format(escape(self.label),
107 return 'var chartdata = {};\n{}'.format(
108 json.dumps(self.sections()),
109 '\n'.join([pkg_resources.resource_string('crunchstat_summary', jsa).decode('utf-8') for jsa in self.JSASSETS]))
114 'label': s.long_label(),
116 self.chartdata(s.label, s.tasks, stat)
117 for stat in (('cpu', ['user+sys__rate', 'user__rate', 'sys__rate']),
119 ('net:eth0', ['tx+rx__rate','rx__rate','tx__rate']),
120 ('net:keep0', ['tx+rx__rate','rx__rate','tx__rate']),
121 ('statfs', ['used', 'total']),
125 for s in self.summarizers]
127 def chartdata(self, label, tasks, stat):
128 """Return chart data for the given tasks.
130 The returned value will be available on the client side as an
131 element of the "chartdata" array.
133 raise NotImplementedError()
136 """Return extra HTML text to include in HEAD."""