I’m trying to find a sane way to parse file system information for multiple disks using the Glances REST API. I’ve found this thread, but the accepted solution seemed content to rely on using an array index to assign metrics to a disk. Unfortunately Glances can’t be trusted to always report disk information in the same order (and some disks are not always present).
I’m currently using Glances 2.7.1 because my servers all run Debian Stretch. If this is easily solved by upgrading to Glances 3.x I may pursue that, but I haven’t found any indication that’s the case.
Here is the JSON output of …/api/2/fs:
[{"device_name": "/dev/sdb2", "fs_type": "ext4", "free": 222757384192, "mnt_point": "/", "used": 1574334464, "size": 236412149760, "percent": 0.7, "key": "mnt_point"}, {"device_name": "/dev/sdb1", "fs_type": "vfat", "free": 535670784, "mnt_point": "/boot/efi", "used": 135168, "size": 535805952, "percent": 0.0, "key": "mnt_point"}, {"device_name": "/dev/mapper/sdc", "fs_type": "xfs", "free": 6199598092288, "mnt_point": "/mnt/sdc", "used": 3799094161408, "size": 9998692253696, "percent": 38.0, "key": "mnt_point"}, {"device_name": "/dev/mapper/sdd", "fs_type": "xfs", "free": 4961232416768, "mnt_point": "/mnt/sdd", "used": 5037459836928, "size": 9998692253696, "percent": 50.4, "key": "mnt_point"}]
Technically the yaml below works, but it’s keyed on the array index, which is not reliable. Today /dev/sdb2 is index[0] but tomorrow it might be index[1]:
- platform: rest
resource: http://1.2.3.4:61208/api/2/fs
name: sdb2
value_template: '{{ value_json[0].used| multiply(0.000000001)| round(1) }}'
unit_of_measurement: GB
- platform: rest
resource: http://1.2.3.4:61208/api/2/fs
name: sdb1
value_template: '{{ value_json[1].used| multiply(0.000000001)| round(1) }}'
unit_of_measurement: GB
This solution also (I believe) polls the API twice, which is not efficient. I have to believe there’s a way to grab the full REST info above, parse the array, and pull out values based on some key other than the index. Unfortunately I’m just not smart or caffeinated enough to figure it out. I did try many permutations of the final example on the RESTful Sensor API doc page but I think it wasn’t working because Glances doesn’t assign a parent for each disk.
Thanks! I’m hoping to use any solution from this to maybe make use of the …/api/2/all output to key in on other data more efficiently as well.