mirror of
				https://git.proxmox.com/git/mirror_zfs.git
				synced 2025-10-26 18:05:04 +03:00 
			
		
		
		
	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 <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 #14621 Closes #14459
This commit is contained in:
		
							parent
							
								
									374f86b5c9
								
							
						
					
					
						commit
						433b9a89c4
					
				| @ -4205,6 +4205,8 @@ print_iostat_header_impl(iostat_cbdata_t *cb, unsigned int force_column_width, | |||||||
| 	unsigned int namewidth; | 	unsigned int namewidth; | ||||||
| 	const char *title; | 	const char *title; | ||||||
| 
 | 
 | ||||||
|  | 	color_start(ANSI_BOLD); | ||||||
|  | 
 | ||||||
| 	if (cb->cb_flags & IOS_ANYHISTO_M) { | 	if (cb->cb_flags & IOS_ANYHISTO_M) { | ||||||
| 		title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)]; | 		title = histo_to_title[IOS_HISTO_IDX(cb->cb_flags)]; | ||||||
| 	} else if (cb->cb_vdev_names_count) { | 	} else if (cb->cb_vdev_names_count) { | ||||||
| @ -4238,6 +4240,8 @@ print_iostat_header_impl(iostat_cbdata_t *cb, unsigned int force_column_width, | |||||||
| 	if (cb->vcdl != NULL) | 	if (cb->vcdl != NULL) | ||||||
| 		print_cmd_columns(cb->vcdl, 1); | 		print_cmd_columns(cb->vcdl, 1); | ||||||
| 
 | 
 | ||||||
|  | 	color_end(); | ||||||
|  | 
 | ||||||
| 	printf("\n"); | 	printf("\n"); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| @ -4247,6 +4251,35 @@ print_iostat_header(iostat_cbdata_t *cb) | |||||||
| 	print_iostat_header_impl(cb, 0, NULL); | 	print_iostat_header_impl(cb, 0, NULL); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * Prints a size string (i.e. 120M) with the suffix ("M") colored | ||||||
|  |  * by order of magnitude. Uses column_size to add padding. | ||||||
|  |  */ | ||||||
|  | static void | ||||||
|  | print_stat_color(char *statbuf, unsigned int column_size) | ||||||
|  | { | ||||||
|  | 	fputs("  ", stdout); | ||||||
|  | 	if (*statbuf == '0') { | ||||||
|  | 		color_start(ANSI_GRAY); | ||||||
|  | 		fputc('0', stdout); | ||||||
|  | 		column_size--; | ||||||
|  | 	} else { | ||||||
|  | 		for (; *statbuf; statbuf++) { | ||||||
|  | 			if (*statbuf == 'K') color_start(ANSI_GREEN); | ||||||
|  | 			else if (*statbuf == 'M') color_start(ANSI_YELLOW); | ||||||
|  | 			else if (*statbuf == 'G') color_start(ANSI_RED); | ||||||
|  | 			else if (*statbuf == 'T') color_start(ANSI_BOLD_BLUE); | ||||||
|  | 			else if (*statbuf == 'P') color_start(ANSI_MAGENTA); | ||||||
|  | 			else if (*statbuf == 'E') color_start(ANSI_CYAN); | ||||||
|  | 			fputc(*statbuf, stdout); | ||||||
|  | 			if (--column_size <= 0) | ||||||
|  | 				break; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  | 	color_end(); | ||||||
|  | 	for (; column_size > 0; column_size--) | ||||||
|  | 		fputc(' ', stdout); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  * Display a single statistic. |  * Display a single statistic. | ||||||
| @ -4262,7 +4295,7 @@ print_one_stat(uint64_t value, enum zfs_nicenum_format format, | |||||||
| 	if (scripted) | 	if (scripted) | ||||||
| 		printf("\t%s", buf); | 		printf("\t%s", buf); | ||||||
| 	else | 	else | ||||||
| 		printf("  %*s", column_size, buf); | 		print_stat_color(buf, column_size); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| /*
 | /*
 | ||||||
|  | |||||||
| @ -433,6 +433,8 @@ to dump core on exit for the purposes of running | |||||||
| .It Sy ZFS_COLOR | .It Sy ZFS_COLOR | ||||||
| Use ANSI color in | Use ANSI color in | ||||||
| .Nm zpool status | .Nm zpool status | ||||||
|  | and | ||||||
|  | .Nm zpool iostat | ||||||
| output. | output. | ||||||
| .It Sy ZPOOL_IMPORT_PATH | .It Sy ZPOOL_IMPORT_PATH | ||||||
| The search path for devices or files to use with the pool. | The search path for devices or files to use with the pool. | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Tino Reichardt
						Tino Reichardt