Skip to content

Commit 0c6c96f

Browse files
mcmilkandrewc12
authored andcommitted
Colorize zpool iostat output
Use a bold header and colorize the space suffixes in iostat by order of magnitude like this: - K is green - M is yellow - G is red - T is lightblue - P is magenta - E is cyan - 0 space is colored gray Reviewed-by: WHR <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Ethan Coe-Renner <[email protected]> Signed-off-by: Tino Reichardt <[email protected]> Closes openzfs#14621 Closes openzfs#14459
1 parent 5f7ff40 commit 0c6c96f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

cmd/zpool/zpool_main.c

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4215,6 +4215,8 @@ print_iostat_header_impl(iostat_cbdata_t *cb, unsigned int force_column_width,
42154215
unsigned int namewidth;
42164216
const char *title;
42174217

4218+
color_start(ANSI_BOLD);
4219+
42184220
if (cb->cb_flags & IOS_ANYHISTO_M) {
42194221
title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)];
42204222
} else if (cb->cb_vdevs.cb_names_count) {
@@ -4248,6 +4250,8 @@ print_iostat_header_impl(iostat_cbdata_t *cb, unsigned int force_column_width,
42484250
if (cb->vcdl != NULL)
42494251
print_cmd_columns(cb->vcdl, 1);
42504252

4253+
color_end();
4254+
42514255
printf("\n");
42524256
}
42534257

@@ -4257,6 +4261,35 @@ print_iostat_header(iostat_cbdata_t *cb)
42574261
print_iostat_header_impl(cb, 0, NULL);
42584262
}
42594263

4264+
/*
4265+
* Prints a size string (i.e. 120M) with the suffix ("M") colored
4266+
* by order of magnitude. Uses column_size to add padding.
4267+
*/
4268+
static void
4269+
print_stat_color(char *statbuf, unsigned int column_size)
4270+
{
4271+
fputs(" ", stdout);
4272+
if (*statbuf == '0') {
4273+
color_start(ANSI_GRAY);
4274+
fputc('0', stdout);
4275+
column_size--;
4276+
} else {
4277+
for (; *statbuf; statbuf++) {
4278+
if (*statbuf == 'K') color_start(ANSI_GREEN);
4279+
else if (*statbuf == 'M') color_start(ANSI_YELLOW);
4280+
else if (*statbuf == 'G') color_start(ANSI_RED);
4281+
else if (*statbuf == 'T') color_start(ANSI_BOLD_BLUE);
4282+
else if (*statbuf == 'P') color_start(ANSI_MAGENTA);
4283+
else if (*statbuf == 'E') color_start(ANSI_CYAN);
4284+
fputc(*statbuf, stdout);
4285+
if (--column_size <= 0)
4286+
break;
4287+
}
4288+
}
4289+
color_end();
4290+
for (; column_size > 0; column_size--)
4291+
fputc(' ', stdout);
4292+
}
42604293

42614294
/*
42624295
* Display a single statistic.
@@ -4272,7 +4305,7 @@ print_one_stat(uint64_t value, enum zfs_nicenum_format format,
42724305
if (scripted)
42734306
printf("\t%s", buf);
42744307
else
4275-
printf(" %*s", column_size, buf);
4308+
print_stat_color(buf, column_size);
42764309
}
42774310

42784311
/*

man/man8/zpool.8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ to dump core on exit for the purposes of running
445445
.It Sy ZFS_COLOR
446446
Use ANSI color in
447447
.Nm zpool Cm status
448+
and
449+
.Nm zpool Cm iostat
448450
output.
449451
.It Sy ZPOOL_IMPORT_PATH
450452
The search path for devices or files to use with the pool.

0 commit comments

Comments
 (0)