Skip to content

Commit

Permalink
Merge pull request #74 from jtpio/rename
Browse files Browse the repository at this point in the history
Rename to jupyter-resource-usage
  • Loading branch information
yuvipanda authored Dec 3, 2020
2 parents ff7531f + f492d09 commit 67a2df9
Show file tree
Hide file tree
Showing 21 changed files with 99 additions and 91 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
- name: Lint with flake8
run: python -m flake8 nbresuse
run: python -m flake8 jupyter_resource_usage
- name: Test with pytest
run: |
python -m pytest -vvv nbresuse --cov=nbresuse --junitxml=python_junit.xml --cov-report=xml --cov-branch
python -m pytest -vvv jupyter_resource_usage --cov=jupyter_resource_usage --junitxml=python_junit.xml --cov-report=xml --cov-branch
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ install:
- pip install --editable .

script:
- python -m pytest -vvv nbresuse
- python -m pytest -vvv jupyter-resource-usage


jobs:
Expand Down
32 changes: 16 additions & 16 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

## 0.4.0

- Soft-deprecate `/metrics` endpoint: [#68](https://github.com/yuvipanda/jupyter-resource-usage/pull/68)
- `nbresuse` now exposes a new endpoint: `/api/metrics/v1`: [#68](https://github.com/yuvipanda/jupyter-resource-usage/pull/68)
- Soft-deprecate `/metrics` endpoint: [#68](https://github.com/jupyter-server/jupyter-resource-usage/pull/68)
- `nbresuse` now exposes a new endpoint: `/api/metrics/v1`: [#68](https://github.com/jupyter-server/jupyter-resource-usage/pull/68)

### Migrating to 0.4.0

Expand All @@ -30,51 +30,51 @@ jupyter lab --ResourceUseDisplay.disable_legacy_endpoint=False

## 0.3.6

- Fix handling of cpu percent in the API endpoint [#56](https://github.com/yuvipanda/jupyter-resource-usage/pull/56)
- Added Binder [#53](https://github.com/yuvipanda/jupyter-resource-usage/pull/53) & RELEASE.md [#54](https://github.com/yuvipanda/jupyter-resource-usage/pull/54)
- Fix handling of cpu percent in the API endpoint [#56](https://github.com/jupyter-server/jupyter-resource-usage/pull/56)
- Added Binder [#53](https://github.com/jupyter-server/jupyter-resource-usage/pull/53) & RELEASE.md [#54](https://github.com/jupyter-server/jupyter-resource-usage/pull/54)

## 0.3.5

- Adding support for jupyterlab statusbar-extension [#45](https://github.com/yuvipanda/jupyter-resource-usage/pull/45) [#36](https://github.com/yuvipanda/jupyter-resource-usage/issues/36)
- Adding support for jupyterlab statusbar-extension [#45](https://github.com/jupyter-server/jupyter-resource-usage/pull/45) [#36](https://github.com/jupyter-server/jupyter-resource-usage/issues/36)

**Note**: this release restores the `/metrics` endpoint returning a JSON response, that was removed in `0.3.4`.

## 0.3.4

- Autoformatting and documentation [#33](https://github.com/yuvipanda/jupyter-resource-usage/pull/33)
- Add section about CPU usage to the README [#30](https://github.com/yuvipanda/jupyter-resource-usage/pull/30)
- Make psutil optional dependency of NBResuse [#25](https://github.com/yuvipanda/jupyter-resource-usage/pull/25)
- Report the memory usage metrics as prometheus metrics [#22](https://github.com/yuvipanda/jupyter-resource-usage/pull/22)
- Autoformatting and documentation [#33](https://github.com/jupyter-server/jupyter-resource-usage/pull/33)
- Add section about CPU usage to the README [#30](https://github.com/jupyter-server/jupyter-resource-usage/pull/30)
- Make psutil optional dependency of NBResuse [#25](https://github.com/jupyter-server/jupyter-resource-usage/pull/25)
- Report the memory usage metrics as prometheus metrics [#22](https://github.com/jupyter-server/jupyter-resource-usage/pull/22)

**Note**: this release removed the `/metrics` endpoint that was returning a JSON response. As a result, JupyterLab does not display the memory usage indicator in the status bar with `nbresuse==0.3.4`.

## 0.3.3

- Made memory limit possibly dynamic via passing a callable in the config. [#23](https://github.com/yuvipanda/jupyter-resource-usage/pull/23)
- Track CPU usage [#21](https://github.com/yuvipanda/jupyter-resource-usage/pull/21)
- Made memory limit possibly dynamic via passing a callable in the config. [#23](https://github.com/jupyter-server/jupyter-resource-usage/pull/23)
- Track CPU usage [#21](https://github.com/jupyter-server/jupyter-resource-usage/pull/21)

## 0.3.2

- Require authentication for /metrics API Handler [#18](https://github.com/yuvipanda/jupyter-resource-usage/pull/18)
- Require authentication for /metrics API Handler [#18](https://github.com/jupyter-server/jupyter-resource-usage/pull/18)

## 0.3.1

- Don't poll in background, since user does not see it [#15](https://github.com/yuvipanda/jupyter-resource-usage/pull/15)
- Poll instantly once page is foregrounded [#15](https://github.com/yuvipanda/jupyter-resource-usage/pull/15)
- Don't poll in background, since user does not see it [#15](https://github.com/jupyter-server/jupyter-resource-usage/pull/15)
- Poll instantly once page is foregrounded [#15](https://github.com/jupyter-server/jupyter-resource-usage/pull/15)

This should reduce the number of /metrics requests massively, with minimal interruption to user experience.

## 0.3.0

- Automatically install & enable extensions [#9](https://github.com/yuvipanda/jupyter-resource-usage/pull/9)
- Automatically install & enable extensions [#9](https://github.com/jupyter-server/jupyter-resource-usage/pull/9)
- Put nbextension / serverextension enables in different places
- Put nbresuse js files in appropriate path

## 0.2.0

- Change 'Mem' prefix in display to less cryptic 'Memory'
- Fix primary screenshot to show memory limit too
- Distribute static files via package_data [#1](https://github.com/yuvipanda/jupyter-resource-usage/pull/1)
- Distribute static files via package_data [#1](https://github.com/jupyter-server/jupyter-resource-usage/pull/1)
- Add screenshot for memory usage warning
- Configurable memory usage warnings
- More configurability via traitlets
Expand Down
18 changes: 9 additions & 9 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Contributing

Contributions to NBResuse are highly welcome! As a [Jupyter](https://jupyter.org) project,
Contributions to jupyter-resource-usage are highly welcome! As a [Jupyter](https://jupyter.org) project,
you can follow the [Jupyter contributor guide](https://jupyter.readthedocs.io/en/latest/contributor/content-contributor.html).

Make sure to also follow [Project Jupyter's Code of Conduct](https://github.com/jupyter/governance/blob/master/conduct/code_of_conduct.md)
Expand All @@ -13,13 +13,13 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
1. Clone the git repository:

```bash
git clone https://github.com/yuvipanda/nbresuse
git clone https://github.com/jupyter-server/jupyter-resource-usage
```

2. Create an environment that will hold our dependencies.

```bash
cd nbresuse
cd jupyter-resource-usage
pipenv --python 3.6
```

Expand All @@ -29,7 +29,7 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
pipenv shell
```

4. Do a dev install of nbresuse and its dependencies
4. Do a dev install of jupyter-resource-usage and its dependencies

```bash
pip install --editable .[dev]
Expand All @@ -38,9 +38,9 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
5. Install and enable the nbextension for use with Jupyter Classic Notebook.

```bash
jupyter nbextension install --py nbresuse --symlink --sys-prefix
jupyter serverextension enable --py nbresuse --sys-prefix
jupyter nbextension enable --py nbresuse --sys-prefix
jupyter nbextension install --py jupyter-resource-usage --symlink --sys-prefix
jupyter serverextension enable --py jupyter-resource-usage --sys-prefix
jupyter nbextension enable --py jupyter-resource-usage --sys-prefix
```

6. Start a Jupyter Notebook instance, open a new notebook and check out the memory usage
Expand All @@ -57,7 +57,7 @@ We recommend using [pipenv](https://docs.pipenv.org/) to make development easier
MEM_LIMIT=$(expr 128 \* 1024 \* 1024) jupyter notebook
```

8. NBResuse has adopted automatic code formatting so you shouldn't
8. jupyter-resource-usage has adopted automatic code formatting so you shouldn't
need to worry too much about your code style.
As long as your code is valid,
the pre-commit hook should take care of how it should look. Here is how to set up pre-commit hooks for automatic code formatting, etc.
Expand Down Expand Up @@ -86,7 +86,7 @@ yourself after that.
or that trigger any bugs that you have fixed to catch regressions. `pytest` is used to run the test suite. You can run the tests with:
```bash
python -m pytest -vvv nbresuse
python -m pytest -vvv jupyter-resource-usage
```
in the repo directory.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
**[Resources Displayed](#resources-displayed)** |
**[Contributing](#contributing)**

# NBResuse
# jupyter-resource-usage

![Github Actions Status](https://github.com/yuvipanda/nbresuse/workflows/Tests/badge.svg)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/yuvipanda/nbresuse/stable)
[![PyPI](https://img.shields.io/pypi/v/nbresuse)](https://pypi.python.org/pypi/nbresuse)
[![PyPI](https://img.shields.io/pypi/l/nbresuse)](https://pypi.python.org/pypi/nbresuse)
[![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/yuvipanda/nbresuse/issues)
![Github Actions Status](https://github.com/jupyter-server/jupyter-resource-usage/workflows/Tests/badge.svg)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/jupyter-server/jupyter-resource-usage/stable)
[![PyPI](https://img.shields.io/pypi/v/jupyter-resource-usage)](https://pypi.python.org/pypi/jupyter-resource-usage)
[![PyPI](https://img.shields.io/pypi/l/jupyter-resource-usage)](https://pypi.python.org/pypi/jupyter-resource-usage)
[![GitHub](https://img.shields.io/badge/issue_tracking-github-blue?logo=github)](https://github.com/jupyter-server/jupyter-resource-usage/issues)

![Screenshot with memory limit](screenshot.png)

NB Resource Usage (NBResuse) is a small extension for Jupyter Notebooks that
Jupyter Resource Usage is an extension for Jupyter Notebooks and JupyterLab that
displays an indication of how much resources your current notebook server and
its children (kernels, terminals, etc) are using. This is displayed in the
main toolbar in the notebook itself, refreshing every 5s.
Expand All @@ -23,22 +23,22 @@ main toolbar in the notebook itself, refreshing every 5s.
You can currently install this package from PyPI.

```bash
pip install nbresuse
pip install jupyter-resource-usage
```

**If your notebook version is < 5.3**, you need to enable the extension manually.

```
jupyter serverextension enable --py nbresuse --sys-prefix
jupyter nbextension install --py nbresuse --sys-prefix
jupyter nbextension enable --py nbresuse --sys-prefix
jupyter serverextension enable --py jupyter-resource-usage --sys-prefix
jupyter nbextension install --py jupyter-resource-usage --sys-prefix
jupyter nbextension enable --py jupyter-resource-usage --sys-prefix
```

## Configuration

### Memory Limit

`nbresuse` can display a memory limit (but not enforce it). You can set this
`jupyter-resource-usage` can display a memory limit (but not enforce it). You can set this
in several ways:

1. `MEM_LIMIT` environment variable. This is set by [JupyterHub](https://github.com/jupyterhub/jupyterhub/)
Expand All @@ -61,7 +61,7 @@ can set the parameter `--ResourceUseDisplay.mem_warning_threshold=0.1`.

### CPU Usage

`nbresuse` can also track CPU usage and report a `cpu_percent` value as part of the `/metrics` response.
`jupyter-resource-usage` can also track CPU usage and report a `cpu_percent` value as part of the `/metrics` response.

You can set the `cpu_limit` in several ways:

Expand Down
10 changes: 5 additions & 5 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Making a new release of nbresuse
# Making a new release of jupyter-resource-usage

## Getting a clean environment

Creating a new environment can help avoid pushing local changes and any extra tag.

```bash
conda create -n nbresuse-release -c conda-forge twine keyring
conda activate nbresuse-release
conda create -n jupyter-resource-usage-release -c conda-forge twine keyring
conda activate jupyter-resource-usage-release
```

Alternatively, the local repository can be cleaned with:
Expand All @@ -23,7 +23,7 @@ Make sure the `dist/` folder is empty.
2. `python setup.py sdist bdist_wheel`
3. Double check the size of the bundles in the `dist/` folder
4. Run the tests
- `pip install "dist/nbresuse-X.Y.Z-py3-none-any.whl[dev]"`
- `pip install "dist/jupyter-resource-usage-X.Y.Z-py3-none-any.whl[dev]"`
- `python -m pytest`
5. `export TWINE_USERNAME=mypypi_username`
6. `twine upload dist/*`
Expand All @@ -34,7 +34,7 @@ The easiest is to wait for the bot to open the PR automatically.

To do the release manually:

1. Open a new PR on https://github.com/conda-forge/nbresuse-feedstock to update the `version` and the `sha256` hash
1. Open a new PR on https://github.com/conda-forge/jupyter-resource-usage-feedstock to update the `version` and the `sha256` hash
2. Wait for the tests
3. Merge the PR

Expand Down
4 changes: 2 additions & 2 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
name: nbresuse
name: jupyter-resource-usage
channels:
- conda-forge
dependencies:
- python=3
- jupyterlab=2
- nbresuse=0.3.6
- jupyter_resource_usage=0.3.6
- nodejs
17 changes: 8 additions & 9 deletions nbresuse/__init__.py → jupyter_resource_usage/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
from jupyter_resource_usage.api import ApiHandler
from jupyter_resource_usage.config import ResourceUseDisplay
from jupyter_resource_usage.metrics import PSUtilMetricsLoader
from jupyter_resource_usage.prometheus import PrometheusHandler
from notebook.utils import url_path_join
from tornado import ioloop

from nbresuse.api import ApiHandler
from nbresuse.config import ResourceUseDisplay
from nbresuse.metrics import PSUtilMetricsLoader
from nbresuse.prometheus import PrometheusHandler


def _jupyter_server_extension_paths():
"""
Set up the server extension for collecting metrics
"""
return [{"module": "nbresuse"}]
return [{"module": "jupyter_resource_usage"}]


def _jupyter_nbextension_paths():
Expand All @@ -21,9 +20,9 @@ def _jupyter_nbextension_paths():
return [
{
"section": "notebook",
"dest": "nbresuse",
"dest": "jupyter_resource_usage",
"src": "static",
"require": "nbresuse/main",
"require": "jupyter_resource_usage/main",
}
]

Expand All @@ -33,7 +32,7 @@ def load_jupyter_server_extension(nbapp):
Called during notebook start
"""
resuseconfig = ResourceUseDisplay(parent=nbapp)
nbapp.web_app.settings["nbresuse_display_config"] = resuseconfig
nbapp.web_app.settings["jupyter_resource_usage_display_config"] = resuseconfig
base_url = nbapp.web_app.settings["base_url"]

if not resuseconfig.disable_legacy_endpoint:
Expand Down
2 changes: 1 addition & 1 deletion nbresuse/api.py → jupyter_resource_usage/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async def get(self):
"""
Calculate and return current resource usage metrics
"""
config = self.settings["nbresuse_display_config"]
config = self.settings["jupyter_resource_usage_display_config"]

cur_process = psutil.Process()
all_processes = [cur_process] + cur_process.children(recursive=True)
Expand Down
4 changes: 2 additions & 2 deletions nbresuse/config.py → jupyter_resource_usage/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def validate(self, obj, value):

class ResourceUseDisplay(Configurable):
"""
Holds server-side configuration for nbresuse
Holds server-side configuration for jupyter-resource-usage
"""

disable_legacy_endpoint = Bool(
True,
help="""
Disable legacy /metrics endpoint
This prevents nbresuse from shadowing the prometheus /metrics endpoint.
This prevents jupyter-resource-usage from shadowing the prometheus /metrics endpoint.
""",
config=True,
)
Expand Down
5 changes: 5 additions & 0 deletions jupyter_resource_usage/etc/nbextension.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"load_extensions": {
"jupyter_resource_usage/main": true
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"NotebookApp": {
"nbserver_extensions": {
"nbresuse": true
"jupyter_resource_usage": true
}
}
}
2 changes: 1 addition & 1 deletion nbresuse/metrics.py → jupyter_resource_usage/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class PSUtilMetricsLoader:
def __init__(self, nbapp: NotebookApp):
self.config = nbapp.web_app.settings["nbresuse_display_config"]
self.config = nbapp.web_app.settings["jupyter_resource_usage_display_config"]
self.nbapp = nbapp

def get_process_metric_value(self, process, name, kwargs, attribute=None):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from typing import Optional

from jupyter_resource_usage.metrics import PSUtilMetricsLoader
from notebook.notebookapp import NotebookApp
from prometheus_client import Gauge

from nbresuse.metrics import PSUtilMetricsLoader

try:
# Traitlets >= 4.3.3
from traitlets import Callable
Expand Down
Loading

0 comments on commit 67a2df9

Please sign in to comment.