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

Machine parsable "zpool status" #2626

Closed
FransUrbo opened this issue Aug 26, 2014 · 16 comments
Closed

Machine parsable "zpool status" #2626

FransUrbo opened this issue Aug 26, 2014 · 16 comments
Labels
Type: Feature Feature request or new feature

Comments

@FransUrbo
Copy link
Contributor

I could really have used this in one of my GetDiskInfo scripts (and grub could need this as well).

It should not be to difficult to do (I'm offering :), but it should really be synchronized with OpenZFS/Illumos (THAT I do not volunteer to do though :) so they're on board with this.

For example (out of the top of my head without much thought :):

Original output:

  pool: test
 state: DEGRADED
status: One or more devices could not be used because the label is missing or
        invalid.  Sufficient replicas exist for the pool to continue
        functioning in a degraded state.
action: Replace the device using 'zpool replace'.
   see: http://zfsonlinux.org/msg/ZFS-8000-4J
  scan: resilvered 25.8M in 0h0m with 0 errors on Fri Aug 22 12:02:46 2014
config:

        NAME                                         STATE     READ WRITE CKSUM
        test                                         DEGRADED     0     0     0
          mirror-0                                   DEGRADED     0     0     0
            spare-0                                  DEGRADED     1     0     0
              ata-VBOX_HARDDISK_VBb80f1f56-538e9acf  ONLINE       0     0     1
              16876260487220383698                   FAULTED      0     0     0  was /dev/disk/by-path/pci-0000:00:0d.0-scsi-12:0:0:0-part1
            ata-VBOX_HARDDISK_VB875e28a5-4b293298    ONLINE       0     0     0
          mirror-1                                   ONLINE       0     0     0
            ata-VBOX_HARDDISK_VB4145ff65-9b1320a3    ONLINE       0     0     0
            ata-VBOX_HARDDISK_VBee9d66a1-edf52bff    ONLINE       0     0     0
        spares
          pci-0000:00:0d.0-scsi-10:0:0:0             AVAIL   
          pci-0000:00:0d.0-scsi-11:0:0:0             AVAIL   
          pci-0000:00:0d.0-scsi-12:0:0:0             AVAIL   
          pci-0000:00:0d.0-scsi-13:0:0:0             AVAIL   

New, parsable output:

pool:test
state:DEGRADED
status: One or more devices could not be used because the label is missing or invalid. Sufficient replicas exist for the pool to continue functioning in a de$
action: Replace the device using 'zpool replace'. see: http://zfsonlinux.org/msg/ZFS-8000-4J
scan:resilvered 25.8M in 0h0m with 0 errors on Fri Aug 22 12:02:46 2014
config:vdev=test;DEGRADED;0;0;0;                                                                                                                              
config:vdev=mirror-0;DEGRADED;0;0;0;                                                                                                                          
config:vdev=mirror-0,vdev=spare-0;DEGRADED;1;0;0;                                                                                                             
config:vdev=mirror-0,vdev=spare-0,dev=ata-VBOX_HARDDISK_VBb80f1f56-538e9acf;ONLINE;0;0;1;                                                                     
config:vdev=mirror-0,vdev=spare-0,dev=16876260487220383698;FAULTED;0;0;0;was=/dev/disk/by-path/pci-0000:00:0d.0-scsi-12:0:0:0-part1                           
config:vdev=mirror-0,dev=ata-VBOX_HARDDISK_VB875e28a5-4b293298;ONLINE;0;0;0;                                                                                  
config:vdev=mirror-1;ONLINE;0;0;0;                                                                                                                            
config:vdev=mirror-1;ata-VBOX_HARDDISK_VB4145ff65-9b1320a3;ONLINE;0;0;0;                                                                                      
config:vdev=mirror-1;ata-VBOX_HARDDISK_VBee9d66a1-edf52bff;ONLINE;0;0;0;                                                                                      
config:vdev=spares;;;;;;                                                                                                                                      
config:vdev=spares;pci-0000:00:0d.0-scsi-10:0:0:0;AVAIL;;;;                                                                                                   
config:vdev=spares;pci-0000:00:0d.0-scsi-11:0:0:0;AVAIL;;;;                                                                                                   
config:vdev=spares;pci-0000:00:0d.0-scsi-12:0:0:0;AVAIL;;;;                                                                                                   
config:vdev=spares;pci-0000:00:0d.0-scsi-13:0:0:0;AVAIL;;;;                                                                                                   

Ok, so that's not very pretty. Needs more work. But it's a start...

@Der-Jan
Copy link

Der-Jan commented Aug 26, 2014

I'm not sure - but why not use zdb -C output? Looks a bit more parseable and even contains full path:

MOS Configuration:
        version: 5000
        name: 'tank'
        state: 0
        txg: x
        pool_guid: x
        errata: 0
        hostid: x
        hostname: 'x'
        vdev_children: 2
        vdev_tree:
            type: 'root'
            id: 0
            guid: x
            children[0]:
                type: 'raidz'
                id: 0
                guid: x
                nparity: 1
                metaslab_array: 23
                metaslab_shift: 36
                ashift: 12
                asize: 15002898268160
                is_log: 0
                create_txg: 4
                children[0]:
                    type: 'disk'
                    id: 0
                    guid: x
                    path: '/dev/disk/by-id/ata-x-part1'
                    phys_path: '/scsi_vhci/disk@g5000x:a'
                    whole_disk: 1
                    DTL: 63
                    create_txg: 4

@FransUrbo
Copy link
Contributor Author

why not use zdb -C output?

Doesn't contain any status information. But otherwise very good - we could use some of that...

@fire
Copy link

fire commented Sep 2, 2014

Illumos uses a lot of json formatted settings.

@lheckemann
Copy link

What about zpool list -vH?

@benyanke
Copy link

benyanke commented Feb 27, 2021

@behlendorf Why did this get closed without comment? Unless I'm missing something, this still isn't a solved problem.

@behlendorf
Copy link
Contributor

Indeed, this hasn't been resolved. I'm not sure why it was closed, although I seem to be the responsible party. Let me reopen it. There was some progress made in the area with the addition of the new zpool_influxdb command. But it only covers one very specific use case, see the zpool_influxdb(8) man page for details.

@behlendorf behlendorf reopened this Apr 9, 2021
@presto8
Copy link

presto8 commented Apr 26, 2021

Given the complexity of the data being displayed, JSON, YAML, TOML, or some other format may be most useful and also allow easy import into any environment with a parser for those. For example, piping the output into jq on the command line.

@benyanke
Copy link

Agreed - I'd argue json is probably best so you're not messing with newlines.

@presto8
Copy link

presto8 commented Apr 26, 2021

I have never contributed to ZFS before but I would be willing to try an implementation and submit a pull request, unless somebody else is already working on it...

@allanjude
Copy link
Contributor

It isn't prefect yet, but a bunch of the data can be gotten via the new vdev properties interface:
#11711

so you could do:
zpool get -H state,guid,parent,children,read_errors,write_errors,checksum_errors,initialize_errors poolname all

To get the status of all of the VDEVs

I have wondered about exposing the rest of the status state, like status, action, scan, etc, as zpool properties as well.

@benyanke
Copy link

I'm not sure if this is something still being discussed, but I would really appreciate if all the data in zpool status could be exposed as properties, such as scrubs and status. Currently it's very difficult trying to parse zpool status for monitoring purpose, often ending up needing to do odd things like this:

zpool status ${poolname} | grep "scrub in progress" &> /dev/null
  if [[ "$?" == "0" ]] ; then
    scrub=1
  else
    scrub=0
  fi

@SeanTasker
Copy link

I decided to take a look to see how complicated this would be. Following zpool status from the entry point I ended up in print_status_config() on this line. There are a lot of print calls within conditionals here and calls to output functions that look up and output additional information.

Just updating the output functions to check for a JSON output option at every print would make the code hard to read and create a burden for any future status messages that might be added to ensure that the JSON output wouldn't break.

If I was familiar with ZFS development (I haven't done any) and understood these structures and output status combinations better I'd probably have a go at creating a new "status_output" structure, update the existing status_callback() and other functions called within it to populate the new structure, then do a simple output from the structure as either current format or JSON.

I'm not sure if that's helpful for anyone who wants to give this a go.

@rincebrain
Copy link
Contributor

If anyone wanted to explore this, #2905 has some skeletons of what you might want, though obviously it's pretty stale.

@Finkregh
Copy link

Finkregh commented Aug 20, 2024

This would be pretty helpful, especially in cases where a pool is not DEGRADED, when e.g. only a log-mirror device broke:

	NAME                                          STATE     READ WRITE CKSUM
	poolname                                   ONLINE       0     0     0
	 mirror-0                                     ONLINE       0     0     0
	   ata-x-part2                              ONLINE       0     0     0
	   wwn-y-part2                           ONLINE       0     0     0
	logs	
	 mirror-1                                    ONLINE       0     0     0
	   wwn-z-part1                           ONLINE       0     0     0
	   wwn-a-part1                          FAULTED      3 2.71K     0  too many errors
	cache
	 wwn-z-part2                            ONLINE       0     0     0
	 wwn-a-part2                            ONLINE       5    85     0

In the meantime you could parse output from https://github.com/openzfs/zfs/blob/816d2b2bfc2591b951f32aeb7c00e14e27ee624c/cmd/zpool_influxdb/README.md

@robn
Copy link
Member

robn commented Aug 20, 2024

Good news: JSON support was recently added to many zpool and zfs subcommands. See #16217.

$ ./zpool status -jp | jq .
{
  "output_version": {
    "command": "zpool status",
    "vers_major": 0,
    "vers_minor": 1
  },
  "pools": {
    "crayon": {
      "name": "crayon",
      "state": "ONLINE",
      "pool_guid": "16973926705435575469",
      "txg": "1511085",
      "spa_version": "5000",
      "zpl_version": "5",
...

This should be available in the upcoming 2.3 series.

@behlendorf
Copy link
Contributor

Closing since this was done for 2.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Feature Feature request or new feature
Projects
None yet
Development

No branches or pull requests