LVS
lvs-users
Google
 
Web LinuxVirtualServer.org

Re: lvs-users Digest, Vol 10, Issue 28

To: lvs-users@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: lvs-users Digest, Vol 10, Issue 28
From: Peter Nash <peter.nash@xxxxxxxxxxxxxxxxx>
Date: Tue, 18 Nov 2003 11:53:42 +0000
I'm using a perl script to pull LVS statistics from my directors into MRTG 
using the ucd-snmp-lvs module.  I'm sure this could be easily modified to 
work with RRDTool.  I'm no perl programmer so I'm sure there are better 
ways to do this but it's been working for me for the last 3 months.  Since 
my MRTG runs on a remote server (not the directors) using SNMP gives me 
the remote access I need.  The main problem to overcome was that the 
"instance number" of a particular "real service" is dependent on the order 
in which the services are added to the IPVS table.  If you are using 
something like ldirectord to add/remove services then this order can vary, 
so the script has to solve this problem.  I also had a few problems 
getting the ucd-snmp-lvs module to compile with net-snmp on my RH8 
directors but that was probably down to my lack of knowledge, I got there 
in the end!

The MRTG call to the script is as follows (director names, SNMP community 
and IP addresses are "dummies"):

Target[lvs-1]: `/home/agents/snmpipvsinfo.pl director1 communitystring 
123.123.123.123 80 bytes` + `/home/agents/snmpipvsinfo.pl director2 
communitystring 123.123.123.123 80 bytes`

This aggregates the results from both primary and backup director so it 
doesn't matter which one is "active".  The script returns zeros if the 
requested service is not currently in the LVS table on the target 
director.

Hope this is useful.

Regards,

Peter.


#!/usr/bin/perl

# 
============================================================================
# LVS Stats info script for mrtg
#
#    File:      snmpipvsinfo.pl
#
#    Author:    Peter Nash 17/06/03 
#
#    Version:   1.0
#
#    Purpose:   Uses SNMP to get the IPVS stats on an LVS director.
#               Needs to find the correct instance in the lvsServiceTable 
to
#               match a given virtual server (the instance number
#               depends on the order in which services are added).
#
#    Usage:     ./snmpipvsinfo.pl director community service_ip 
service_port [conn|packets|bytes]
#
#    Notes:     The instance number of a given service in the LVS table
#               depends on the order in which the services are added to 
the table.
#               For example, if a monitoring service such as ldirectord is 
used
#               to add/remove services to LVS then the instance number of 
a service
#               will be based on the polling sequence of ldirectord.  As 
services are
#               added or removed the instance numbers of existing services 
may
#               change.  Therefore this script has to determine the 
current SNMP
#               instance number for each LVS service every time it is run.
#               In addition to the director address and SNMP community if 
takes the
#               service IP and service PORT as parameters to identify a 
specific
#               service.  The last option determines the static to return.
#               Output is in MRTG compatible format.
# 
============================================================================

$director=shift;
$community=shift;
$service_ip=shift;
$service_port=shift;
$mode=shift;
$instance="";

# First we need to find the LVS instance for this service
# Get all service addresses
@addresses=`snmpwalk -v 2c -c $community -m LVS-MIB $director 
lvsServiceAddr`;
# Get all the service ports
@ports=`snmpwalk -v 2c -c $community -m LVS-MIB $director lvsServicePort`;

# Now for each service check to see if both address and port match
foreach $i (0 .. $#addresses) {
  ($address,)=splitnamevalue($addresses[$i]);
  ($port,$thisinstance)=splitnamevalue($ports[$i]);
  if ( $address =~ /$service_ip/ ) {
    if ( $port =~ /$service_port/ ) {
      $instance=$thisinstance;
    }
  }
}

# Now we've got the instance for the service get the requested data

if ( $instance eq "") {
  # If the instance does not exist return zero's (i.e. this may be the 
backup director)
  $param1="0: = 0";
  $param2="0: = 0";
} else {
  if ( $mode eq "conn" ) {
    $param1=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsConns.$instance`;
    $param2=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsConns.$instance`;
  } elsif ( $mode eq "packets" ) {
    $param1=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsInPkts.$instance`;
    $param2=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsOutPkts.$instance`;
  } elsif ( $mode eq "bytes" ) {
    $param1=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsInBytes.$instance`;
    $param2=`snmpget -v 2c -c $community -m LVS-MIB $director 
lvsServiceStatsOutBytes.$instance`;
  } else {
    $param1="";
    $param2="";
    print "Error in mode parameter";
  }
}

# Get the uptime
$uptime=`snmpwalk -v 2c -c $community $director sysUpTime.0`;
$uptime =~ s/.*\)\s+(\w+)/$1/;
($value1,)=splitnamevalue($param1);
($value2,)=splitnamevalue($param2);
print "$value1\n";
print "$value2\n";
print "$uptime";
print "LVS $mode\n";


sub splitnamevalue {
    $namevalue=shift;
    chomp($namevalue);
    ($index,$value)=split(/ = /, $namevalue);
    $index =~ s/.*\.([0-9]{1,6})$/$1/;
    $value =~ s/.*:\s+(\w+)/$1/;
    return $value,$index;
} 




> 
> > You have two main options here.
> > 
> > 1. Write something that quiries the kernel directly,
> >    libipvs should be able to help you here.
> > 
> > 2. Add a(nother) option to ipvsadm.
> > 
> > Personally I would go for 1 as it is probably quicker.
> > Though you could try 2 and see if you can twist Wensong's arm
> > into including it in the release.
> 
> I start to find my way using ucd-snmp-lvs-module-0.0.2, and an 
> adaptation of the check_traffic perl suites written for Nagios (we 
> are using nagios for all our monitoring. I know asyd@xxxxxxxxxx made
> it using this MIB, but with another monitoring tool at the end 
> (can't remember the name).
> 
> It is not working _yet_ but I will make it work. I think using snmp 
> is far less resource consuming. Maybe I'm wrong, but...
> 
> François. 
> 
> _______________________________________________
> lvs-users mailing list
> lvs-users@xxxxxxxxxxxxxxxxxxxxxx
> http://www.in-addr.de/mailman/listinfo/lvs-users
<Prev in Thread] Current Thread [Next in Thread>
  • Re: lvs-users Digest, Vol 10, Issue 28, Peter Nash <=