Unreliable InfluxDB size sensor

Being fussy, there is probably a small correction to some of the code above related to using du -s xxxxxxxxx to measure the disk usage. ie :

"{{ (value.split('\t')[0]|int(0)/1000)|round(1) }}"

Should probably be corrected to :

"{{ (value.split('\t')[0]|int(0)/1024)|round(1) }}"

Unless you have something non standard in your environment variables, du -s will give a number in number of “blocks” that are used on the disk. But default, a block will usually be 1024 bytes (but not always). So effectively, this is a measure of the KB of disk usage. In addition to that, when measuring MB for disk usage, it is usually a binary measurement where there are 1024 bytes in a KB and 1024KB in a MB. So to get the du -s number to MB we need to divide by 1024. To give a number in binary MB.

Being fussy, even if you want your MB to by measuring bytes where there are 1,000,000 bytes in a MB (which is less conventional but sometimes referred to as decimal notation), you would still NOT divide by 1000 to get MB. You would still need to multiply the number of blocks by 1024 (to get it in bytes), then you would need to divide by 1,000,000 to get it into decimal MB which is a different answer again. Which gives a slightly different answer.

Note : decimal MB is most commonly used by HDD manufacturers which makes their capacity look as big as possible in the marketing marterial. But on the computer, mostly when referring to KB, MB, GB or TB they are binary numbers where 1024 is the multiple. This is one of the reasons why a 1TB drive come up short of 1TB when you put it in your computer and they give you an indication in the OS. On the computer they measure in binary 1024x1024x1024 MB definition, but the HDD manufacturers like the bigger 1,000,000 MB definition.

If your environment is setup a little differently and the default “block size” for du is different, you can check this with :

du -sb

which will give you the number of bytes of disk used. If you divide this number by the number from

du -s

it will confirm the block size and thus the number you will need to convert to bytes. And if it is anything other than 1024, you will need to adjust your maths a bit to better understand the actual disk usage.

1 Like