root / plugins / router / snmp__mikrotik_ram @ 8a52ef23
Historique | Voir | Annoter | Télécharger (2,87 ko)
| 1 |
#!/usr/bin/perl -w |
|---|---|
| 2 |
# |
| 3 |
# Copyright (C) 2019 Alejandro Suarez (teconecta.es) |
| 4 |
# |
| 5 |
# Munin plugin to monitor Mikrotik routers RAM utilization. |
| 6 |
# Based on snmp__if_ plugin. |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or |
| 9 |
# modify it under the terms of the GNU General Public License |
| 10 |
# as published by the Free Software Foundation; version 2 dated June, |
| 11 |
# 1991. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 21 |
|
| 22 |
|
| 23 |
#%# family=snmpauto |
| 24 |
#%# capabilities=snmpconf |
| 25 |
|
| 26 |
use strict; |
| 27 |
use Net::SNMP; |
| 28 |
|
| 29 |
my $DEBUG = 0; |
| 30 |
|
| 31 |
my $host = $ENV{host} || undef;
|
| 32 |
my $port = $ENV{port} || 161;
|
| 33 |
my $community = $ENV{community} || "public";
|
| 34 |
|
| 35 |
my $response; |
| 36 |
|
| 37 |
if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") |
| 38 |
{
|
| 39 |
print "require 1.3.6.1.2.1.25.2.3.1.5.65536 \n"; |
| 40 |
exit 0; |
| 41 |
} |
| 42 |
|
| 43 |
if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_mikrotik_ram$/) |
| 44 |
{
|
| 45 |
$host = $1; |
| 46 |
if ($host =~ /^([^:]+):(\d+)$/) |
| 47 |
{
|
| 48 |
$host = $1; |
| 49 |
$port = $2; |
| 50 |
} |
| 51 |
} |
| 52 |
elsif (!defined($host)) |
| 53 |
{
|
| 54 |
print "# Debug: $0 -- $1\n" if $DEBUG; |
| 55 |
die "# Error: couldn't understand what I'm supposed to monitor."; |
| 56 |
} |
| 57 |
|
| 58 |
my $sysRAMUsage = "1.3.6.1.2.1.25.2.3.1.6.65536"; |
| 59 |
my $sysRAMTotal = "1.3.6.1.2.1.25.2.3.1.5.65536"; |
| 60 |
|
| 61 |
my ($session, $error) = Net::SNMP->session( |
| 62 |
-hostname => $host, |
| 63 |
-community => $community, |
| 64 |
-port => $port |
| 65 |
); |
| 66 |
|
| 67 |
|
| 68 |
if (!defined ($session)) |
| 69 |
{
|
| 70 |
die "Croaking: $error"; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
if ($ARGV[0] and $ARGV[0] eq "config") |
| 75 |
{
|
| 76 |
print "host_name $host\n"; |
| 77 |
if (!defined ($response = $session->get_request($sysRAMTotal))) |
| 78 |
{
|
| 79 |
die "Croaking: " . $session->error(); |
| 80 |
} |
| 81 |
# print "graph_args --base 1000 -r --lower-limit 0 --upper-limit 100\n"; |
| 82 |
print "graph_args --base 1024 -l 0 --vertical-label Bytes --upper-limit " . ($response->{$sysRAMTotal} * 1024) . "\n";
|
| 83 |
print "graph_title RAM usage\n"; |
| 84 |
print "graph_category system\n"; |
| 85 |
print "graph_info This graph shows the router's memory usage.\n"; |
| 86 |
print "graph_order Total Used\n"; |
| 87 |
print "graph_vlabel bytes\n"; |
| 88 |
print "sysRAMTotal.label Total Memory\n"; |
| 89 |
print "sysRAMTotal.draw AREA\n"; |
| 90 |
print "sysRAMUsage.label Used Memory\n"; |
| 91 |
print "sysRAMUsage.draw AREA\n"; |
| 92 |
exit 0; |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
if (defined ($response = $session->get_request(-varbindlist => [$sysRAMUsage, $sysRAMTotal]))) |
| 97 |
{
|
| 98 |
print "sysRAMUsage.value ", $response->{$sysRAMUsage}*1024, "\n";
|
| 99 |
print "sysRAMTotal.value ", $response->{$sysRAMTotal}*1024, "\n";
|
| 100 |
} |
| 101 |
else |
| 102 |
{
|
| 103 |
print "sysRAMUsage.value U\n"; |
| 104 |
} |
| 105 |
|
| 106 |
# vim:syntax=perl |
