-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
boot_time() is wrong #658
Comments
What OS is that? Linux? |
sorry, yes, arch linux arm, updated to latest version |
Please paste the output of |
cat /proc/stat |
Uhm... that
Maybe your system clock was messed up? |
the system clock is messed up because the raspi does not have the HW clock, so it start as timestamp=0 and then NTP set it to correct value. |
Since this is no longer reproducible I'm gonna close it for now. Feel free to reopen in case you bump into this issue again. |
I have a pretty easy way to reproduce it here with telegraf, which uses the gopsutil library, which is pretty much a word for word rewrite of your library: I have added a bug at gopsutil but your bug is pretty much the same: launch the python script before NTP does its magic, then wait until NTP corrects the date, and then enjoy your 40+ years uptime :D |
Mmm... I guess that means that /proc/stat doesn't get updated for some reason. |
This is what I get for a problematic Rpi:
If you do the math, it actually makes sense, all the numbers are correct. The issue is that you retrieve |
That is true, |
There is another flip of this coin which is probably worth mentioning. The cost of giving up the cache and return the right process creation time after a system clock update is a 2x slowdown when creating a
|
I understand the performance issue, but the returned value is still wrong for any system that encountered NTP adjustment during the life of the python process that uses psutil. As I said in the original bug in telegraf (which uses the python gopsutil but has the same bug), I suspect that many monitoring systems might be minutes or hours off their real uptime, depending on how skewed their RTC is, and how often the NTP process has to compensate for it. Right now the only way to solve the issue is to restart the python process doing the monitoring. Maybe there is a middle ground where the actual btime is read again at regular intervals (say, at least every 15 minutes) and cached in between? |
I agree this should be fixed. We can resolve the slowdown by getting the boot time by using
Note to self: this issue is related to #1724. |
Also, another note to self: originally we were already using |
Lines 435 to 440 in 7ce6c3c
It appears that uptime -s returns a stable time, but still not sure how. This should be the source code:https://github.com/coreutils/coreutils/blob/master/src/uptime.c |
@giampaolo if If what is said in #1724 is right, you can bypass the problem for the process Then the last thing to check is that in VM/docker environment, the |
Ah my bad, |
The caching is why we have this problem currenly: since |
Yeah but it might be sufficient to read it at regular intervals (every N calls, or store the last read timestamp and read every 15 minutes). The problem lies in reading it only once. If the uptime is eventually consistent, then it might be OK. I'm just suggesting this because you mentioned the performance hit, the real, irrefutable fix is to read |
hi,
on a system without HW clock (raspberry) the boot_time() give 45 years (since epoch), while "uptime" command from shell give correct results.
The text was updated successfully, but these errors were encountered: