CPU use is excessive

SYSTEM INFORMATION
OS type and version Ubuntu Linux 20.04.6
Webmin version 2.021
Usermin version 1.861
Virtualmin version 7.7
Theme version 20.21
Package updates All installed packages are up to date

Woke up this morning to this alarm:


It is not an important VS and not a big use system (consider it idling)
However, as you can see the CPU use suddenly went up to 100% and stayed there for an extended period.
I have looked in the logs and cannot find anything to explain it. Only the other minor spikes (where I or a domain user has logged in) The load averages look normal and typically in the range 0% to 3%. There is no website or activity during that period that also coincides with most folk being asleep.

Any ideas?

you think 1 user logging and spiking to 100% in is normal ? what does this vps have 1/2 a core ?

Yes it does. It is only a test bed so nothing important and not production (ha ha)
I am not worried by the spikes I can account for them.
I just cannot figure out the long period (overnight) when the cpu goes up suddenly to 100% and stays there when nothing happened. Nothing in the logs.

The process count looks quite high for what is there but at least that is a constant. and the cpu is currently ticking over at 1-3% which is pretty normal.

does it have a wordpress site on it ?

Certainly not! I hate WP and wouldn’t go anywhere near it.
I should also add that PHP is disabled here the “site” not that I’d call it that is just a group of simple .html tests with no linking or menu the css and js are also very small - the domain is obscure so very unlikely to be searched. the index.html remain the Virtualmin default. Nothing in the access or error logs for the period in question. I have looked on previous nights and there are only a few random hits.

I don’t look here every day and only spotted the use today as I was adding a new test.html file

Then I’m unsure … you might have to wait till next time it happens

Thanks, you are probably right. but when/if it does then with nothing in the logs this time I don’t expect anything next time. I wondered if there is some process running that is not logging but is using a lot of cpu.

if you catch it using 100% cpu should be easy to look at what it is

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.