Revision 1 as of 2009-09-18 20:36:07

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, in particular OpenLDAP.

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"