From d6edf6a8a94b5740670368c6ad91299049e5a34f Mon Sep 17 00:00:00 2001 From: David Leen Date: Tue, 23 Aug 2022 06:44:38 -0700 Subject: [PATCH] Allow users to opt out of prometheus metrics (#124) * Allow users to opt out of prometheus metrics Poor mans fix for #123 * Update README.md Co-authored-by: Kevin Bates * Lint README.md Co-authored-by: Kevin Bates Co-authored-by: Jeremy Tuloup --- README.md | 9 +++++++++ jupyter_resource_usage/config.py | 7 +++++++ jupyter_resource_usage/server_extension.py | 13 +++++++++---- 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 3290244..3af6d33 100644 --- a/README.md +++ b/README.md @@ -91,6 +91,15 @@ As a command line argument: jupyter notebook --ResourceUseDisplay.track_cpu_percent=True ``` +### Disable Prometheus Metrics + +There is a [known bug](https://github.com/jupyter-server/jupyter-resource-usage/issues/123) with Prometheus metrics which +causes "lag"/pauses in the UI. To workaround this you can disable Prometheus metric reporting using: + +``` +--ResourceUseDisplay.enable_prometheus_metrics=False +``` + ## Resources Displayed Currently the server extension only reports memory usage (just RSS) and CPU usage. Other metrics will be diff --git a/jupyter_resource_usage/config.py b/jupyter_resource_usage/config.py index 0c58ce9..e8622bf 100644 --- a/jupyter_resource_usage/config.py +++ b/jupyter_resource_usage/config.py @@ -122,3 +122,10 @@ def _mem_limit_default(self): @default("cpu_limit") def _cpu_limit_default(self): return float(os.environ.get("CPU_LIMIT", 0)) + + enable_prometheus_metrics = Bool( + default_value=True, + help=""" + Set to False in order to disable reporting of Prometheus style metrics. + """, + ).tag(config=True) diff --git a/jupyter_resource_usage/server_extension.py b/jupyter_resource_usage/server_extension.py index c5f8cd4..65b3045 100644 --- a/jupyter_resource_usage/server_extension.py +++ b/jupyter_resource_usage/server_extension.py @@ -19,7 +19,12 @@ def load_jupyter_server_extension(server_app): ".*", [(url_path_join(base_url, "/api/metrics/v1"), ApiHandler)] ) - callback = ioloop.PeriodicCallback( - PrometheusHandler(PSUtilMetricsLoader(server_app)), 1000 - ) - callback.start() + if resuseconfig.enable_prometheus_metrics: + callback = ioloop.PeriodicCallback( + PrometheusHandler(PSUtilMetricsLoader(server_app)), 1000 + ) + callback.start() + else: + server_app.log.info( + "Prometheus metrics reporting disabled in jupyter_resource_usage." + )