Trying unsuccessfully to get space usage percentage using Pool API (/api/v2.0/pool/)

stewartLG

Dabbler
Joined
Dec 21, 2016
Messages
13
I'm the author of a Nagios plug-in that uses the TrueNAS API to check a TrueNAS server for various kinds of health and status, and it uses the 2.0 API.

https://github.com/StewLG/check_truenas_extended_play

A user/fellow developer has submitted a PR to me that attempts to use the data coming back about the zpools from the /api/v2.0/pool/ API call to work out the used/free capacity for the zpool. It does this by adding up the topology.data.size and topology.data.allocated values for all a zpool's vdevs, and doing a percentage calculation.

This math isn't working out to agree with the TrueNAS GUI, and it's off enough that it's not yet fit for deployment (10-20% off).

Are the topology.data.size and topology.data.allocated values inclusive or exclusive of parity? Do they ignore or include the RaidZ level? How can I get reasonably close to the output I see in zpool_capacity.py, which is just calling 'zpool list -H -o cap'?
 

ClassicGOD

Contributor
Joined
Jul 28, 2011
Messages
145
/api/v2.0/pool/ endpoint contains pool data - the values there are as ZFS sees them so depending on a pool configuration. For example for RAIDz2 pool it sums up space of all drives, for Mirror you see only "half". It's equivalent to "zpool list" output.

what you want is /pool/dataset endpoint. Every pool should contain top level dataset with the same name as the pool. There you'll find both .used and .available value in raw and parsed formats.
 

stewartLG

Dabbler
Joined
Dec 21, 2016
Messages
13
Thank you for responding!

I figured out that I had to use datasets already, and the script is now working properly. I am sorry for not following up here to answer my own question.
 
Top