[collectd] Problems with exec script

Christian Dervaric christian.dervaric at googlemail.com
Wed Oct 19 13:22:14 CEST 2011


Hi,

I wrote a small script for the exec plugin to measure the download time 
of some image from different media servers. I added the script to my 
exec config, and it looks like its executed, when I add logging, 
everything looks fine. But for some reason the corresponding folders in 
the rrd output folder are never created and the results of the script 
therefore never got stored. I have another script for checking disk 
space in place, and it works just fine.
I also made some experiments with the working check disk space script 
which I copied, added to config and changed the name of the identifier 
in the PUTVAL output, like exchanging "space" for "spoce" and similar 
changes. Sometimes, it worked and sometimes not. I am confused.

Has anyone an idea, what could be wrong? I added the config, script and 
the output below.

Thanks in advance,
Christian


Example output looks like:

PUTVAL "serverxyz/mediadl/time_fb1" interval=300 N:355
PUTVAL "serverxyz/mediadl/time_fb2" interval=300 N:864
PUTVAL "serverxyz/mediadl/time_fb3" interval=300 N:299
PUTVAL "serverxyz/mediadl/time_fb4" interval=300 N:236
PUTVAL "serverxyz/mediadl/time_fb5" interval=300 N:499
PUTVAL "serverxyz/mediadl/time_fb6" interval=300 N:473
PUTVAL "serverxyz/mediadl/time_fb7" interval=300 N:596


My exec config looks like:

LoadPlugin exec
TypesDB "/etc/collectd/add-ons/exec-types.db"

<Plugin exec>
         Exec "gd:gd" "/etc/collectd/add-ons/exec/check_disk_space.sh"
         Exec "gd:gd" 
"/etc/collectd/add-ons/exec/check_download_media_timings.sh"
</Plugin>

The script is:

#!/bin/bash
#
# This script test the download timings for a test file from the fb 
media servers.
#
# The test file is named test.jpg - resides in the media root dir and is 
about 20k big.

HOSTNAME="${COLLECTD_HOSTNAME:-`hostname -f`}"
INTERVAL="${COLLECTD_INTERVAL:-300}"

function downloadTestFile() {
         time $(wget -q --timeout=10 -O - 
http://fb$1.someserver.org/test.jpg >> /dev/null)
}

function measureFBDownload() {
         # value like "real      0m0.586s"
         value=$(downloadTestFile "$1" 2>&1 | grep real)
         # split minutes, seconds, millis
         minutes=$(echo -n "$value" | grep -Eo "[0-9]+m" | grep -Eo 
"[0-9]+")
         seconds=$(echo -n "$value" | grep -Eo "m[0-9]+" | grep -Eo 
"[0-9]+")
         millis=$(echo -n "$value" | grep -Eo "[0-9]+s" | grep -Eo 
"[^0][0-9]+")
         [ -z "${millis}" ] && millis=0
         totalMillis=$(( ($minutes * 60 * 60) + ($seconds * 60) + $millis ))
         echo "$totalMillis"
}

OUTPUT=""
for i in {1..7} ; do
         millis=$(measureFBDownload $i)
         OUTPUT="${OUTPUT}PUTVAL \"${HOSTNAME}/mediadl/time_fb${i}\" 
interval=${INTERVAL} N:${millis}\n"
done

# output full result at once and remove empty lines
echo -e "${OUTPUT}" | sed '/^$/d'

exit 0





More information about the collectd mailing list