use strict; use warnings; print "localtime,ESTABLISHED,LISTEN,TIME_WAIT,httpd,cgi,Threads_connected,Threads_running,lvg_1min,lvg_5min,lvg_10min,running/total,lastpid,r,b,swpd,free,buff,cache,si,so,bi,bo,in,cs,us,sy,id,wa,st\n"; while (1) { my @netstat = `netstat -na`; my $established = grep {/ESTABLISHED/} @netstat; my $listen = grep {/LISTEN/} @netstat; my $time_wait = grep {/TIME_WAIT/} @netstat; my @ps = `ps -e`; my $httpd = grep {/httpd/} @ps; my $cgi = grep {/\.cgi/} @ps; my @loadavg = split /\s/, `cat /proc/loadavg`; my $status; printf(qq{" % s",%s\n}, scalar localtime, join(',', $established, $listen, $time_wait, $httpd, $cgi, $status ? $status->{Threads_connected}{Value} : 0, $status ? $status->{Threads_running}{Value} : 0, @loadavg ) ); sleep 1; } 1; __END__ nice -15 perl watch_resources.pl