Return System Monitor integration disk/mem stats in bytes instead (or provide option)

Most monitoring platforms (e.g. disk input plugin in Telegraf, etc) return disk usage in bytes. This avoids any ambiguity with SI vs IEC units, and would also match the output of the df -B1 command in linux. It also gives more fine-grained monitoring of the disk usage (allowing to spot log file leaks, etc, before they become a problem).

E.g. 1 kilobyte (kB) = 1000 bytes, 1 kibibyte (kiB) = 1024 bytes.

Currently, Home Assistant’s System Monitor integration reports units in gibibytes (GiB). This is then rounded to one decimal place in the source code here.

This results in values like 4.3 GiB:

The problem is that, because the value is already rounded, I cannot simply convert back to bytes by multiplying as 4.3 x 1024 x 1024 x 1024 = 4,617,089,843. Some resolution is lost. The true value in my case is 4,563,746,816 bytes:
image

The only way to get fine-grained value back in bytes is to either run the df utility manually, or use an external monitoring service on the host (e.g. Telegraf).

As disk blocks have fixed sizes of 512 bytes or more, you can probably get back to what it should be. The question is however, what is your use case for needing accuracy on single byte level? In other words, why should anyone care?

Edwin is correct, but you know you can choose your units?

@Edwin_D As stated, it allows to better keep an eye on disk usage leaks.

I am absolutely not looking for accuracy on the single byte level (and have no use case for that).

But at the moment, The System Monitor shows me values to 1 decimal place, which means changes of 0.1 GiB. So this is ~100 MB, which is very coarse resolution changes.

Again that setting is there too, right below.

Removed from feature requests as it is already there.

@nickrout This doesn’t increase the resolution. The value is always given in GiB and rounded to 1 decimal place in the source code. It cannot be changed.

The setting you are referring to merely takes this rounded value (i.e. already decreased resolution), and simply multiples it back by 1024 x 1024 x 1024. This isn’t the true value in bytes.

(the true value is 4,563,746,816 bytes in my case).

How did you establish that?

I moved it back

I provided a screenshot in the original post, showing the output of the df -B1 command on the Home Assistant host machine.

Yes I see it now, thanks for pointing that out.

I guess a workaround is a command line sensor running df -B1

1 Like

Okay yes that will work.

This gives correct disk usage in bytes:

command_line:
  - sensor:
      name: system_monitor_disk_total_bytes
      command: "df -B1 / | tail -1 | awk '{print $2}'"
      unit_of_measurement: "B"
  - sensor:
      name: system_monitor_disk_use_bytes
      command: "df -B1 / | tail -1 | awk '{print $3}'"
      unit_of_measurement: "B"
  - sensor:
      name: system_monitor_disk_free_bytes
      command: "df -B1 / | tail -1 | awk '{print $4}'"
      unit_of_measurement: "B"
  - sensor:
      name: system_monitor_disk_used_percent
      command: "df -B1 / | tail -1 | awk '{print $5}' | tr -d '%'"
      unit_of_measurement: "%"
1 Like

A true Linux user, love it.

awk, hard to get your head around at first.