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

[Gitpod CLI] New command gp top - Display workspace used/available resources #10570

Merged
merged 1 commit into from
Jun 13, 2022

Conversation

andreafalzetti
Copy link
Contributor

@andreafalzetti andreafalzetti commented Jun 10, 2022

Description

Introducing a new command for gitpod-cli: $ gp top

Command line interface for Gitpod

Usage:
  gp [command]

Available Commands:
...
  top                 Display workspace resource (CPU/Memory usage)

This command similarly to gp ports list and gp tasks list use colors. It's a best practice for CLI tools to be accessible and allow disabling colors in certain circumstances.

I've followd this approach, which seems to be very common and community sanctioned:

Screenshot 2022-06-10 at 15 02 07

I've enclosed this logic in a utility so that, if we like it, we can re-use it also for the other commands.

Without disabling colors, running watch gp top it would display the following:

Screenshot 2022-06-10 at 15 05 14

By detecting if the CLI is being used without any wrapper or being piped into a command, it disables the colors and it looks good:

Screenshot 2022-06-10 at 15 04 41

Related Issue(s)

Fixes #9521

How to test

  1. Start this workspace in prev env: https://afalz-9521-gp-top.preview.gitpod-dev.com/#https://github.com/andreafalzetti/gitpod-experiments-c
  2. Run gp top, observe the cpu/memory usage
  3. Try disabling colors with the following options:
    • gp top --no-color
    • NO_COLOR=1 gp top
    • GP_NO_COLOR=1 gp top
    • TERM=dumb gp top

Optionally, to test the colors based on usage:
4. To stress the CPU, run: yes > /dev/null & multiple times
5. Run gp top again and obsere the CPU usage
6. To get the CPU back to a lower value, run: killall yes
7. To stress the Memory, run cat /dev/zero | head -c 5G | tail once or twice

In prev env, it easily hangs before you can actually test gp top for this, I've also attached some screenshots taken from my dev branch in gitpod.io.

Release Notes

Added a new command to gitpod-cli: "gp top" which displays workspace resources (CPU/Memory usage)

Screenshot 2022-06-09 at 21 59 49

Screenshot 2022-06-09 at 21 59 20

Screenshot 2022-06-09 at 21 59 33

Screenshot 2022-06-09 at 22 31 58

Screenshot 2022-06-09 at 22 32 49

Documentation

https://github.com/gitpod-io/website/pull/2207

@andreafalzetti andreafalzetti marked this pull request as ready for review June 10, 2022 03:27
@andreafalzetti andreafalzetti requested a review from a team June 10, 2022 03:27
@andreafalzetti andreafalzetti changed the title feat(gitpod-cli): add top cmd [Gitpod CLI] New command gp top - Display workspace used/available resources Jun 10, 2022
Copy link
Member

@akosyakov akosyakov left a comment

Choose a reason for hiding this comment

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

/lgtm

/hold
if you want to make any small adjustments, otherwise it looks good

@andreafalzetti andreafalzetti marked this pull request as draft June 10, 2022 17:06
@andreafalzetti andreafalzetti force-pushed the afalz/9521-gp-top branch 2 times, most recently from 4f177ff to c48cf02 Compare June 10, 2022 20:01
@andreafalzetti andreafalzetti marked this pull request as ready for review June 10, 2022 20:12
Copy link
Member

@filiptronicek filiptronicek left a comment

Choose a reason for hiding this comment

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

Thanks a lot @andreafalzetti 🚀!

I just have two questions:

  1. Would it be a common use case for users to run this with watch? Maybe we could add a way to run continuously to behave more like top?
  2. Is there a way to consume the info via other means? Can I use these values in my app somehow? I would like to for instance output JSON so it can be consumed by tools like https://github.com/akosyakov/gitpod-monitor (still the best VS Code extension there is).

@andreafalzetti
Copy link
Contributor Author

andreafalzetti commented Jun 13, 2022

Thanks a lot @andreafalzetti 🚀!

I just have two questions:

1. Would it be a common use case for users to run this with `watch`? Maybe we could add a way to run continuously to behave more like `top`?

2. Is there a way to consume the info via other means? Can I use these values in my app somehow? I would like to for instance output JSON so it can be consumed by tools like https://github.com/akosyakov/gitpod-monitor (still the best VS Code extension there is).

These are good points, I've also mentioned them in this PR - see: 1 and 2 :)

Copy link
Member

@filiptronicek filiptronicek left a comment

Choose a reason for hiding this comment

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

These are good points, I've also mentioned them in this PR - see: #10570 (comment) and #10570 (comment) :)

Thanks for the pointers, @andreafalzetti, I have tried the command and it LGTM ✅.

@andreafalzetti
Copy link
Contributor Author

andreafalzetti commented Jun 13, 2022

Thanks @akosyakov and @filiptronicek

There was a typo in the OSS header (2020 -> 2022). Fixed and pushed. Waiting for the build to finish and it will be merged 🙏

/unhold

@roboquat roboquat merged commit f5eaee9 into main Jun 13, 2022
@roboquat roboquat deleted the afalz/9521-gp-top branch June 13, 2022 17:15
@roboquat roboquat added deployed: IDE IDE change is running in production deployed Change is completely running in production labels Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: gp cli deployed: IDE IDE change is running in production deployed Change is completely running in production release-note size/L team: IDE
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Expose perf details for the current workspace
4 participants