It is a two part script, a data grabber, and the cacti script.
Code: Select all
[cacti@argon bin]$ cat iptables-genstats.pl
#!/usr/bin/perl
use Data::Dumper;
my $iptables = '/sbin/iptables';
my @chains = qw(STATS_IN STATS_OUT);
# Gather data from chains.
foreach (@chains){
$data{$_} = `$iptables -L $_ -v -x -n`;
`$iptables -Z $_`;
}
foreach $chain (@chains){
@parts = split('\n',$data{$chain});
foreach (@parts){
$data = ~ /[\W+]?[0-9]+\W+([0-9]+)\W+[A-Z]+\W+[a-z]+\W+([0-9\.\/])+\W+[0-9\.\/]+\W+(.*)/;
my ($junk, $port) = split(":",$3);
next if (!$1);
if (!$port){
$port = 'none ';
}
$output{$port}{$chain} = $1;
}
}
for (keys(%output)){
foreach $chain (@chains){
$printtext = ($_);
chop($printtext);
next if (!$output{$_}{$chains[0]});
print "$printtext," . $output{$_}{$chains[0]} . "," . $output{$_}{$chains[1]} ."\n";
delete $output{$_};
}
}
Code: Select all
[root@argon bin]# ./iptables-genstats.pl
143,3417,9343
25,1291,1795
80,498,539
none,563,480
22,360,384
I then have a script for cacti:
Code: Select all
[root@argon scripts]# cat iptables.pl
#!/usr/bin/perl
use Data::Dumper;
$STAT_FILE = "/var/log/iptables.stats";
our $data;
sub process_stats{
$val = shift();
# Die unless we can locate the stats file
if (!open(STATS,$STAT_FILE)) {
die "Failed to open $STAT_FILE: $!\n";
}
while(<STATS>){
@incoming = split(',',$_);
chomp($incoming[2]);
$in{$incoming[0]} = {in=> $incoming[1], out=> $incoming[2]};
}
close(STATS);
}
if ($ARGV[0])
{
process_stats($ARGV[0]);
print "in: 0$in{$ARGV[0]}->{in} out: 0$in{$ARGV[0]}->{out}";
}
else
{
print "Usage: $0 Chain\n";
}
Code: Select all
[root@argon scripts]# ./iptables.pl 80
in: 01725 out: 02852[root@argon scripts]# ./iptables.pl none
in: 013416 out: 019357[root@argon scripts]# ./iptables.pl 200
in: 0 out: 0[root@argon scripts]#
So I made a new data template and such:
------------
------------
The RDD file looks empty( every database line is NAN), and so does the graph..
What am I doing wrong?
This also might have something to do with it:
[/img]
Code: Select all
[cacti@argon rra]$ php /var/www/shtml/monitoring/poller.php
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
OK u:0.00 s:0.00 r:1.01
ERROR: Not enough arguments
OK u:0.00 s:0.00 r:1.02
OK u:0.00 s:0.00 r:1.02
ERROR: Not enough arguments
OK u:0.00 s:0.00 r:1.02
OK u:0.00 s:0.00 r:1.02
Content-type: text/html
X-Powered-By: PHP/4.3.9