Revision 2 as of 2009-09-18 20:38:14

Clear message

Examples for Custom Graphs

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

LDAP

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.

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

# 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

# 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

# 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

# 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"