first i have to say that cacti and even rrdtool are very great tools. I'm using them since monday. So i want to share a script i wrote for counting specific processes with you:
Code: Select all
#!/usr/bin/perl -w
#
# advanced process counting script for use with cacti - by Achim Schrepfer <a.schrepfer@oncom.de>
# 10.04.2003 - Version 0.1
#
# counts process numbers for any given command; type "ps -eo cmd|awk '{print $1}'|sort|uniq" to see the command-list on your machine
#
# usage:
# proc_advanced.pl command_name1[,command_name2,...]
#
# output:
# num_procs_for_cmd1 num_procs_for_cmd2 ...
use strict;
# go away without arguments
if (!@ARGV) { exit 1; }
my %command_counter;
# initialize counters for each command
foreach (@ARGV) {
$command_counter{ $_ } = 0;
}
# walk through the process list and count processes if exist
foreach (split(/\n/,`ps -eo cmd|awk '{print \$1}'`)) {
$command_counter{ $_ } ++ if (exists($command_counter{ $_ }));
}
my @values;
foreach (@ARGV) {
push @values, $command_counter{ $_ };
}
# print out process counters in same order as the arguments seperated by spaces
print join(' ',@values);
To see what commands are used for the specifig processes type in the following command: ps -eo cmd|awk '{print $1}'|sort|uniq
have fun
moojoo