[mrtg] Re: slapd monitoring

Dan Rich drich at employees.org
Wed Mar 7 23:35:45 MET 2001


On Wed, 7 Mar 2001, Sanjeet T wrote:

> Any clues how to monitor slapd on a LDAP server using
> Mrtg ?

If you are using a version of slapd that supports the monitor query, you
can use the following script and cfg file entries (replace
ldap.lapseofthought.com with your LDAP server hostname):

##
## LDAP stats
##
Target[morpheus.lapseofthought.com_ldap]: `mrtg-ldap-probe.pl -h ldap.lapseofthought.com`
Title[morpheus.lapseofthought.com_ldap]: LDAP statistics -- ldap.lapseofthought.com
PageTop[morpheus.lapseofthought.com_ldap]: <H1>LDAP statistics -- ldap.lapseofthought.com</H1>
Options[morpheus.lapseofthought.com_ldap]: perminute
MaxBytes[morpheus.lapseofthought.com_ldap]: 100000
YLegend[morpheus.lapseofthought.com_ldap]: #/min
ShortLegend[morpheus.lapseofthought.com_ldap]: #/min
Legend1[morpheus.lapseofthought.com_ldap]: LDAP connections
Legend2[morpheus.lapseofthought.com_ldap]: entries returned
LegendI[morpheus.lapseofthought.com_ldap]: connections:
LegendO[morpheus.lapseofthought.com_ldap]: entries:


mrtg-ldap-probe.pl:

#!/usr/bin/perl

# Norbert Klasen <norbert.klasen at directory.dfn.de>
# License: GPL
#
# 20001221 converted to Net::LDAP - drich at employees.org
# 20000809 umich ldap 3.3 reports time without century
# 20000807 initial version
#
# requires perldap (http://www.perldap.org)

use Getopt::Std;                        # To parse comonthand line
arguments.
use Time::Local;
use Net::LDAP;

use strict;
no strict "vars";


#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "mrtg-ldap-probe";
$USAGE  = "$APPNAM -h host -p port -D bind -w pswd";


#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('b:h:D:p:w:'))
{
   print "usage: $APPNAM $USAGE\n";
   exit;
}

$opt_h = "ldap.lapseofthought.com" unless($opt_h);
$opt_p = "389" unless ($opt_p);


#################################################################################
# open connection to server and read counters
#
$conn = new Net::LDAP($opt_h);
#die "Could't connect to LDAP server $opt_h" unless $conn;

$conn->bind ( dn => "$opt_D",
              password => "$opt_w");


my $mesg = $conn->search( base => "cn=monitor",
                          scope => "base",
                          filter => "objectclass=*" );
#$entry = $conn->search("cn=monitor", "base", "(objectclass=*)", 0,
("version","totalconnections","entriessent","currenttime", "starttime"));

$mesg->code && die $mesg->error;

foreach $entry ($mesg->all_entries) {

#$conn->printError() if $conn->getErrorCode();

print (($entry->get('totalconnections'))[0]);
print "\n";
print (($entry->get('entriessent'))[0]);
print "\n";

#some other statistics, change attributes in search string accordingly
#print (($entry->get("opscompleted"))[0]),"\n";
#print (($entry->get("bytessent"))[0]),"\n";

#absolute values, specify "gauge" in MRTG config
#print $entry->{currentconnections}[0],"\n";
#print $entry->{threads}[0],"\n";

#################################################################################
# calculate server uptime 
#
print (($entry->get('starttime'))[0]);
print "\n";
($year,$month,$day,$hour,$min,$sec) = (($entry->get('starttime'))[0] =~
/^(\d{2,4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})Z/);
if ($year > 1900) { $year -= 1900; }
$elapsed = time - timegm($sec,$min,$hour,$day,$month-1,$year);
$seconds =  $elapsed % 60;
$elapsed = ($elapsed - $seconds) / 60;
$minutes =  $elapsed % 60;
$elapsed = ($elapsed - $minutes) / 60;
$hours   =  $elapsed % 24;
$days    = ($elapsed - $hours)   / 24;
printf "%d days, %d:%02d:%02d\n", $days, $hours,$minutes,$seconds;

print (($entry->get('version'))[0]);
print " on $opt_h, port $opt_p (<a
href=\"ldap://$opt_h:$opt_p/??base?objectclass=*\">rootDSE</a>, <a
href=\"ldap://$opt_h:$opt_p/cn=monitor??base?objectclass=*\">Monitor</a>)\n";
}


#################################################################################
# Close the connection.
#
#$conn->close();



-- 
Dan Rich <drich at employees.org> |   http://www.employees.org/~drich/
                               | "Danger, you haven't seen the last of me!" 
                               |   "No, but the first of you turns my stomach!"
                               |          -- The Firesign Theatre's Nick Danger


--
Unsubscribe mailto:mrtg-request at list.ee.ethz.ch?subject=unsubscribe
Archive     http://www.ee.ethz.ch/~slist/mrtg
FAQ         http://faq.mrtg.org    Homepage     http://www.mrtg.org
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the mrtg mailing list