19744: Include text report in HTML report
[arvados.git] / tools / crunchstat-summary / crunchstat_summary / webchart.py
index 790b08da87f1b7894fc4e47511c63d44eda9604e..8adf0fee7eda9c157bd32562cf88e573afea7bf3 100644 (file)
@@ -2,7 +2,11 @@
 #
 # SPDX-License-Identifier: AGPL-3.0
 
-import cgi
+try:
+    from html import escape
+except ImportError:
+    from cgi import escape
+
 import json
 import pkg_resources
 
@@ -10,7 +14,7 @@ import pkg_resources
 class WebChart(object):
     """Base class for a web chart.
 
-    Subclasses must assign JSLIB and JSASSET, and override the
+    Subclasses must assign JSLIB and JSASSETS, and override the
     chartdata() method.
     """
     JSLIB = None
@@ -20,20 +24,29 @@ class WebChart(object):
         self.label = label
         self.summarizers = summarizers
 
-    def html(self):
+    def html(self, bodytext=''):
         return '''<!doctype html><html><head>
         <title>{} stats</title>
         <script type="text/javascript" src="{}"></script>
         <script type="text/javascript">{}</script>
+        <style>
+        table {{
+          width: 80%
+        }}
+        td {{
+          width: 20%;
+        }}
+        </style>
         {}
-        </head><body></body></html>
-        '''.format(cgi.escape(self.label),
-                   self.JSLIB, self.js(), self.headHTML())
+        </head><body>{}</body></html>
+        '''.format(escape(self.label),
+                   self.JSLIB, self.js(), self.headHTML(),
+                   bodytext)
 
     def js(self):
         return 'var chartdata = {};\n{}'.format(
             json.dumps(self.sections()),
-            pkg_resources.resource_string('crunchstat_summary', self.JSASSET))
+            '\n'.join([pkg_resources.resource_string('crunchstat_summary', jsa).decode('utf-8') for jsa in self.JSASSETS]))
 
     def sections(self):
         return [
@@ -41,10 +54,13 @@ class WebChart(object):
                 'label': s.long_label(),
                 'charts': [
                     self.chartdata(s.label, s.tasks, stat)
-                    for stat in (('cpu', 'user+sys__rate'),
-                                 ('mem', 'rss'),
-                                 ('net:eth0', 'tx+rx__rate'),
-                                 ('net:keep0', 'tx+rx__rate'))],
+                    for stat in (('cpu', ['user+sys__rate', 'user__rate', 'sys__rate']),
+                                 ('mem', ['rss']),
+                                 ('net:eth0', ['tx+rx__rate','rx__rate','tx__rate']),
+                                 ('net:keep0', ['tx+rx__rate','rx__rate','tx__rate']),
+                                 ('statfs', ['used', 'total']),
+                                 )
+                    ],
             }
             for s in self.summarizers]