[Feature Request] Increase time in CPU usage detection
powergrim opened this issue · 5 comments
I am using this piece of software with a lot of success! I am able to turn on my media-server remotely. But with an eye on power-consumption I want to turn it off when it's not used. I have a schema that doesn't turn off. So Autopoweroff always runs. I`ve set the CPU threshold to 5.
But ever so often my server needs to skip from task to task so it drops to 2/3% for around a second. Therefore, Autopoweroff is triggered. Can the CPU usage detection be increased from 1sec to say 5sec? Like take last 5 seconds, calculate usage over 5sec and take that number as a triggering number? Or, take the highest value every 5 sec, so it doesn't trigger on the 1sec low usage?
Not with a simple configuration. But, to solve your problem quickly, you can edit the installed file ApoObserverResources.py (run locate ApoObserverResources.py
to find its location on your system) and in the following line, change 1
with any interval you want, expressed in seconds:
self.cpuUsage = psutil.cpu_percent(interval=1, percpu=False)
Documentation about the function is located at: https://psutil.readthedocs.io/en/latest/#psutil.cpu_times_percent
I will keep your feature request open because it is a good one and quite easy to implement. I will work on it when I will have some time. Let me know if this quick workaround works fine or not.
Sorry for the late response, busy days.
I did change the threshold to 5 in the file you mentioned. All keeps running fine. But at this point I am thinking it doesn't do anything at all with the threshold. I really looks like when it reaches its startupdelay that the server just shuts down. I have set the aforementioned value to 5 and the .conf value to 2. So it should drop below 2% somewhere in 5sec to match all conditions. I`m sure it doesn't and the server still receives a shutdown from autopoweroff. Is there any logging I can dive in to?
Thanks for the quick response so far!
Mmm... Something fishy is going on. I do not use this feature, but I implemented it for someone else and that person reported that it worked well.
Now, it seams that for you, it does not work well. As a workaround, instead of having Autopoweroff shutdown, you can setup a custom script that just logs the action. This way, your server stays up and you can further debug what is going on. Maybe your process is blocked by an IO and the CPU temporarily drops below your threshold? Unfortunately, you will need to debug this on your side. You could also run a script that loops and burn 100% CPU all the time to see how Autopoweroff handles this. If Autopoweroff works well with this script, it might suggest that your real process does fall sometimes below the CPU threshold. You can also increase the interval from 5s to 120s for instance.
Let me know about your findings.
@powergrim, you have any feedback to provide?
@powergrim, you have any feedback to provide?