Ps-watcher can run ps periodically and match patterns based on the output of ps. You can check for memory usage, number of processes, etc. Let’s grab the program and try to compile:
[root@test psw]# ls ps-watcher-1.0.tar.gz [root@test psw]# tar -xzf *.gz [root@test psw]# cd ps* [root@test ps-watcher-1.0]# ls aclocal.m4 configure install-sh mkinstalldirs README touch.pl AUTHORS configure.ac Makefile.am NEWS samples ChangeLog COPYING Makefile.in post-configure.in tests config.guess docs Makefile.PL ps-watcher THANKS config.sub INSTALL missing ps-watcher.in.in TODO [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether ln -s works... yes checking whether make sets $(MAKE)... (cached) yes checking for perl... /usr/bin/perl checking for ps... /bin/ps configure: creating ./config.status config.status: creating Makefile config.status: creating post-configure config.status: creating docs/Makefile config.status: creating tests/args.t config.status: creating tests/basic.cnf config.status: creating tests/basic.t config.status: creating tests/count.t config.status: creating tests/full.t config.status: creating tests/Makefile config.status: creating ps-watcher.in config.status: executing default-1 commands Checking for your version of Perl...5.006001 Checking to see that you have all library modules installed... Sys::Syslog is installed File::Basename is installed Pod::Text is installed Need package "Config::IniFiles": Can't locate Config/IniFiles.pm in @INC (@INC contains: /usr/lib/perl5/5.6.1/i386-linux /usr/lib/perl5/5.6.1 /usr/lib/perl5/site_perl/5.6.1/i386-linux /usr/lib/perl5/site_perl/5.6.1 /usr/lib/perl5/site_perl/5.6.0/i386-linux /usr/lib/perl5/site_perl/5.6.0 /usr/lib/perl5/site_perl /usr/lib/perl5/vendor_perl/5.6.1/i386-linux /usr/lib/perl5/vendor_perl/5.6.1 /usr/lib/perl5/vendor_perl .) at (eval 4) line 3. [root@test ps-watcher-1.0]# |
Doh! Gotta install the IniFiles module. Let’s find it and install:
root@test ps-watcher-1.0]# perl -MCPAN -e shell /usr/lib/perl5/5.6.1/CPAN/Config.pm initialized. CPAN is the world-wide archive of perl resources. It consists of about 100 sites that all replicate the same contents all around the globe. Many countries have at least one CPAN site already. The resources found on CPAN are easily accessible with the CPAN.pm module. If you want to use CPAN.pm, you have to configure it properly. If you do not want to enter a dialog now, you can answer 'no' to this question and I'll try to autoconfigure. (Note: you can revisit this dialog anytime later by typing 'o conf init' at the cpan prompt.) Are you ready for manual configuration? [yes] no . . . commit: wrote /usr/lib/perl5/5.6.1/CPAN/Config.pm cpan shell -- CPAN exploration and modules installation (v1.59_54) ReadLine support available (try 'install Bundle::CPAN') cpan> cpan> i /IniFiles/ CPAN: Storable loaded ok CPAN: LWP::UserAgent loaded ok . . . Distribution J/JV/JVBSOFT/Config-IniFiles-Import-1.000.tar.gz Distribution W/WA/WADG/Config-IniFiles-2.38.tar.gz Module Config::IniFiles (W/WA/WADG/Config-IniFiles-2.38.tar.gz) Module Config::IniFiles::Import (J/JV/JVBSOFT/Config-IniFiles-Import-1.000.tar.gz) 4 items found cpan> cpan> install Config::IniFiles Running install for module Config::IniFiles Running make for W/WA/WADG/Config-IniFiles-2.38.tar.gz Trying with "/usr/bin/lynx -source" to get ftp://ftp.perl.org/pub/CPAN/authors/id/W/WA/WADG/Config-IniFiles-2.38.tar.gz CPAN: MD5 security checks disabled because MD5 not installed. Please consider installing the MD5 module. Scanning cache /root/.cpan/build for sizes Config-IniFiles-2.38/ Config-IniFiles-2.38/t/ . . . t/06oo..............ok t/07misc............ok, 1/4 skipped: unknown reason All tests successful, 1 subtest skipped. Files=8, Tests=83, 0 wallclock secs ( 0.57 cusr + 0.06 csys = 0.63 CPU) /usr/bin/make test -- OK Running make install Installing /usr/lib/perl5/site_perl/5.6.1/Config/IniFiles.pm Installing /usr/share/man/man3/Config::IniFiles.3pm Writing /usr/lib/perl5/site_perl/5.6.1/i386-linux/auto/Config/IniFiles/.packlist Appending installation info to /usr/lib/perl5/5.6.1/i386-linux/perllocal.pod /usr/bin/make install -- OK cpan> cpan> exit Lockfile removed. [root@test ps-watcher-1.0]# |
Let’s try again:
[root@test ps-watcher-1.0]# ./configure checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk . . . Checking what to put after #! at the top of ps-watcher.../usr/bin/perl Rewriting ps-watcher.in into ps-watcher... ./ps-watcher.stamp All done. Now run "make"; "make check" [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# make Making all in docs make[1]: Entering directory `/root/psw/ps-watcher-1.0/docs' pod2man --section=8 ../ps-watcher.in >ps-watcher.8 pod2html --infile=../ps-watcher.in --outfile=ps-watcher.html make[1]: Leaving directory `/root/psw/ps-watcher-1.0/docs' Making all in tests make[1]: Entering directory `/root/psw/ps-watcher-1.0/tests' make[1]: Nothing to be done for `all'. make[1]: Leaving directory `/root/psw/ps-watcher-1.0/tests' make[1]: Entering directory `/root/psw/ps-watcher-1.0' make[1]: Nothing to be done for `all-am'. make[1]: Leaving directory `/root/psw/ps-watcher-1.0' [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# make check Making check in docs make[1]: Entering directory `/root/psw/ps-watcher-1.0/docs' make[1]: Nothing to be done for `check'. make[1]: Leaving directory `/root/psw/ps-watcher-1.0/docs' Making check in tests make[1]: Entering directory `/root/psw/ps-watcher-1.0/tests' make args.t basic.t count.t full.cnf args.cnf basic.cnf count.cnf full.cnf make[2]: Entering directory `/root/psw/ps-watcher-1.0/tests' make[2]: `args.t' is up to date. make[2]: `basic.t' is up to date. make[2]: `count.t' is up to date. make[2]: Nothing to be done for `full.cnf'. make[2]: Nothing to be done for `args.cnf'. make[2]: `basic.cnf' is up to date. make[2]: Nothing to be done for `count.cnf'. make[2]: Nothing to be done for `full.cnf'. make[2]: Leaving directory `/root/psw/ps-watcher-1.0/tests' srcdir=.; export srcdir; \ /usr/bin/perl ./driver args................ok basic...............ok count...............ok full................ok All tests successful. Files=4, Tests=10, 5 wallclock secs ( 1.77 cusr + 2.79 csys = 4.56 CPU) make[1]: Leaving directory `/root/psw/ps-watcher-1.0/tests' make[1]: Entering directory `/root/psw/ps-watcher-1.0' make[1]: Nothing to be done for `check-am'. make[1]: Leaving directory `/root/psw/ps-watcher-1.0' [root@test ps-watcher-1.0]# |
That’s all good. Lets run some tests:
[root@test ps-watcher-1.0]# vi config.ini [root@test ps-watcher-1.0]# cat config.ini [httpd] action = echo "There are $count instances of httpd running" [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# ./ps-watcher --config config.ini --log log [root@test ps-watcher-1.0]# tail log ps-watcher: Starting: $Id: ps-watcher.in.in,v 1.25 2003/07/10 11:50:21 rockyb Exp $ ps-watcher: There are 16 instances of httpd running [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# cat config.ini [httpd] trigger = $count < 17 action = echo "There are $count instances of httpd running - less than 17" [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# ./ps-watcher --config config.ini --log log [root@test ps-watcher-1.0]# tail log ps-watcher: Starting: $Id: ps-watcher.in.in,v 1.25 2003/07/10 11:50:21 rockyb Exp $ ps-watcher: There are 16 instances of httpd running - less than 17 [root@test ps-watcher-1.0]# [root@test ps-watcher-1.0]# vi config.ini [root@test ps-watcher-1.0]# cat config.ini [httpd] trigger = $count < 16 action = echo "There are $count instances of httpd running - less than 16" [root@test ps-watcher-1.0]# ./ps-watcher --config config.ini --log log [root@test ps-watcher-1.0]# tail log -n 1 ps-watcher: Starting: $Id: ps-watcher.in.in,v 1.25 2003/07/10 11:50:21 rockyb Exp $ [root@test ps-watcher-1.0]# |
On the first test, we see that there are 16 instances of httpd running, but on the second test, the trigger doesn’t fire, because there are not less than 16. Of course, you can perform any action based on the trigger results. Virtually any test you can think of regarding processes can be evaluated. Pretty cool utility.