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"

Disk I/O

Here is a script for graphing disk reads in kbytes/s:

# CHANGE THIS TO WHATEVER DEVICE YOU WANT TO MONITOR
device="sda"

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

# sample output:
# Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
# sda               8.47        64.74       316.30     107266     524081
data=$(iostat -kd "$device" | grep "^$device" | awk '{print $2}')

echo $data

To graph disk writes instead, just output the third column instead of the second one as was done in the previous script:

# CHANGE THIS TO WHATEVER DEVICE YOU WANT TO MONITOR
device="sda"

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

# sample output:
# Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
# sda               8.47        64.74       316.30     107266     524081
data=$(iostat -kd "$device" | grep "^$device" | awk '{print $3}')

echo $data

lm-sensors

Please install the lm-sensors package first and then run the sensors-detect configuration script to get setup with this tool. The sample custom graph scripts below basically just get a different output from sensors for each graph. This output may be different in your case, so please adjust accordingly. It's best to just run sensors once on each system to see what the output looks like.

Also keep in mind that the actual numbers that sensors provides are not always very accurate and usually need some adjustments in the configuration file, like different multipliers or offsets. Consult its documentation for more information.

Power fan speed

if [ -z "$(which sensors)" ]; then
    echo "ERROR, install and configure lm-sensors"
    exit 1
fi

sensors -u | awk '/fan3_input/ {print $2}'

RSS memory usage of a single process

Let's say we need to graph the RSS memory usage of the landscape-broker process:

# USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND

ps axwu|grep /usr/bin/landscape-|grep -v grep |grep landscape-broker| awk '{print $6}'

To graph VSZ instead, just replace $6 with $5.

CustomGraphs/Examples (last edited 2010-11-23 09:50:37 by ahasenack)