logcpu and monitorcpu

Stuff that has yet to be sorted into a category.
Post Reply
Message
Author
User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

logcpu and monitorcpu

#1 Post by MU »

I attach two scripts I wrote.
License: GPL

They can help on servers to keep track of problematic programs, that use a high CPU load.

The numbers I use are examples, you can edit the scripts, to modify intervall, duration, and CPU usage.


logcpu checks every hour, if a program uses more than 70% CPU load.
If yes, a second script is run, logprocess.
It checks for an hour every minute, if the CPU load continuously remains over the desired value.
If yes, it is added to /root/cpulog.txt.

Example (with shorter timings for testing):
So 22. Nov 14:30:42 GMT-8 2009 - 20% - 16396 tty1 SLl 29:42 ./PuppyBrowser
So 22. Nov 14:30:43 GMT-8 2009 - 19% - 28824 pts/1 SLl+ 3:06 mplayer-mt.bin -lavdopts threads=2 /mnt/sda6/filme-sda6/gesehen/Starship_Troopers_09.09.20_23-15_pro7_135_TVOON_DE.mpg.HQ.avi
So 22. Nov 14:32:50 GMT-8 2009 - 20% - 16396 tty1 SLl 30:03 ./PuppyBrowser
So 22. Nov 14:32:50 GMT-8 2009 - 19% - 28824 pts/1 SLl+ 3:30 mplayer-mt.bin -lavdopts threads=2 /mnt/sda6/filme-sda6/gesehen/Starship_Troopers_09.09.20_23-15_pro7_135_TVOON_DE.mpg.HQ.avi
So 22. Nov 14:34:57 GMT-8 2009 - 20% - 16396 tty1 SLl 30:24 ./PuppyBrowser

Almost the same is achieved with "monitorcpu".
But here the program is not added to a logfile, but instead it will be killed.


To stop them, type:
killall logcpu
killall logprocess


or:
killall monitorcpu
killall monitorprocess


I also included start/stop scripts for /etc/init.d (to run them when Puppy starts).
So if you copy those, you could use
/etc/init.d/logcpu start
/etc/init.d/logcpu stop


Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

User avatar
MU
Posts: 13649
Joined: Wed 24 Aug 2005, 16:52
Location: Karlsruhe, Germany
Contact:

#2 Post by MU »

here is a modified version, "cpukillflash".

It checks the OVERALL CPU-usage every 30 seconds.
If it is higher than "limit" (95%), then it runs "cpukillflash2" in background.

This one checks for 5 minutes every 30 seconds, if the usage remains over the limit. If yes, then "killall flashplayer" is executed.


Instead of "killall flashplayer" you could add your own command, e.g. write to a logfile, or send an email to alert the administrator of the server.

Mark
[url=http://murga-linux.com/puppy/viewtopic.php?p=173456#173456]my recommended links[/url]

Post Reply