Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- #
- # script for RRDtool to collect statistics abount active connections
- #
- $step=60;
- $base="/Serv/rrd-scripts/sysinfo/db/netstat.rrd";
- $path=path_to_img
- if ($ARGV[0] eq init){
- system("rrdtool create $base --step $step".
- " DS:established:GAUGE:200:0:U".
- " RRA:AVERAGE:0.5:1:1440". # 1440 samples every minute - day
- " RRA:AVERAGE:0.5:5:2016"); # 2016 samples every 5 minute - week
- exit;
- }
- if ($ARGV[0] eq update){
- # load avg
- open LA,"netstat -tns |";
- $est=getestablished();
- $n=time;
- system("rrdtool update $base $n:$est");
- #system("echo update $base $n:$est");
- exit;
- }
- if ($ARGV[0] eq day){
- system("rrdtool graph $path/day-established.gif -t \"Established Connections\" ".
- "DEF:established=$base:established:AVERAGE ".
- "AREA:established#ff0000:\"Established\" ".
- "-h 200 ");
- exit;
- }
- if($ARGV[0] eq remove){
- unlink $base;
- }
- if($ARGV[0] eq descr){
- print("Number of ESTABLISHED Connections:$path/day-established.gif\n");
- }
- sub getestablished()
- {
- $est=0;
- while( <LA>){
- #print $_;
- $established='(\d*)\sconnections\sestablished';
- if( $_ =~ $established ){
- $est+=$1;
- return $est;
- }
- }
- close LA;
- }
Advertisement
Add Comment
Please, Sign In to add comment