Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CPU display to extension #105

Merged
merged 2 commits into from
Dec 3, 2021
Merged

Conversation

stevenstetzler
Copy link
Contributor

I added a brief extension to main.js to support displaying CPU utilization. I'm opening a PR in case there is interest in adding this functionality.

Happy to make changes to conform with style or extension usage.

This is how it looks in the browser:
image

@welcome
Copy link

welcome bot commented Jul 23, 2021

Thanks for submitting your first pull request! You are awesome! 🤗

If you haven't done so already, check out Jupyter's Code of Conduct. Also, please make sure you followed the pull request template, as this will help us review your contribution more quickly.
welcome
You can meet the other Jovyans by joining our Discourse forum. There is also a intro thread there where you can stop by and say Hi! 👋

Welcome to the Jupyter community! 🎉

@jtpio jtpio linked an issue Jul 23, 2021 that may be closed by this pull request
@jtpio
Copy link
Member

jtpio commented Jul 23, 2021

Thanks!

}
}

$('#jupyter-resource-usage-cpu').text(display);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think CPU usage still needs to be explicitly enabled for now with track_cpu_percent.

What happens if it is not enabled? Is the "CPU:" label displayed on the UI?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, yeah it wasn't handling that and the display would be messed up. I've committed a change to handle this.

@stevenstetzler
Copy link
Contributor Author

The new commit handles the track_cpu_percent option. I've also moved the CPU display handling to the same $.getJSON() call so only one call is made per update.

Running the notebook like jupyter notebook will display:
Screen Shot 2021-07-23 at 7 18 36 PM

Running with jupyter notebook --NotebookApp.ResourceUseDisplay.track_cpu_percent=True will display:
Screen Shot 2021-07-23 at 7 19 03 PM

And running

export CPU_LIMIT=100
jupyter notebook --NotebookApp.ResourceUseDisplay.track_cpu_percent=True

displays:
Screen Shot 2021-07-23 at 7 19 32 PM

Also FYI starting the notebook with e.g. jupyter notebook --NotebookApp.ResourceUseDisplay.track_cpu_percent=True --NotebookApp.ResourceUseDisplay.cpu_limit=2 will throw an error on start-up:

[W 19:24:28.289 NotebookApp] Error loading server extension jupyter_resource_usage
    Traceback (most recent call last):
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/notebook/notebookapp.py", line 2030, in init_server_extensions
        func(self)
      File "/Users/steven/Projects/jupyter-resource-usage/jupyter_resource_usage/__init__.py", line 47, in _load_jupyter_server_extension
        resuseconfig = ResourceUseDisplay(parent=server_app)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/config/configurable.py", line 104, in __init__
        self.config = config
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 604, in __set__
        self.set(obj, value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 593, in set
        obj._notify_trait(self.name, old_value, new_value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 1222, in _notify_trait
        type='change',
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 1227, in notify_change
        return self._notify_observers(change)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 1264, in _notify_observers
        c(event)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 888, in compatible_observer
        return func(self, change)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/config/configurable.py", line 208, in _config_changed
        self._load_config(change.new, traits=traits, section_names=section_names)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/config/configurable.py", line 175, in _load_config
        setattr(self, name, deepcopy(config_value))
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 604, in __set__
        self.set(obj, value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 578, in set
        new_value = self._validate(obj, value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 610, in _validate
        value = self.validate(obj, value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 1981, in validate
        self.error(obj, value)
      File "/Users/steven/Projects/jupyter-resource-usage/env/lib/python3.7/site-packages/traitlets/traitlets.py", line 690, in error
        raise TraitError(e)
    traitlets.traitlets.TraitError: The 'cpu_limit' trait of a ResourceUseDisplay instance expected a float or a callable, not the str '2'.

The cpu_limit traitlet won't handle strings passed from the command line (hence why I had to set the CPU_LIMIT environment variable above). Perhaps just handling string to float parsing here would work?

@stevenstetzler
Copy link
Contributor Author

Also I guess the displayed limit is kind of inconsistent or confusing. The value in the parenthesis is the max cpus reported by the metrics API, which is different from what is configured with cpu_limit. I did that when I made this because I value knowing the number of available cores/threads on the machines I was running notebooks on.

Copy link
Member

@jtpio jtpio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jtpio
Copy link
Member

jtpio commented Dec 3, 2021

The cpu_limit traitlet won't handle strings passed from the command line (hence why I had to set the CPU_LIMIT environment variable above). Perhaps just handling string to float parsing here would work?

Yes this sounds related to #86

@jtpio jtpio merged commit f125e71 into jupyter-server:master Dec 3, 2021
@welcome
Copy link

welcome bot commented Dec 3, 2021

Congrats on your first merged pull request in this project! 🎉
congrats
Thank you for contributing, we are very proud of you! ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I want to display the cpu usage on the screen.
2 participants