-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Colorize zfs list output #14350
Colorize zfs list output #14350
Conversation
An idea came up while looking over the PR just before submitting: An alternative way of coloring the |
That would be my vote as well. Maybe judging by "80% bad, 95-96% really bad" we should do: 80% full: AVAIL yellow Otherwise just keep AVAIL the default color. |
You might find how I color zfs list interesting, or maybe not, it's very loud and information-dense, and not everyone's cup of tea. Or, more accurately, in its current iteration. I would particularly suggest coloring the segments of the dataset names consistently but distinctly, and the non-digit property values likewise, as extremely useful, as well as the every other line contrast to help avoid trouble distinguishing which row and column go together. You can play with it yourself, if you like, it's just something to pipe zfs list into. (The sizes as a gradient from 1-1024 and then the suffix as a separate coloring I also find useful, but some people really dislike Many Colors.) |
Thanks for the input! @rincebrain thanks for sending your implementation. I like many of the ideas in it, though, as you suggest, as a whole it may be too opinionated to be built directly in.
These are excellent suggestions, I will add these! @tonyhutter I agree, I think coloring by percentage makes sense in the |
277fe2d
to
9cb07df
Compare
After doing some testing and having a conversation, I’ve come to the conclusion that limiting the amount of color to specifically highlighting problems (or potential problems) is best. This is for two reasons:
For these reasons, I've scaled back this PR to just color the AVAIL column based on the percentage full. |
9cb07df
to
a56bb2b
Compare
0d064c0
to
337320c
Compare
- Bold header row - Color AVAIL column based on percentage of volume available - < 20%: Yellow - < 10%: Red Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov>
337320c
to
bc1ba01
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a few small nits. When you refresh this can you make sure to rebase it on the latest commits in the master branch. That should get us a cleaner CI test run.
zfs_list_avail_color(zfs_handle_t *zhp) | ||
{ | ||
int used = zfs_prop_get_int(zhp, ZFS_PROP_USED); | ||
int available = zfs_prop_get_int(zhp, ZFS_PROP_AVAILABLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int available = zfs_prop_get_int(zhp, ZFS_PROP_AVAILABLE); | |
uint64_t available = zfs_prop_get_int(zhp, ZFS_PROP_AVAILABLE); |
zfs_prop_get_int()
returns a uint64_t
which we want to make sure to use here for both used
and available
.
{ | ||
int used = zfs_prop_get_int(zhp, ZFS_PROP_USED); | ||
int available = zfs_prop_get_int(zhp, ZFS_PROP_AVAILABLE); | ||
int percentage = (int)((double)available / (available + used) * 100); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int percentage = (int)((double)available / (available + used) * 100); | |
int percentage = (int)((double)available / MAX(available + used, 1) * 100); |
Even though it shouldn't happen, we should protect against a division by zero error here.
When the output of Maybe some check with Edit: libzfs_util.c has a isatty() check - so everything is fine with this. Please ignore this comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add the small changes which @behlendorf requested and do a rebase?
The tests should be fine then - I think.
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes: openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes: openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes: openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Reviewed-by: WHR <msl0000023508@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes openzfs#14621 Closes openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Reviewed-by: WHR <msl0000023508@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes openzfs#14621 Closes openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Reviewed-by: WHR <msl0000023508@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes openzfs#14621 Closes openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Reviewed-by: WHR <msl0000023508@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes openzfs#14621 Closes openzfs#14350
Use a bold header row and colorize the AVAIL column based on the used space percentage of volume. We define these colors: - when > 80%, use yellow - when > 90%, use red Reviewed-by: WHR <msl0000023508@gmail.com> Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Ethan Coe-Renner <coerenner1@llnl.gov> Signed-off-by: Tino Reichardt <milky-zfs@mcmilk.de> Closes openzfs#14621 Closes openzfs#14350
Motivation and Context
Add colored output to
zfs list
to improve readability and allow users to quickly see datasets that are dangerously (performance-wise) full.Description
This uses the interface introduced in #9340 to add color to
zfs list
.If the
ZFS_COLOR
env variable is set, then outputzfs list
is colored as follows:AVAIL
column is colored based on the percentage still availableScreenshots
How Has This Been Tested?
Manually tested.
Types of changes
Checklist:
Signed-off-by
.