Skip to content

Commit

Permalink
Allow users to opt out of prometheus metrics (#124)
Browse files Browse the repository at this point in the history
* Allow users to opt out of prometheus metrics

Poor mans fix for #123

* Update README.md

Co-authored-by: Kevin Bates <kbates4@gmail.com>

* Lint README.md

Co-authored-by: Kevin Bates <kbates4@gmail.com>
Co-authored-by: Jeremy Tuloup <jeremy.tuloup@gmail.com>
  • Loading branch information
3 people authored Aug 23, 2022
1 parent a5e6978 commit d6edf6a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions jupyter_resource_usage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
13 changes: 9 additions & 4 deletions jupyter_resource_usage/server_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)

0 comments on commit d6edf6a

Please sign in to comment.