Revision 7 as of 2009-09-18 21:07:42

Clear message

Examples for Custom Graphs

Here in this page we collect a few sample scripts to be used with Custom Graphs.

  • /!\ NOTE: some of these scripts use a fixed filename in /tmp, which is a bad idea from a security point of view. When using them in production, please modify the script so they use a private directory for their temporary data.

    /!\ NOTE: DO NOT use root to run these scripts: that is not needed at all! Please use an unprivileged user like nobody.

OpenLDAP

Some sample scripts that plot LDAP related information. Most rely on the server being a recent enough version of OpenLDAP (the version tested was 2.4.18) and with the cn=monitor backend enabled. To learn more about this backend please consult the slapd-monitor(5) manpage.

The scripts consider that access to the information at cn=monitor is restricted and attempts to bind as an example user. Please adjust the user and password to your needs. If anonymous searches are allowed, then just drop the -D "$binddn" -w "$bindpw" parameters from the ldapsearch command line.

LDAP binds/s

This script counts the number of successful bind operations that were completed within 5min and calculates the per second average. If your server is very lightly used, you will get very low numbers here. You may divide by 60 then (one minute) instead of 5 to get the number of binds per minute.

# YOU NEED TO ADJUST THESE TWO
binddn="uid=ldap monitor,ou=system accounts,dc=example,dc=org"
bindpw="ldapmonitor"

basedn="cn=Bind,cn=Operations,cn=Monitor"
attr="monitorOpCompleted"
# 5 minutes
interval=$((5 * 60))
oldfile=/tmp/old-binds.dat

function calc() {
    echo "scale=2; $1" | bc
}

if [ -z "$(which ldapsearch)" ]; then
    echo "ERROR, please install ldap-utils"
    exit 1
fi

if [ -z "$(which bc)" ]; then
    echo "ERROR, please install bc"
    exit 1
fi


binds=$(ldapsearch -x -D "$binddn" -w "$bindpw" -b "$basedn" "$attr" | grep -E ^"$attr" | awk '{print $2}')
if [ -z "$binds" ]; then
    echo "ERROR, no binds returned"
    exit 1
fi

[ -f "$oldfile" ] && old=`cat $oldfile`

curr="$binds"

if [ -z "$old" ]; then
    old=$curr
fi
echo $curr > $oldfile
calc "($curr-$old)/$interval"

LDAP searches/s

This script counts the number of search operations that were completed within 5min and calculates the per second average. If your server is very lightly used, you will get very low numbers here. You may divide by 60 then (one minute) instead of 5 to get the number of searches per minute.

# YOU NEED TO ADJUST THESE TWO
binddn="uid=ldap monitor,ou=system accounts,dc=example,dc=org"
bindpw="ldapmonitor"

basedn="cn=Search,cn=Operations,cn=Monitor"
attr="monitorOpCompleted"
# 5 minutes
interval=$((5 * 60))
oldfile=/tmp/old-searches.dat

function calc() {
    echo "scale=2; $1" | bc
}

if [ -z "$(which ldapsearch)" ]; then
    echo "ERROR, please install ldap-utils"
    exit 1
fi

if [ -z "$(which bc)" ]; then
    echo "ERROR, please install bc"
    exit 1
fi


binds=$(ldapsearch -x -D "$binddn" -w "$bindpw" -b "$basedn" "$attr" | grep -E ^"$attr" | awk '{print $2}')
if [ -z "$binds" ]; then
    echo "ERROR, no binds returned"
    exit 1
fi

[ -f "$oldfile" ] && old=`cat $oldfile`

curr="$binds"

if [ -z "$old" ]; then
    old=$curr
fi
echo $curr > $oldfile
calc "($curr-$old)/$interval"

LDAP active connections

Here we count the number of active connections to the slapd service. Note this script will output the number of connections it reads at the time it is run.

# YOU NEED TO ADJUST THESE TWO
binddn="uid=ldap monitor,ou=system accounts,dc=example,dc=org"
bindpw="ldapmonitor"

basedn="cn=Current,cn=Connections,cn=Monitor"
attr="monitorCounter"

if [ -z "$(which ldapsearch)" ]; then
    echo "ERROR, please install ldap-utils"
    exit 1
fi

data=$(ldapsearch -x -D "$binddn" -w "$bindpw" -b "$basedn" "$attr" | grep -E ^"$attr" | awk '{print $2}')
if [ -z "$data" ]; then
    echo "ERROR, no data returned"
    exit 1
fi

echo "$data"

slapd uptime

This script outputs the uptime of the OpenLDAP service, in hours.

# YOU NEED TO ADJUST THESE TWO
binddn="uid=ldap monitor,ou=system accounts,dc=example,dc=org"
bindpw="ldapmonitor"

basedn="cn=Current,cn=Connections,cn=Monitor"
attr="monitorCounter"

if [ -z "$(which ldapsearch)" ]; then
    echo "ERROR, please install ldap-utils"
    exit 1
fi

data=$(ldapsearch -x -D "$binddn" -w "$bindpw" -b "$basedn" "$attr" | grep -E ^"$attr" | awk '{print $2}')
if [ -z "$data" ]; then
    echo "ERROR, no data returned"
    exit 1
fi

echo "$data"