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

System Monitor disk usage reports identical values for all devices #50158

Closed
attila123456 opened this issue May 6, 2021 · 4 comments · Fixed by #50362
Closed

System Monitor disk usage reports identical values for all devices #50158

attila123456 opened this issue May 6, 2021 · 4 comments · Fixed by #50362

Comments

@attila123456
Copy link

The problem

After upgrading to 2021.5.0 I noticed that all my disk usage widgets on the dashboard were showing identical values.
The code uses psutil.disk_usage(path) to check disk space, and when I ran the same command inside the home assistant docker container, in a python shell, it came back with correct values.

So after some digging in the code, I came across #48699 which seems to have introduced caching, which could cause an issue like this. Could it be using a single cached value for all disk usage/device entries?

What is version of Home Assistant Core has the issue?

2021.5.0

What was the last working version of Home Assistant Core?

2021.4.6

What type of installation are you running?

Home Assistant Container

Integration causing the issue

systemmonitor

Link to integration documentation on our website

https://www.home-assistant.io/integrations/systemmonitor/

Example YAML snippet

- platform: systemmonitor
    resources:
      - type: disk_use_percent
        arg: /
      - type: disk_free
        arg: /
      - type: disk_use_percent
        arg: /mnt/storage
      - type: disk_free
        arg: /mnt/storage
      - type: memory_free
      - type: memory_use
      - type: memory_use_percent
      - type: last_boot
      - type: load_1m
      - type: load_5m
      - type: load_15m

Anything in the logs that might be useful for us?

No response

Additional information

No response

@ColinRobbins
Copy link
Contributor

ColinRobbins commented May 9, 2021

I’ve seen this too.
The problem seems to relate to the recent update to add a dictionary to update all values in one update operation.

To me, the sensor_registry seems to be based on a type (disk_usage) having single values, not multiple.

During set up, line 228 in systemmonitor/sensor.py sets up sensor_registry, where _type is what the sensor should monitor and argument is the path name.

sensor_registry[type_] = SensorData(argument, None, None, None, None)

If this is called for a 2nd or 3rd time, the previous value of argument is lost.

Line 229 creates a new SystemMonitorSensor per config line

  entities.append(SystemMonitorSensor(sensor_registry, type_, argument))

and uses the registry as the data store.

Thus when the 2nd or 3rd sensor of the same type is added they all share the same sensor_registry data, so all see the same value. Thus any data presented by the sensor is duplicated.

ColinRobbins added a commit to ColinRobbins/Home-Assistant-Core that referenced this issue May 9, 2021
@artlov
Copy link

artlov commented May 9, 2021

I can confirm. I found same issue after core upgrade.

- platform: systemmonitor
 resources:
   - type: disk_free
     arg: /
   - type: disk_free
     arg: /share
   - type: disk_free
     arg: /media


config $ df -hT
Filesystem           Type            Size      Used Available Use% Mounted on
overlay              overlay       195.9G      7.9G    178.0G   4% /
/dev/nvme0n1p2       ext4           27.4G      4.6G     21.3G  18% /share
/dev/nvme0n1p5       ext4          697.4G    593.6G     68.3G  90% /media

image

@ColinRobbins
Copy link
Contributor

I have fixed it in my local environment, had have just created a pull request #50362

@bdraco bdraco self-assigned this May 10, 2021
balloob pushed a commit that referenced this issue May 10, 2021
* Fix #50158 - add support for multiple disks

* Rework as a tuple
balloob pushed a commit that referenced this issue May 10, 2021
* Fix #50158 - add support for multiple disks

* Rework as a tuple
@ColinRobbins
Copy link
Contributor

Should be fixed in 2021.5.2

@github-actions github-actions bot locked and limited conversation to collaborators Jun 9, 2021
thomasgermain pushed a commit to thomasgermain/home-assistant that referenced this issue Jun 10, 2021
* Fix home-assistant#50158 - add support for multiple disks

* Rework as a tuple
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants