diff --git a/.cspell/custom-dictionary-workspace.txt b/.cspell/custom-dictionary-workspace.txt index 217577ac0..bb34a7c60 100644 --- a/.cspell/custom-dictionary-workspace.txt +++ b/.cspell/custom-dictionary-workspace.txt @@ -181,6 +181,7 @@ kwargs kwhb labelcolor labelnames +larr linebreak linestyle loadml diff --git a/apps/predbat/web.py b/apps/predbat/web.py index ab080a2d2..f5ec59a37 100644 --- a/apps/predbat/web.py +++ b/apps/predbat/web.py @@ -73,7 +73,7 @@ from predbat import THIS_VERSION from component_base import ComponentBase from config import APPS_SCHEMA -from web_metrics_dashboard import get_metrics_dashboard_css, get_metrics_dashboard_body, FALLBACK_HTML +from web_metrics_dashboard import get_metrics_dashboard_css, get_metrics_dashboard_body from predbat_metrics import metrics_handler, metrics_json_handler, metrics, PROMETHEUS_AVAILABLE ROOT_YAML_KEY = "pred_bat" @@ -4448,7 +4448,17 @@ async def html_metrics_dashboard(self, request): self.default_page = "./metrics_dashboard" if not PROMETHEUS_AVAILABLE: - return web.Response(text=FALLBACK_HTML, content_type="text/html") + text = self.get_header("Predbat Metrics", refresh=0) + text += "\n" + text += """
+

Metrics Dashboard Unavailable

+

prometheus_client is not installed.

+

Install it with: pip install prometheus_client

+

← Back to Dashboard

+
+""" + text += "\n" + return web.Response(text=text, content_type="text/html") import json as _json diff --git a/apps/predbat/web_metrics_dashboard.py b/apps/predbat/web_metrics_dashboard.py index 82abd61de..c1111ef9a 100644 --- a/apps/predbat/web_metrics_dashboard.py +++ b/apps/predbat/web_metrics_dashboard.py @@ -9,10 +9,6 @@ Dark/light mode is derived automatically from the ``body.dark-mode`` class used by the rest of the PredBat web UI - no separate theme toggle is needed. """ - -from predbat_metrics import PROMETHEUS_AVAILABLE, metrics - - def get_metrics_dashboard_css(): """Return scoped CSS for the metrics dashboard component.""" return """ -

Metrics Dashboard Unavailable

-

prometheus_client is not installed.

-

Install it with: pip install prometheus_client

""" - - -async def metrics_dashboard_handler(request): - """Serve the self-contained metrics dashboard at ``/metrics_dashboard``.""" - import json - from aiohttp import web - - if not PROMETHEUS_AVAILABLE: - return web.Response(text=FALLBACK_HTML, content_type="text/html") - - data_json = json.dumps(metrics().to_dict()) - html = ( - "" - "" - "PredBat Metrics" - + get_metrics_dashboard_css() - + "" - + get_metrics_dashboard_body(data_json) - + "" - ) - return web.Response(text=html, content_type="text/html")