CPU use is excessive

Just as an update - nothing last night only a few random hits in the logs average cpu back to normal.

Still a little concerned over number of processes - has dropped from yesterday but still 200 - which is much higher than the production server currently at 144-155 (9 domains)

I wouldn’t worry about it here is a production server that is working fine

I wouldn’t worry so much for a production server (I’d even expect it and the cpu load is also low on the production VS box as it as more cores to share the work.)

But it is the OP VS that is giving me concern. Sure it is only 1 core but there is nothing to do here - virtually no activity other than idle waiting for the very occasional web request and odd email (no more than 3 a day between the 4 users and me.

When happens go to Webmin > System > Running Processes and see what eats CPU
Could be cleanup/ logrotate/ webmin backup or hosting backup (etckeeper or git)/ awstats/ setup backups/ any cron job

the problem (CPU 100%) was spotted yesterday and had happened overnight having cleared itself by the time I logged in with nothing in the logs.

I have gone in Webmin -> System -> Running Processes and they are all at < 0.5% cpu now as they were when I checked yesterday (I was not awake when the cpu was 100%) - I don’t think there is a way of monitoring cpu when it goes high. but would expect something to be logged somewhere.

There is no backup on this VS (there really is nothing worth backing up!)
I could clean up the log rotates but these I would guess only have impact on file storage and the stats - I cannot see how that would help.

Just checked processes again and /usr/share/webmin/proc/index_cpu.cgi is running at 56% with a refresh taking it back down to <1%
What does this process do? Is it important? Is it just a glitch?

SOlution inspired from link in bottom

Make a new service

It should contain the command in square brackets [while true; do (echo “%CPU %MEM ARGS $(date)” && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> /var/log/ps.log; sleep 5; done]

Save it and start it, or reboot to see if starts (and check how it looks)

You’ll have the log in /var/log/ps.log

My newb inspiration command line - How to log CPU load? - Ask Ubuntu

Hope that helps.

Tx. but a slight problem when starting

What is the log saying?
And please paste the exact cpulog.service, how you wrote it.

It should look exactly like this, is case sensitive (Webmin > System > Bootup and Shutdown, than press on cpulog.service)

[Unit]
Description=CPU Logging

[Service]
ExecStart=/bin/sh -c 'while true; do (echo “%CPU %MEM ARGS $(date)” && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> /var/log/ps.log; sleep 5; done'

[Install]
WantedBy=multi-user.target

it seems to be those “square brackets”?

Don’t use the [ … code … ], only the command between the ’ '. I put the square brackets only to contain the command, they shouldn’t be included in it.

while true; do (echo “%CPU %MEM ARGS $(date)” && ps -e -o pcpu,pmem,args --sort=pcpu | cut -d" " -f1-5 | tail) >> /var/log/ps.log; sleep 5; done

It should work

Also, I named it “cpu-log.service” with a - because cpulog could be a service of OS, you can name it anything really

And the logging works from when I posted here, and it seems that isn’t that big. Anyway, as I said before, 100% CPU could be from ClamVM and other maintanance service

I deleted the previous one
Still same - will not start.

not running - too big - not of use on this machine.

Copy and paste that command in terminal as root, than go in /var/log/ and look for ps.log and see if works from terminal. After you issue the command the log should appear.

If the command doesnt work maybe I have installed something you have not.

No it didn’t like it. terminal got stuck and had to break out ^Z
[+1] Stopped Sleep 5 There are Stopped Jobs

Ctrl+C to exit
The command doesn’t output nothing while runs, that’s normal.

Did you checked the log in /var/log/ps.log?

I did check systemctl which has this

and unsurprisingly no ps.log

DO you have ps command installed on your system?

Type in terminal:

ps

If not, install it with:

apt-get install procps

procps is already the newest version (2:3.3.16-1ubuntu2.3).

It works on 2 vHosts and my daily driver, just tested and improved it a bit:

while true; do (echo "\nCPU\tMEM\tUser\tGroup\tvMem\tNice\tCMD\tARGS\t$(date)" && ps -e -o pcpu,pmem,user,group,vsz,nice,args --sort=-pcpu | cut -d" " -f1- | tail) >> /var/log/ps.log; sleep 5; done

And this is the log format for the new version, hope that helps someone:


*As a note, if you are in docker or something, maybe ps doesn’t work.

1 Like

That worked !!!

and I have a log to study next time it goes crazy (if it does)

Many thanks for persevering.

You’re welcome, but I also learned something today, so thank you too :slight_smile: