Skip to content

'zpool iostat -v' formatting is hard-coded to 80 columns (patch included) #622

@craig-sanders

Description

@craig-sanders

The hard-coded 80 column output makes the output difficult to read when you have long device names in your pools (e.g. /dev/disk/by-id device names).

e.g.

                                           capacity     operations    bandwidth
pool                                    alloc   free   read  write   read  write
--------------------------------------  -----  -----  -----  -----  -----  -----
backup                                  2.44T  1.19T     11      1  34.4K  44.8K
  raidz1                                2.44T  1.19T     11      1  34.4K  44.8K
    scsi-SATA_ST31000528AS_6VP3FWAG         -      -      2      0  16.4K  16.9K
    scsi-SATA_ST31000528AS_9VP4RPXK         -      -      2      0  14.8K  16.8K
    scsi-SATA_ST31000528AS_9VP509T5         -      -      2      0  16.2K  16.9K
    scsi-SATA_ST31000528AS_9VP4P4LN         -      -      2      0  14.7K  16.8K
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part5     4K  1.98G      0      0      4      0
--------------------------------------  -----  -----  -----  -----  -----  -----
export                                  2.40T  1.22T      8     15  44.5K  91.7K
  raidz1                                2.40T  1.22T      8     14  44.5K  73.4K
    scsi-SATA_WDC_WD10EACS-00_WD-WCASJ2114122      -      -      2      4  18.1K  46.5K
    scsi-SATA_WDC_WD10EACS-00_WD-WCASJ2195141      -      -      1      4  15.0K  43.1K
    scsi-SATA_WDC_WD10EARS-00_WD-WMAV50817803      -      -      2      4  17.9K  46.5K
    scsi-SATA_ST31000528AS_9VP18CCV         -      -      1      4  14.6K  43.8K
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part6    36K  1.98G      0      0      4  8.54K
  scsi-SATA_Patriot_WildfirPT1131A00006353-part5    64K  3.97G      0      0      4  9.76K
cache                                       -      -      -      -      -      -
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part7  4.04G  14.2G      2      0  24.2K  21.5K
  scsi-SATA_Patriot_WildfirPT1131A00006353-part6  4.22G  14.6G      2      0  21.8K  22.5K
--------------------------------------  -----  -----  -----  -----  -----  -----

here's a patch for zpool_main.c which:

sets the default line length to 80 columns,
sets $COLUMNS from the environment if it's there,
sets line length to 999 if stdout is not a tty, for redirected output.

i'd attach it as a patch file, but github doesn't seem to have any way to attach
files to an issue.

--- zpool_main.c.orig   2012-03-27 08:41:19.884741258 +1100
+++ zpool_main.c        2012-03-27 10:11:11.528655924 +1100
@@ -84,6 +84,8 @@
 static int zpool_do_get(int, char **);
 static int zpool_do_set(int, char **);

+static int tty_columns = 80;
+
 /*
  * These libumem hooks provide a reasonable set of defaults for the allocator's
  * debugging facilities.
@@ -2191,13 +2193,14 @@
        }

        /*
-        * The width must fall into the range [10,38].  The upper limit is the
-        * maximum we can have and still fit in 80 columns.
+        * The width must be at least 10, but <= tty_columns - 42
+        * so that we can still fit in one line.
         */
+
        if (cb->cb_namewidth < 10)
                cb->cb_namewidth = 10;
-       if (cb->cb_namewidth > 38)
-               cb->cb_namewidth = 38;
+       if (cb->cb_namewidth > tty_columns - 42)
+               cb->cb_namewidth = tty_columns -42;

        return (0);
 }
@@ -4713,12 +4716,22 @@
        int ret;
        int i = 0;
        char *cmdname;
+       char* env_columns;

        (void) setlocale(LC_ALL, "");
        (void) textdomain(TEXT_DOMAIN);

        opterr = 0;

+       env_columns = getenv("COLUMNS");
+
+       if (env_columns != NULL) {
+               tty_columns = atoi(env_columns);
+       } else {
+         if (!isatty(fileno(stdout)))
+               tty_columns = 999;
+       }
+
        /*
         * Make sure the user has specified some command.
         */

That makes the output columns line up properly in a wide terminal or when redirecting output to a file, like this:

(this looks better - perfect - on a terminal. github text input fields aren't wide enough)

                                                          capacity     operations    bandwidth
pool                                                   alloc   free   read  write   read  write
-----------------------------------------------------  -----  -----  -----  -----  -----  -----
backup                                                 2.44T  1.19T     11      1  34.4K  44.8K
  raidz1                                               2.44T  1.19T     11      1  34.4K  44.7K
    scsi-SATA_ST31000528AS_6VP3FWAG                        -      -      2      0  16.4K  16.9K
    scsi-SATA_ST31000528AS_9VP4RPXK                        -      -      2      0  14.8K  16.8K
    scsi-SATA_ST31000528AS_9VP509T5                        -      -      2      0  16.2K  16.9K
    scsi-SATA_ST31000528AS_9VP4P4LN                        -      -      2      0  14.7K  16.8K
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part5     4K  1.98G      0      0      4      0
-----------------------------------------------------  -----  -----  -----  -----  -----  -----
export                                                 2.40T  1.22T      8     15  44.5K  91.7K
  raidz1                                               2.40T  1.22T      8     14  44.5K  73.4K
    scsi-SATA_WDC_WD10EACS-00_WD-WCASJ2114122              -      -      2      4  18.1K  46.5K
    scsi-SATA_WDC_WD10EACS-00_WD-WCASJ2195141              -      -      1      4  15.0K  43.1K
    scsi-SATA_WDC_WD10EARS-00_WD-WMAV50817803              -      -      2      4  17.9K  46.5K
    scsi-SATA_ST31000528AS_9VP18CCV                        -      -      1      4  14.6K  43.7K
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part6    12K  1.98G      0      0      4  8.54K
  scsi-SATA_Patriot_WildfirPT1131A00006353-part5         88K  3.97G      0      0      4  9.76K
cache                                                      -      -      -      -      -      -
  scsi-SATA_Patriot_Torqx_278BF0715010800025492-part7  4.06G  14.2G      2      0  24.1K  21.6K
  scsi-SATA_Patriot_WildfirPT1131A00006353-part6       4.24G  14.5G      2      0  21.8K  22.6K
-----------------------------------------------------  -----  -----  -----  -----  -----  -----

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions