From cc87b1f0e7187c25a0705ff1bbda7459a0530c9d Mon Sep 17 00:00:00 2001 From: Peter Amstutz Date: Wed, 3 Jul 2024 16:47:01 -0400 Subject: [PATCH] 21121: Produce limited report if prometheus is not available Arvados-DCO-1.1-Signed-off-by: Peter Amstutz --- .../arvados_cluster_activity/report.py | 48 +++++++++++------ .../crunchstat_summary/webchart.py | 51 +++++++++++-------- 2 files changed, 62 insertions(+), 37 deletions(-) diff --git a/tools/cluster-activity/arvados_cluster_activity/report.py b/tools/cluster-activity/arvados_cluster_activity/report.py index ee1fe9cc4c..0f13d0d36f 100644 --- a/tools/cluster-activity/arvados_cluster_activity/report.py +++ b/tools/cluster-activity/arvados_cluster_activity/report.py @@ -273,14 +273,23 @@ class ClusterActivityReport(object): self.collect_graph(s2, since, to, storage_category, "storage used", "arvados_keep_total_bytes{cluster='%s'}", resampleTo="60min", extra=self.collect_storage_cost) - managed_data_now = s2.tasks[storage_category].series[storage_category,"managed"][-1] - storage_used_now = s2.tasks[storage_category].series[storage_category,"storage used"][-1] + managed_data_now = None + storage_used_now = None - storage_cost = aws_monthly_cost(storage_used_now.y) - dedup_ratio = managed_data_now.y/storage_used_now.y - dedup_savings = aws_monthly_cost(managed_data_now.y) - storage_cost + if len(s2.tasks[storage_category].series[storage_category,"managed"]) > 0: + managed_data_now = s2.tasks[storage_category].series[storage_category,"managed"][-1] + if len(s2.tasks[storage_category].series[storage_category,"storage used"]) > 0: + storage_used_now = s2.tasks[storage_category].series[storage_category,"storage used"][-1] - self.summarizers = [s1, s2] + if managed_data_now and storage_used_now: + storage_cost = aws_monthly_cost(storage_used_now.y) + dedup_ratio = managed_data_now.y/storage_used_now.y + dedup_savings = aws_monthly_cost(managed_data_now.y) - storage_cost + + if self.prom_client: + self.summarizers = [s1, s2] + else: + self.summarizers = [] tophtml = "" bottomhtml = "" @@ -293,25 +302,34 @@ class ClusterActivityReport(object): workbench = workbench[:-1] if to.date() == date.today(): - tophtml.append("""

Cluster status as of {now}

- - - + + data_rows = "" + if managed_data_now and storage_used_now: + data_rows = """ -
Total users{total_users}
Total projects{total_projects}
Total data under management{managed_data_now}
Total storage usage{storage_used_now}
Deduplication ratio{dedup_ratio:.1f}
Approximate monthly storage cost${storage_cost:,.2f}
Monthly savings from storage deduplication${dedup_savings:,.2f}
- """.format(now=date.today(), - total_users=self.total_users, - total_projects=self.total_projects, + """.format( managed_data_now=format_with_suffix_base10(managed_data_now.y), storage_used_now=format_with_suffix_base10(storage_used_now.y), dedup_savings=dedup_savings, storage_cost=storage_cost, dedup_ratio=dedup_ratio, - workbench=workbench)) + ) + + tophtml.append("""

Cluster status as of {now}

+ + + + {data_rows} +
Total users{total_users}
Total projects{total_projects}
+ """.format(now=date.today(), + total_users=self.total_users, + total_projects=self.total_projects, + workbench=workbench, + data_rows=data_rows)) tophtml.append("""

Activity and cost over the {reporting_days} day period {since} to {to}

diff --git a/tools/crunchstat-summary/crunchstat_summary/webchart.py b/tools/crunchstat-summary/crunchstat_summary/webchart.py index 47fc042022..5a1eae46a2 100644 --- a/tools/crunchstat-summary/crunchstat_summary/webchart.py +++ b/tools/crunchstat-summary/crunchstat_summary/webchart.py @@ -74,39 +74,46 @@ class WebChart(object): """.format(i) for i in items) def html(self, beforechart='', afterchart=''): + graph_card = "" + + if self.summarizers: + graph_card = """ +
+
+

Graph

+
+
+
+ """ + return ''' - {} stats - - + {label} stats + + - {} + {header}
-

{}

-
-
- {} -
-
-

Graph

-
+

{label}

- {} + {beforegraph} + {graph} + {aftergraph} - '''.format(escape(self.label), - self.JSLIB, - self.js(), - self.STYLE, - self.headHTML(), - escape(self.label), - self.cardlist(beforechart), - self.cardlist(afterchart)) + '''.format(label=escape(self.label), + jslib=self.JSLIB, + ourjs=self.js(), + style=self.STYLE, + header=self.headHTML(), + beforegraph=self.cardlist(beforechart), + graph=graph_card, + aftergraph=self.cardlist(afterchart)) def js(self): return 'var chartdata = {};\n{}'.format( -- 2.30.2