Changeset 865

Show
Ignore:
Timestamp:
03/30/05 02:39:49 (7 years ago)
Author:
ilmari
Message:

Converted the cpuload, load, processes and users SNMP plugins to use
Munin::Plugin::SNMP.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • people/ilmari/modularisation-branch/node/node.d/snmp__cpuload.in

    r864 r865  
    6969 
    7070use strict; 
    71 use Net::SNMP; 
     71use Munin::Plugin::SNMP; 
    7272 
    7373my $DEBUG = 0; 
    74 my $MAXLABEL = 20; 
    75  
    76 my $host      = $ENV{host}      || undef; 
    77 my $port      = $ENV{port}      || 161; 
    78 my $community = $ENV{community} || "public"; 
    79 my $iface     = $ENV{interface} || undef; 
    80  
    81 my $response; 
     74my $hrProcessorLoad = '1.3.6.1.2.1.25.3.3.1.2'; 
    8275 
    8376if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    8477{ 
    85         print "require 1.3.6.1.2.1.25.3.3.1.2.1 [0-9]\n"; # Number 
     78        print "require $hrProcessorLoad.1 [0-9]\n"; # Number 
    8679        exit 0; 
    8780} 
    8881 
    89 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_users$/) 
    90 
    91         $host  = $1; 
    92         if ($host =~ /^([^:]+):(\d+)$/) 
    93         { 
    94                 $host = $1; 
    95                 $port = $2; 
    96         } 
    97 
    98 elsif (!defined($host)) 
    99 
    100         print "# Debug: $0 -- $1\n" if $DEBUG; 
    101         die "# Error: couldn't understand what I'm supposed to monitor."; 
    102 
    103  
    104 my ($session, $error) = Net::SNMP->session( 
    105                 -hostname  => $host, 
    106                 -community => $community, 
    107                 -port      => $port 
    108         ); 
     82my ($session, $error) = Munin::Plugin::SNMP->session(); 
    10983 
    11084if (!defined ($session)) 
     
    11589if (defined $ARGV[0] and $ARGV[0] eq "config") 
    11690{ 
    117         print "host_name $host\n"; 
     91        print "host_name ", $session->hostname(), "\n"; 
    11892        print "graph_title CPU utilisation 
    11993graph_args --base 1000 -l 0 -u 100 
     
    130104} 
    131105 
    132 print "cpu.value ", &get_single ($session, "1.3.6.1.2.1.25.3.3.1.2.1"), "\n"; 
    133  
    134 sub get_single 
    135 
    136         my $handle = shift; 
    137         my $oid    = shift; 
    138  
    139         print "# Getting single $oid...\n" if $DEBUG; 
    140  
    141         $response = $handle->get_request ($oid); 
    142  
    143         if (!defined $response->{$oid}) 
    144         { 
    145             return undef; 
    146         } 
    147         else 
    148         { 
    149             return $response->{$oid}; 
    150         } 
    151 
    152  
     106print "cpu.value ", $session->get_single("$hrProcessorLoad.1"), "\n"; 
  • people/ilmari/modularisation-branch/node/node.d/snmp__load.in

    r864 r865  
    6666 
    6767use strict; 
    68 use Net::SNMP; 
     68use Munin::Plugin::SNMP; 
    6969 
    7070my $DEBUG = 0; 
    71 my $MAXLABEL = 20; 
    72  
    73 my $host      = $ENV{host}      || undef; 
    74 my $port      = $ENV{port}      || 161; 
    75 my $community = $ENV{community} || "public"; 
    76 my $iface     = $ENV{interface} || undef; 
    77  
    78 my $response; 
     71my $laLoad = "1.3.6.1.4.1.2021.10.1.3"; 
    7972 
    8073if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    8174{ 
    82         print "require 1.3.6.1.4.1.2021.10.1.3.2 [0-9]\n"; # Number 
     75        print "require $laLoad.2 [0-9]\n"; 
    8376        exit 0; 
    8477} 
    8578 
    86 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_load$/) 
    87 
    88         $host  = $1; 
    89         if ($host =~ /^([^:]+):(\d+)$/) 
    90         { 
    91                 $host = $1; 
    92                 $port = $2; 
    93         } 
    94 
    95 elsif (!defined($host)) 
    96 
    97         print "# Debug: $0 -- $1\n" if $DEBUG; 
    98         die "# Error: couldn't understand what I'm supposed to monitor."; 
    99 
    100  
    101 my ($session, $error) = Net::SNMP->session( 
    102                 -hostname  => $host, 
    103                 -community => $community, 
    104                 -port      => $port 
    105         ); 
     79my ($session, $error) = Munin::Plugin::SNMP->session(); 
    10680 
    10781if (!defined ($session)) 
     
    11286if (defined $ARGV[0] and $ARGV[0] eq "config") 
    11387{ 
    114         print "host_name $host\n"; 
     88        print 'host_name ', $session->hostname(), "\n"; 
    11589        print "graph_title Load average 
    11690graph_args --base 1000 -l 0  
     
    126100} 
    127101 
    128 print "load.value ", &get_single ($session, "1.3.6.1.4.1.2021.10.1.3.2"), "\n"; 
    129  
    130 sub get_single 
    131 
    132         my $handle = shift; 
    133         my $oid    = shift; 
    134  
    135         print "# Getting single $oid...\n" if $DEBUG; 
    136  
    137         $response = $handle->get_request ($oid); 
    138  
    139         if (!defined $response->{$oid}) 
    140         { 
    141             return undef; 
    142         } 
    143         else 
    144         { 
    145             return $response->{$oid}; 
    146         } 
    147 
    148  
     102print "load.value ", $session->get_single("$laLoad.2"), "\n"; 
  • people/ilmari/modularisation-branch/node/node.d/snmp__processes.in

    r864 r865  
    6363 
    6464use strict; 
    65 use Net::SNMP; 
     65use Munin::Plugin::SNMP; 
    6666 
    6767my $DEBUG = 0; 
    68 my $MAXLABEL = 20; 
    69  
    70 my $host      = $ENV{host}      || undef; 
    71 my $port      = $ENV{port}      || 161; 
    72 my $community = $ENV{community} || "public"; 
    73 my $iface     = $ENV{interface} || undef; 
    74  
    75 my $response; 
     68my $hrSystemProcesses = '1.3.6.1.2.1.25.1.6'; 
    7669 
    7770if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    7871{ 
    79         print "require 1.3.6.1.2.1.25.1.6.0 [0-9]\n"; # Number 
     72        print "require $hrSystemProcesses.0 [0-9]\n"; # Number 
    8073        exit 0; 
    8174} 
    8275 
    83 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_processes$/) 
    84 
    85         $host  = $1; 
    86         if ($host =~ /^([^:]+):(\d+)$/) 
    87         { 
    88                 $host = $1; 
    89                 $port = $2; 
    90         } 
    91 
    92 elsif (!defined($host)) 
    93 
    94         print "# Debug: $0 -- $1\n" if $DEBUG; 
    95         die "# Error: couldn't understand what I'm supposed to monitor."; 
    96 
    97  
    98 my ($session, $error) = Net::SNMP->session( 
    99                 -hostname  => $host, 
    100                 -community => $community, 
    101                 -port      => $port 
    102         ); 
     76my ($session, $error) = Munin::Plugin::SNMP->session(); 
    10377 
    10478if (!defined ($session)) 
     
    10983if (defined $ARGV[0] and $ARGV[0] eq "config") 
    11084{ 
    111         print "host_name $host\n"; 
     85        print "host_name ", $session->hostname(), "\n"; 
    11286        print "graph_title Number of Processes 
    11387graph_args --base 1000 -l 0  
     
    12397} 
    12498 
    125 print "processes.value ", &get_single ($session, "1.3.6.1.2.1.25.1.6.0"), "\n"; 
    126  
    127 sub get_single 
    128 
    129         my $handle = shift; 
    130         my $oid    = shift; 
    131  
    132         print "# Getting single $oid...\n" if $DEBUG; 
    133  
    134         $response = $handle->get_request ($oid); 
    135  
    136         if (!defined $response->{$oid}) 
    137         { 
    138             return undef; 
    139         } 
    140         else 
    141         { 
    142             return $response->{$oid}; 
    143         } 
    144 
    145  
     99print "processes.value ", $session->get_single("$hrSystemProcesses.0"), "\n"; 
  • people/ilmari/modularisation-branch/node/node.d/snmp__users.in

    r864 r865  
    6666 
    6767use strict; 
    68 use Net::SNMP; 
     68use Munin::Plugin::SNMP; 
    6969 
    7070my $DEBUG = 0; 
    71 my $MAXLABEL = 20; 
    72  
    73 my $host      = $ENV{host}      || undef; 
    74 my $port      = $ENV{port}      || 161; 
    75 my $community = $ENV{community} || "public"; 
    76 my $iface     = $ENV{interface} || undef; 
    77  
    78 my $response; 
     71my $hrSystemNumUsers = '1.3.6.1.2.1.25.1.5'; 
    7972 
    8073if (defined $ARGV[0] and $ARGV[0] eq "snmpconf") 
    8174{ 
    82         print "require 1.3.6.1.2.1.25.1.5.0 [0-9]\n"; # Number 
     75        print "require $hrSystemNumUsers.0 [0-9]\n"; # Number 
    8376        exit 0; 
    8477} 
    8578 
    86 if ($0 =~ /^(?:|.*\/)snmp_([^_]+)_users$/) 
    87 
    88         $host  = $1; 
    89         if ($host =~ /^([^:]+):(\d+)$/) 
    90         { 
    91                 $host = $1; 
    92                 $port = $2; 
    93         } 
    94 
    95 elsif (!defined($host)) 
    96 
    97         print "# Debug: $0 -- $1\n" if $DEBUG; 
    98         die "# Error: couldn't understand what I'm supposed to monitor."; 
    99 
    100  
    101 my ($session, $error) = Net::SNMP->session( 
    102                 -hostname  => $host, 
    103                 -community => $community, 
    104                 -port      => $port 
    105         ); 
     79my ($session, $error) = Munin::Plugin::SNMP->session(); 
    10680 
    10781if (!defined ($session)) 
     
    11286if (defined $ARGV[0] and $ARGV[0] eq "config") 
    11387{ 
    114         print "host_name $host\n"; 
     88        print "host_name ", $session->hostname(), "\n"; 
    11589        print "graph_title Number of users 
    11690graph_args --base 1000 -l 0  
     
    127101} 
    128102 
    129 print "users.value ", &get_single ($session, "1.3.6.1.2.1.25.1.5.0"), "\n"; 
    130  
    131 sub get_single 
    132 
    133         my $handle = shift; 
    134         my $oid    = shift; 
    135  
    136         print "# Getting single $oid...\n" if $DEBUG; 
    137  
    138         $response = $handle->get_request ($oid); 
    139  
    140         if (!defined $response->{$oid}) 
    141         { 
    142             return undef; 
    143         } 
    144         else 
    145         { 
    146             return $response->{$oid}; 
    147         } 
    148 
    149  
     103print "users.value ", $session->get_single("$hrSystemNumUsers.0"), "\n";