diaries, triumphs, failures, and rants
- All
- Animals
- Books
- Chess
- Cigars and the Man-Grill
- Collaboration
- Doctor Who
- General
- Internet
- iPhone
- Java
- LDAP
- mac
- oneLiners
- onThisDay
- slamd
- Star Trek
- Sun
- Travel
ds_monitor.pl
Here's ds_monitor.pl. This little Perl script prints out some interesting Directory Server operational statistics. I'll try to keep an updated version at my tools.
#! /usr/bin/perl -w
#
# terry.gardner@sun.com
#
# 20-JUL-2005
# 20-SEP-2005
# 21-SEP-2005
# 08-FEB-2008
#
# Parameter and variables
my ( $lines, $linesPerPage, $loadPerConnection );
#
# set up some default values
#
$port = 10389;
$root = "/ldap";
$instance = "instance-name";
$delay = 1;
$hostname = "localhost";
$pidFile = $root . "/logs/pid";
#
# parameters that cannot be modified by
# command line options
#
$searchBase= "cn=monitor";
sub displayUsageHints() {
print "ds_monitor.pl prints a tabular display of some directory server\n";
print " operational information.\n";
print "\n";
print "Usage:\n";
print "ds_monitor.pl [OPTIONS]\n";
print "\n";
print "[--hostname hostname] LDAP server hostname, default: $hostname\n";
print "[--port port] LDAP server port, default: $port\n";
print "[--instance instanceName] LDAP server instance, default: $instance\n";
print "[--delay delayBetweenIterations] delay between samples, default: $delay\n";
print "[--pidFile file ] file containing the PID of the running directory server, default: $pidFile\n";
print "[--help] display ds_monitor.pl command invocation hints\n";
}
#
# process command line options
#
$sn = 0;
for (@ARGV) {
if (/--port/) {
$port = $ARGV[++$sn];
++$sn;
} elsif (/--hostname/) {
$hostname = $ARGV[++$sn];
++$sn;
} elsif (/--root/) {
$root = $ARGV[++$sn];
++$sn;
} elsif (/--instance/) {
$instance = $ARGV[++$sn];
++$sn;
} elsif (/--delay/) {
$delay = $ARGV[++$sn];
++$sn;
} elsif (/--pidFile/) {
$pidFile = $ARGV[++$sn];
++$sn;
} elsif (/--help/) {
&displayUsageHints;
exit;
}
}
#
# check to see if the $pidFile can be opened
#
open(pidFile,$pidFile) or die "cannot open $pidFile: $!";
close(pidFile);
#
# read directory server pid, used
# later for process size
#
$pid = `cat $pidFile`; chomp $pid;
$scratchFile = "/tmp/" . "ds_monitor" . `date +%H%m%S`;
$lines = 0;
$linesPerPage = 30;
$lastCurrentConnections = 0;
$currentConnections = 0;
for (;;) {
`ldapsearch -s base -h $hostname -p $port -b $searchBase '(objectClass=*)' > $scratchFile`;
$size = `ps -p $pid -o vsz | tail -1`; chomp $size;
$uptime = `uptime`;
($junk,
$junk,
$junk,
$junk,
$junk,
$junk,
$junk,
$junk,
$junk,
$cpu) = split(" ",$uptime,9999);
$cpu =~ s/,//g;
open(scratchFile,$scratchFile) || die "Failed to open $scratchFile: $!";
while ()
{
chomp();
s/://;
($attribute,$value) = split(" ",$_,2);
if (/currentconnections/) {
$lastCurrentConnections = $currentConnections;
$currentConnections = $value;
} elsif (/totalconnections/) {
$totalConnections = $value;
} elsif (/readwaiters/) {
$readWaiters = $value;
} elsif (/request-que-backlog/) {
$requestQueueBacklog = $value;
} elsif (/connectionpeak/) {
$connectionPeak = $value;
}
$attribute = "";
}
close(scratchFile);
# Get the current time
($sec,$min,$hour,$junk,$junk,$junk,$junk,$junk,$junk) = localtime(time);
$diffConnections = $currentConnections - $lastCurrentConnections;
printf "%9.9s %2.2d:%2.2d:%2.2d size:%d la:%.2f tc:%d peak:%d cc:%d (%d) rq:%d rw:%d\n",
$hostname,
$hour,
$min,
$sec,
$size,
$cpu,
$totalConnections,
$connectionPeak,
$currentConnections,
$diffConnections,
$requestQueueBacklog,
$readWaiters;
sleep $delay;
}
Technorati Tags: dsee, ldap, perl, script, software, tools
Posted at 01:17PM May 01, 2008 by tgardner in LDAP | Comments[1]
Thursday May 01, 2008
very interesting, thanks for sharing.
I'll take it for a spin on 6 and 7 sometime this week.
Posted by arnaud on October 12, 2009 at 01:35 PM EDT #