Skip to content

Instantly share code, notes, and snippets.

@mikeda
Last active December 12, 2015 08:59
Show Gist options
  • Select an option

  • Save mikeda/4747985 to your computer and use it in GitHub Desktop.

Select an option

Save mikeda/4747985 to your computer and use it in GitHub Desktop.
muninのSNMPプラグインをちょこちょこ書き換え 「1ポートで17回もポーリングしてたので、ifDescr、ifAlias、ifSpeedなどを取らないように」 「ErrorsとDiscardsを分離」 「SNMPのretry:1->0、timeout:5->2」 
#!/usr/bin/perl -w
# -*- cperl -*-
use strict;
use Munin::Plugin;
use Munin::Plugin::SNMP;
my $response;
my $iface;
my $alias;
### OID->インタフェース名の変換は機種ごとにベタ書き
if ($Munin::Plugin::me =~ /_if_(101(\d+))$/) {
$iface = $1;
$alias = "GigabitEthernet1/0/$2"
}elsif ($Munin::Plugin::me =~ /_if_(106(\d+))$/) {
$iface = $1;
$alias = "GigabitEthernet2/0/$2"
} else {
die "Could not determine interface number from ".$Munin::Plugin::me."\n";
}
my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryIn64Octets = "1.3.6.1.2.1.31.1.1.1.6.$iface";
my $ifEntryOut64Octets = "1.3.6.1.2.1.31.1.1.1.10.$iface";
my ($session, $error);
$session = Munin::Plugin::SNMP->session();
$session->retries(0);
$session->timeout(2);
if ($ARGV[0] and $ARGV[0] eq "config") {
my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();
print "host_name $host\n" unless $host eq 'localhost';
my $speed = 1_000_000_000;
my $warn = $speed/8;
print "graph_title Interface $alias traffic\n";
print "graph_order recv send\n";
print "graph_args --base 1000\n";
print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
print "graph_category traffic\n";
print "graph_info This graph shows traffic for the \"$alias\" network interface.\n";
print "send.info Bits sent/received by this interface.\n";
print "recv.label recv\n";
print "recv.type DERIVE\n";
print "recv.graph no\n";
print "recv.cdef recv,8,*\n";
print "recv.max $speed\n";
print "recv.min 0\n";
print "recv.warning ", (-$warn), "\n" if defined $warn;
print "send.label bps\n";
print "send.type DERIVE\n";
print "send.negative recv\n";
print "send.cdef send,8,*\n";
print "send.max $speed\n";
print "send.min 0\n";
print "send.warning $warn\n" if defined $warn;
exit 0;
}
$response = $session->get_single($ifEntryStatus);
if (!$response || $response == 2) {
print "recv.value U\n";
print "send.value U\n";
exit 0;
}
if (defined ($response = $session->get_single($ifEntryIn64Octets))) {
print "recv.value ", $response, "\n";
} else {
# No response...
print "recv.value U\n";
}
if (defined ($response = $session->get_single($ifEntryOut64Octets))) {
print "send.value ", $response, "\n";
} else {
# No response...
print "send.value U\n";
}
#!/usr/bin/perl -w
# -*- cperl -*-
use strict;
use Munin::Plugin;
use Munin::Plugin::SNMP;
my $response;
my $iface;
my $alias;
### OID->インタフェース名の変換は機種ごとにベタ書き
if ($Munin::Plugin::me =~ /_if_(101(\d+))$/) {
$iface = $1;
$alias = "GigabitEthernet1/0/$2"
}elsif ($Munin::Plugin::me =~ /_if_(106(\d+))$/) {
$iface = $1;
$alias = "GigabitEthernet2/0/$2"
} else {
die "Could not determine interface number from ".$Munin::Plugin::me."\n";
}
my $ifEntryStatus = "1.3.6.1.2.1.2.2.1.8.$iface";
my $ifEntryIn64Octets = "1.3.6.1.2.1.31.1.1.1.6.$iface";
my $ifEntryOut64Octets = "1.3.6.1.2.1.31.1.1.1.10.$iface";
my ($session, $error);
$session = Munin::Plugin::SNMP->session();
$session->retries(0);
$session->timeout(2);
if ($ARGV[0] and $ARGV[0] eq "config") {
my ($host,undef,$version) = Munin::Plugin::SNMP->config_session();
print "host_name $host\n" unless $host eq 'localhost';
my $speed = 1_000_000_000;
my $warn = $speed/8;
print "graph_title Interface $alias traffic\n";
print "graph_order recv send\n";
print "graph_args --base 1000\n";
print "graph_vlabel bits in (-) / out (+) per \${graph_period}\n";
print "graph_category traffic\n";
print "graph_info This graph shows traffic for the \"$alias\" network interface.\n";
print "send.info Bits sent/received by this interface.\n";
print "recv.label recv\n";
print "recv.type DERIVE\n";
print "recv.graph no\n";
print "recv.cdef recv,8,*\n";
print "recv.max $speed\n";
print "recv.min 0\n";
print "recv.warning ", (-$warn), "\n" if defined $warn;
print "send.label bps\n";
print "send.type DERIVE\n";
print "send.negative recv\n";
print "send.cdef send,8,*\n";
print "send.max $speed\n";
print "send.min 0\n";
print "send.warning $warn\n" if defined $warn;
exit 0;
}
if (defined ($response = $session->get_single($ifEntryStatus))) {
if ($response == 2) {
# Interface is down
print "recv.value U\n";
print "send.value U\n";
exit 0;
}
}
if (defined ($response = $session->get_single($ifEntryIn64Octets))) {
print "recv.value ", $response, "\n";
} else {
# No response...
print "recv.value U\n";
}
if (defined ($response = $session->get_single($ifEntryOut64Octets))) {
print "send.value ", $response, "\n";
} else {
# No response...
print "send.value U\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment