OpenGamePanel/OGP-Agent-Linux

Process Monitor does not reflect real time CPU usage

Closed this issue · 5 comments

As title says, the Process Monitor in Dashboard module does not reflect the real time CPU usage, because it uses 'ps' and this is the way it works.

I tried to find some viable native alternative on Linux, and found that we may be able to achieve kinda the same thing as it currently does, but with accurate results for CPU usage by changing ogp_agent.pl line 3836

from $taskList{'task'} = encode_base64(`ps -Ao user,pid,pcpu,pmem,comm,args --sort=-pcpu | head -n 30`);

to $taskList{'task'} = encode_base64(`top -b -c -i -o +%CPU -w512 -n1|grep "COMMAND" -A 30`);

Unfortunately top is not very friendly when it comes to customization, but I think it would be better this way.

What do you think guys? Do you know any alternative to do what it currently does (list processes resources usage and informations, and sorting them by CPU usage) without adding extra packages to OGP install?

Why do you get the impression that ps is not accurate? I'm pretty sure it is...

Because I run a few 64 slots server, when I look with HTOP it show the process X or Y goes to 95% - 106% CPU and in Process Monitor it shows 11.5% or so.. From my internet researches it is because of that:

man ps in NOTES section.

CPU usage is currently expressed as the percentage of time spent running
during the entire lifetime of a process. This is not ideal, and it does not
conform to the standards that ps otherwise conforms to. CPU usage is
unlikely to add up to exactly 100%.

HTOP shows the real time CPU usage and it is constantly changing, but for same server process, when it is started since two days the CPU usage in Process Monitor is not accurate at all and stays low.

What's wrong with the top implementation? Why can't we just use that over htop?

I did not say to use htop

I tried to find some viable native alternative on Linux, and found that we may be able to achieve kinda the same thing as it currently does, but with accurate results for CPU usage by changing ogp_agent.pl line 3836

from $taskList{'task'} = encode_base64(ps -Ao user,pid,pcpu,pmem,comm,args --sort=-pcpu | head -n 30);

to $taskList{'task'} = encode_base64(top -b -c -i -o +%CPU -w512 -n1|grep "COMMAND" -A 30);

Unfortunately top is not very friendly when it comes to customization, but I think it would be better this way.

I just said that I see the real CPU usage in htop (because I always use htop over top, especially when I was replying, but top and htop are similar) which is completely different than ps. But my suggestion is to use top as it is the only native solution in Linux I found.

created PR #9