73 lines
1.9 KiB
Perl
Executable file
73 lines
1.9 KiB
Perl
Executable file
#!/usr/bin/perl -w
|
|
#
|
|
# Plugin to monitor individual interrupts
|
|
#
|
|
# $Log$
|
|
# Revision 1.7.2.1 2005/02/24 17:33:22 jimmyo
|
|
# linux/irqstats should no longer fail on some systems (Deb#296452).
|
|
#
|
|
#%# family=auto
|
|
#%# capabilities=autoconf
|
|
use strict;
|
|
|
|
if (defined $ARGV[0] && $ARGV[0] eq 'autoconf') {
|
|
if(-e '/usr/bin/netstat') {
|
|
print "yes\n";
|
|
exit(0);
|
|
} else {
|
|
print "no\n";
|
|
exit(1);
|
|
}
|
|
}
|
|
open my $in, "/usr/bin/netstat -bin |"
|
|
or die "Can't run netstat -bin: $!\n";
|
|
|
|
my @ifstats;
|
|
|
|
while (my $line = <$in>) {
|
|
if ($line =~ /<Link>/) {
|
|
my @values = split(' ', $line);
|
|
my $ifname = $values[0];
|
|
$ifname =~ s/\*/_/g;
|
|
my ($ibytes, $obytes);
|
|
if ($values[3] =~ /\:/) {
|
|
$ibytes = $values[4];
|
|
$obytes = $values[5];
|
|
} else {
|
|
$ibytes = $values[3];
|
|
$obytes = $values[4];
|
|
}
|
|
push @ifstats, {
|
|
ifname => $ifname,
|
|
ibytes => $ibytes,
|
|
obytes => $obytes
|
|
};
|
|
}
|
|
}
|
|
close $in;
|
|
|
|
if (defined $ARGV[0] && $ARGV[0] eq 'config') {
|
|
print "graph_title interface traffic (bytes) \n";
|
|
print <<EOM;
|
|
graph_args --base 1000
|
|
graph_vlabel bytes in(-) / out(+) per \${graph_period}
|
|
graph_category network
|
|
EOM
|
|
print join(' ', 'graph_order', map {$_->{ifname}."_in ".$_->{ifname}."_out"} @ifstats), "\n";
|
|
for my $if (@ifstats) {
|
|
print $if->{ifname}, '_in.label ', $if->{ifname}, "\n";
|
|
print $if->{ifname}, '_out.label ', $if->{ifname}, "\n";
|
|
print $if->{ifname}, '_in.info bytes in on: ', $if->{ifname}, "\n";
|
|
print $if->{ifname}, '_out.info bytes out on: ', $if->{ifname}, "\n";
|
|
print $if->{ifname}, "_in.type COUNTER\n";
|
|
print $if->{ifname}, "_out.type COUNTER\n";
|
|
print $if->{ifname}, "_in.min 0\n";
|
|
print $if->{ifname}, "_out.min 0\n";
|
|
print $if->{ifname}, "_in.graph no\n";
|
|
print $if->{ifname}, "_out.negative ", $if->{ifname}, "_in\n";
|
|
}
|
|
} else {
|
|
print $_->{ifname}, '_in.value ', $_->{ibytes}, "\n" for @ifstats;
|
|
print $_->{ifname}, '_out.value ', $_->{obytes}, "\n" for @ifstats;
|
|
}
|
|
|