Monys

De wikilivois
Aller à la navigationAller à la recherche


Monys est une application de monitoring de serveurs /postes informatiques.

Installation

Me demander le script monys

Debuggage

#./monys.pl -v update 127.0.0.1
  • HOST-RESOURCES-MIB
#snmpwalk -v 2c -c public localhost .1.3.6.1.2.1.25 -Oqn

uptime netsnmp uptime

#snmpget -Oqn -v 2c -c public localhost .1.3.6.1.2.1.1.3.0

system uptime

#snmpget -Oqn -v 2c -c public localhost .1.3.6.1.2.1.25.1.1.0 

net

#.1.3.6.1.2.1.2.2.1

cpu (5.4)

#snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.25.3 | grep 768
#snmpwalk -v 2c -c public localhost 1.3.6.1.2.1.25.3.3.1.2

mem

1.3.6.1.2.1.25.2.3.1.3
HOST-RESOURCES-MIB::hrStorageDescr.1 = STRING: Physical memory
HOST-RESOURCES-MIB::hrStorageDescr.3 = STRING: Virtual memory
HOST-RESOURCES-MIB::hrStorageDescr.6 = STRING: Memory buffers
HOST-RESOURCES-MIB::hrStorageDescr.7 = STRING: Cached memory
HOST-RESOURCES-MIB::hrStorageDescr.8 = STRING: Shared memory
HOST-RESOURCES-MIB::hrStorageDescr.10 = STRING: Swap space

1.3.6.1.2.1.25.2.3.1.5
HOST-RESOURCES-MIB::hrStorageSize.1 = INTEGER: 1522820
HOST-RESOURCES-MIB::hrStorageSize.3 = INTEGER: 3530936
HOST-RESOURCES-MIB::hrStorageSize.6 = INTEGER: 60352
HOST-RESOURCES-MIB::hrStorageSize.7 = INTEGER: 126724
HOST-RESOURCES-MIB::hrStorageSize.8 = INTEGER: 0
HOST-RESOURCES-MIB::hrStorageSize.10 = INTEGER: 2008116

1.3.6.1.2.1.25.2.3.1.6
HOST-RESOURCES-MIB::hrStorageUsed.1 = INTEGER: 1468900
HOST-RESOURCES-MIB::hrStorageUsed.3 = INTEGER: 1824272
HOST-RESOURCES-MIB::hrStorageUsed.10 = INTEGER: 355372

disk

Ce sont les mêmes oid que pour la mémoire.
usage: 1.3.6.1.2.1.25.2.3.1.6.x
size: 1.3.6.1.2.1.25.2.3.1.5.x
unit: 1.3.6.1.2.1.25.2.3.1.4.x
name: 1.3.6.1.2.1.25.2.3.1.3.x

procs

 .1.3.6.1.2.1.25.4.2.1.1.x index
 .1.3.6.1.2.1.25.4.2.1.2.x name
 .1.3.6.1.2.1.25.4.2.1.3.1 0
 .1.3.6.1.2.1.25.4.2.1.4.1 name+
 .1.3.6.1.2.1.25.4.2.1.5.1 params
 .1.3.6.1.2.1.25.4.2.1.6.1 type (application)
 .1.3.6.1.2.1.25.4.2.1.7.1 status (runnable|running)
 .1.3.6.1.2.1.25.5.1.1.1.1 cpu
 .1.3.6.1.2.1.25.5.1.1.2.1 mem
  • UCD-SNMP-MIB: .1.3.6.1.4.1.2021

Load

.1.3.6.1.4.1.2021.10.1.3.1 laLoad.1
.1.3.6.1.4.1.2021.10.1.3.2 laLoad.2
.1.3.6.1.4.1.2021.10.1.3.3 laLoad.3

systemStats

.1.3.6.1.4.1.2021.11

sensors

.1.3.6.1.4.1.2021.13

ping
disman-ping : buggé dans net-snmp.
http://www.mail-archive.com/net-snmp-coders@lists.sourceforge.net/msg08977.html
http://www.oidview.com/mibs/0/DISMAN-PING-MIB.html


SNMP

http://net-snmp.sourceforge.net/docs/FAQ.html

http://forums.gentoo.org/viewtopic-t-40975-highlight-netsnmp+proc+snmp6.html

http://search.cpan.org/dist/Net-SNMP/lib/Net/SNMP.pm

http://www.mibdepot.com/cgi-bin/vendor_index.cgi?r=linux

snmp v3

http://www.net-snmp.org/docs/README.snmpv3.html

#net-snmp-config

#snmpd -H 

#snmpd -Dmib_init


<licode file=/etc/conf.d/snmpd>

  1. Initial (empty) options.

SNMPD_FLAGS="-V"

  1. Enable connection logging.

SNMPD_FLAGS="${SNMPD_FLAGS} -a" </licode>

#tail -f /var/log/net-snmpd.log

monys.conf

oid uptime      .1.3.6.1.2.1.25.1.1.0 #system uptime
oid cpu2        .1.3.6.1.2.1.25.3.3.1.2.768
oid cpu         .1.3.6.1.4.1.2021.50.3.1.2.8.99.112.117.115.116.97.116.115
oid load        .1.3.6.1.4.1.2021.10.1.3
oid mem         .1.3.6.1.2.1.25.2.3.1
oid disk        .1.3.6.1.2.1.25.2.3.1
oid proc        .1.3.6.1.2.1.25 #.4.2.1.2
#oid cproc      .1.3.6.1.2.1.25 #.5.1.1.1
#oid mproc      .1.3.6.1.2.1.25 #.5.1.1.2
oid net         .1.3.6.1.2.1.2.2.1
oid nf_INPUT     .1.3.6.1.4.1.2021.54.3.1.2.8.105.112.116.115.116.97.116.115
oid nf_OUTPUT    .1.3.6.1.4.1.2021.55.3.1.2.8.105.112.116.115.116.97.116.115
oid nf_FORWARD   .1.3.6.1.4.1.2021.56.3.1.2.8.105.112.116.115.116.97.116.115

Monys.pm

#!/usr/bin/perl -w
package Monys;
use Exporter;
use File::Temp qw/ tempfile tempdir /;
@ISA = qw ( Exporter );
@EXPORT = qw ( $DEBUG @colors %start $rrddir $pngdir $period %color @color);
use strict;

sub new
{
  my $class = shift;
  my $self= {};
  my ($hostname,$session,$href)=@_;

  #monys object values: hostname,session,oid,filename,rrd,png,name,vars
  $self->{hostname}=$hostname;
  $self->{session}=$session;
  $self->{oid}=$href->{oid};
  $self->{png}=$Monys::pngdir."/".$hostname."/".$Monys::period."/".$href->{file_png}.".png";
  $self->{name}=$href->{name};
  $self->{vars}=$href->{vars};

  print "$hostname: $self->{name}: $self->{oid}\n" if $Monys::DEBUG;
  bless $self, $class;
  return $self;
}

sub rrd_create
{
  my $self = shift;
  my ($rrd,@DS)=@_;
  print "CREATE $rrd\n" if $Monys::DEBUG;
  my (@RRA_LAST,@RRA_AVERAGE,@RRA_MIN,@RRA_MAX);

  #RRA:AVERAGE | MIN | MAX | LAST:xff:steps:rows
  #xff The xfiles factor defines what part of a consolidation interval may be made up from *UNKNOWN* data while the consolidated value is still regarded as known.
  #steps defines how many of these primary data points are used to build a consolidated data point which then goes into the archive.
  #rows defines how many generations of data values are kept in an RRA.
  push @RRA_LAST, "RRA:LAST:0.5:1:367"; #288*300=86400s in a day
  push @RRA_LAST, "RRA:LAST:0.5:7:288"; #288*7*300=7*86400s in a week
  push @RRA_LAST, "RRA:LAST:0.5:31:288";#288*31*300=31*86400s in a month
  push @RRA_LAST, "RRA:LAST:0.5:366:288";#288*366*300=366*86400s in a year

  push @RRA_AVERAGE, "RRA:AVERAGE:0.5:1:367";
  push @RRA_AVERAGE, "RRA:AVERAGE:0.5:7:288";
  push @RRA_AVERAGE, "RRA:AVERAGE:0.5:31:288";
  push @RRA_AVERAGE, "RRA:AVERAGE:0.5:366:288";

  push @RRA_MIN, "RRA:MIN:0.5:1:367";
  push @RRA_MIN, "RRA:MIN:0.5:7:288";
  push @RRA_MIN, "RRA:MIN:0.5:31:288";
  push @RRA_MIN, "RRA:MIN:0.5:366:288";

  push @RRA_MAX, "RRA:MAX:0.5:1:367";
  push @RRA_MAX, "RRA:MAX:0.5:7:288";
  push @RRA_MAX, "RRA:MAX:0.5:31:288";
  push @RRA_MAX, "RRA:MAX:0.5:366:288";

  RRDs::create ("$rrd",
  @DS,
  @RRA_LAST,
  @RRA_AVERAGE,
  @RRA_MIN,
  @RRA_MAX);
  my $ERR=RRDs::error;print "ERROR:  $ERR\n" if $ERR;
}

sub update
{
  my $self = shift;
  my ($rrd,$N)=@_;
  print "UPDATE $rrd $N\n" if $Monys::DEBUG;
  RRDs::update ($rrd, $N);
  my $ERR=RRDs::error;print "ERROR:  $ERR\n" if $ERR;
}

sub graph
{
  my $self = shift;
  print "GRAPH $self->{png}\n" if $Monys::DEBUG;
  my ($DEF,$CDEF,$AREA,$label,$title)=@_;
  my $DATE=`date '+%d/%m/%y %H\\:%M'`;chomp $DATE;
  push @$AREA, "COMMENT:                                                  last update\\: $DATE";

  my %start = ('day' => -86400, 'week' => -604800, 'month' => -2419200, 'year' => -31449600 );

  RRDs::graph ( "$self->{png}",
  "--vertical-label",$label,
  "--title", "$self->{hostname} - $title",
  "--start", $start{$Monys::period},
  "--height=150",
  "--width=480",
  @$DEF,
  @$CDEF,
  @$AREA);
  my $ERR=RRDs::error;print "ERROR:  $ERR\n" if $ERR;

  #foreach (@$DEF){print $_,"\n";}
  #foreach (@$CDEF){print $_,"\n";}
  #foreach (@$AREA){print $_,"\n";}
}

##gsize - Used with rrdgraph -> display xx.xx[kMG] values
sub gsize
{
  my $self = shift;
  my ($size)=@_;
  if    ( ($size/1073741824) >= 1 ) { return sprintf "%.2fG",($size/1073741824);}
  elsif ( ($size/1048576)    >= 1 ) { return sprintf "%.2fM",($size/1048576);}
  elsif ( ($size/1024)       >= 1 ) { return sprintf "%.2fk", ($size/1024);}
  else { return sprintf "%.2f";}
}

#dump & backup rrd file - restore -r
sub rrd_dump_restore
{
  my $self = shift;
  my ($rrd,$host)=@_;
  my ($fh, $rrddump) = tempfile("/tmp/rrddump.XXXXXX");

  print "rrdtool dump $rrd > $rrddump\n" if $Monys::DEBUG;
  `rrdtool dump $rrd > $rrddump`;
  rename $rrd,"$rrd.old";
  print "rrdtool restore $rrddump $rrd -r\n" if $Monys::DEBUG;
  `rrdtool restore $rrddump $rrd -r`;
   unlink "$rrddump";
}

exemple: uptime.pm

#!/usr/bin/perl -w
package Monys::uptime;
@ISA = qw ( Monys );

use strict;
use Net::SNMP;
use RRDs;

sub new
{
  my $class = shift;
  my ($hostname,$session,$href)=@_;
  my $self= Monys->new($hostname,$session,$href);
  bless $self, $class;
  return $self;
}

sub rrd_create
{
  my $self = shift;
  my ($rrd)=@_;
  my @DS;
  push @DS, "DS:upt:GAUGE:600:0:U";
  $self->SUPER::rrd_create($rrd,@DS);
}

sub update
{
  my $self=shift;
  my $N="N";
  my $OID = $self->{oid};
  my $result = $self->{session}->get_request(-varbindlist => [$OID]);
  my $time=0;

  if ($result->{$OID} =~ /([0-9]+) minutes/)    { $time += $1/1440;}
  if ($result->{$OID} =~ /([0-9]+) hour(s)?, ([0-9]+):/) { $time += $1/24 + $3/1440;}
  if ($result->{$OID} =~ /([0-9]+) day/) { $time += $1;}
  if ($result->{$OID} =~ /([0-9]+):([0-9]+):/)    { $time += $1/24 + $2/1440;}
  #if ($result->{$OID} =~ /([0-9]+) hour/){ $time += $1/24;}
  #elsif ($result->{$OID} =~ /([0-9]+) hour/){ $time += $1/24;}

  if (! $time){print STDERR "uptime = $result->{$OID}\n";}

  $N.=":$time";
  my $rrdfile=$Monys::rrddir."/".$self->{hostname}."/"."uptime.rrd";
  unless (-f $rrdfile){$self->rrd_create($rrdfile);}#create rrd if it doesn't exist
  $self->SUPER::update($rrdfile,$N);
}

sub graph
{
  my $self = shift;
  my (@DEF,@CDEF,@AREA);
  my $rrdfile=$Monys::rrddir."/".$self->{hostname}."/"."uptime.rrd";

  push @DEF, "DEF:dupt=$rrdfile:upt:LAST";
  push @AREA, "COMMENT:                  min    max    avg    last\\n";
  push @AREA, "AREA:dupt#$Monys::color{'uptime'}: ";
  push @AREA, "COMMENT:Uptime    ";
  push @AREA, "GPRINT:dupt:MIN:%3.2lf ";
  push @AREA, "GPRINT:dupt:MAX:%3.2lf ";
  push @AREA, "GPRINT:dupt:AVERAGE:%3.2lf ";
  push @AREA, "GPRINT:dupt:LAST:%3.2lf \\n";

  $self->SUPER::graph(\@DEF,\@CDEF,\@AREA,"Days","Uptime");
}