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 Network sensors number-wrap #5141

Closed
Tommatheussen opened this issue Jan 2, 2017 · 10 comments
Closed

System monitor Network sensors number-wrap #5141

Tommatheussen opened this issue Jan 2, 2017 · 10 comments

Comments

@Tommatheussen
Copy link
Contributor

Home Assistant release (hass --version):
0.35.3

Python release (python3 --version):
3.4.3

Component/platform:
System Monitor

Description of problem:
The system monitor network interfaces do not take in account wrapping around the maximum number.
After the amount gets too high, the number just wraps around to 0.

Expected:
The number should not wrap around to 0, unless the interface has actually been set to 0 again.

Problem-relevant configuration.yaml entries and steps to reproduce:

- platform: systemmonitor
    resources:
      - type: network_in
        arg: eth0
  1. Let the number accumulate high enough

Additional info:
Reading in the psutil lib docs, there's stated here: https://pythonhosted.org/psutil/#network
that applications should be prepared for this.
I got a very old system, and it already wraps around after 4096MiB.
You can see this on the following screenshots:

screen shot 2017-01-02 at 12 39 25

While in my /proc/net/dev (where psutil gets the info from) these numbers can be seen:

screen shot 2017-01-02 at 12 40 40

@fanaticDavid
Copy link
Contributor

I've noticed this behaviour too, for both network_in and network_out, but silly me never thought of looking at the graph to see what the cut-off point was. I ended up removing both resources from my config as I couldn't make sense of the values (and it's pointless anyway when it resets every now and then).

I take it the values should only reset upon rebooting the host HASS is running on?

@Tommatheussen
Copy link
Contributor Author

As far as I could find, the values are indeed reset upon restarting the host.

Knowing this, it would be more useful for me to get monthly stats, so I should check wether I can reset those manually or find another solution :p

@fanaticDavid
Copy link
Contributor

I just happen to do some research and it seems this is caused by a known issue in psutil. The documentation contains the following warning about the network monitor:

on some systems such as Linux, on a very busy or long-lived system these numbers may wrap (restart from zero), see issues #802. Applications should be prepared to deal with that.

That issue was opened 10 months ago, so the system monitor may require changes to deal with the number wrapping (as suggested).

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@giampaolo
Copy link

giampaolo commented May 8, 2017

(psutil author here)

It's the OS which wraps those numbers, psutil simply returns them unmodified. Unfortunately a bullet proof solution to this problem really does not exist.

psutil may do some magic in order to "watch" the numbers which wrap across function calls and do old_big_number + new_smaller_number (e.g. 233340298402 + 20) but of course when the function is called for the first time it doesn't know whether 20 is a number which has already wrapped or not.

Also, psutil is not aware of what the exact threshold at which the number is supposed to wrap is, so in the example above adding 20 is a step forward but the resulting number would still not be correct because it doesn't take the threshold into account. The right formula would be:

old_num + (threshold - old_num) + new_num

...but we don't have the threshold value.
That aside, assumed there is no bullet proof solution, rolling in the "partial" solution described above would be better than nothing and I'd be OK with it.

re: giampaolo/psutil#802

@giampaolo
Copy link

giampaolo commented May 9, 2017

OK, I've fixed this in psutil: https://github.com/giampaolo/psutil/pull/1056/files (future 5.3.0).
Both disk_io_counters() and net_io_counters() now provide a new nowrap parameter (True by default) which adjusts the numbers which overflow and wrap (restart from 0) by adding "old value" to "new value". With this the returned numbers will always be increasing or remain the same, but never decrease.

@balloobbot
Copy link

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates.

Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍

@balloobbot
Copy link

This issue will be auto-closed because there hasn't been any activity for a few months. Feel free to open a new one if you still experience this problem 👍

@giampaolo
Copy link

New psutil 5.3.0 is out and it includes the fix which wraps the numbers in case they reset from zero so the fix for the home-assistant project consists in upgrading psutil.

@fanaticDavid
Copy link
Contributor

That should be sorted in the next (major) release: #9253

@home-assistant home-assistant locked and limited conversation to collaborators Dec 11, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants