#!/bin/sh #------------------------------------------------------------------------------ # RRDtool3 - Startup Script 3.5.0 # # Creation: 2010-08-29 Tiger # Last Update: $Id: rc940.rrdtool3$ # # Copyright (c) 2010 Fli4L Team # # This OPT package is licensed under Free Software Foundation, Inc., # General Public License Version 2, June 1991 #------------------------------------------------------------------------------ CreateSoftLink () { local filename=$1 #----------------- if [ -n "$filename" ] then if [ -f "$filename" ] then ln -s "$filename" "`echo $filename | sed 's|[0-9.]*$||'`" else log_error "ERROR: File '$filename' not found." fi fi } CreateFolder () { local folder=$1 #----------------- if [ -n "$folder" ] then if [ ! -e "$folder" ] then if ! mkdir -p "$folder" 2> /dev/null then log_error "Cannot create folder '$folder'." fi fi fi } CreateOptConfigurationFile () { local filename=$1 #----------------- if [ -n "$filename" ] then set | sed '\|^RRDTOOL3_|!d; \ \|^RRDTOOL3_COLLECTD_|d; \ \|^RRDTOOL3_RRDCACHED_SOCKET|p; \ \|^RRDTOOL3_RRDCACHED_|d' > $filename fi } # Convert tab configuration to a list of plugins (one plugin per line) with all # parameters separated by plus (+) characters appended to the line. A colon (:) # sections the plugin name from the parameters. ParseTabConfiguration () { local tab_index= local graph_index= local subtab_index= ( for tab_index in `seq 1 $RRDTOOL3_TAB_N` do for subtab_index in `seq 1 0$(eval echo '$RRDTOOL3_TAB_'$tab_index'_SUBTAB_N')` do eval echo '$RRDTOOL3_TAB_'$tab_index'_SUBTAB_'$subtab_index'_GRAPH' for graph_index in `seq 1 0$(eval echo '$RRDTOOL3_TAB_'$tab_index'_SUBTAB_'$subtab_index'_GRAPH_N')` do eval echo '$RRDTOOL3_TAB_'$tab_index'_SUBTAB_'$subtab_index'_GRAPH_'$graph_index done done eval echo '$RRDTOOL3_TAB_'$tab_index'_GRAPH' for graph_index in `seq 1 0$(eval echo '$RRDTOOL3_TAB_'$tab_index'_GRAPH_N')` do eval echo '$RRDTOOL3_TAB_'$tab_index'_GRAPH_'$graph_index done done ) | tr '+' '\n' | sed '\|^$|d;\|^[^:]*:|{h;s|:.*$||;x};\|^[^:]*:|!{G;s|\(.*\)\n\(.*\)|\2:\1|}' | sort | sed '$!N; \|^\(.*\)\n\1$|!P; D' | sed -e :a -e '$!N;s/^\([^:]*:\)\(.*\)\n\1/\1\2+/;ta' -e 'P;D' } CreateCollectdConfigurationFile () { local filename=$1 #----------------- if [ -n "$filename" ] then cat << __EOF__ | sed '\|^[ ]*$|d' > "$filename" Hostname "$HOSTNAME" PluginDir "$RRDTOOL3_DIR_COLLECTD_PLUGIN" TypesDB "$RRDTOOL3_FILE_COLLECTD_TYPESDB" ${RRDTOOL3_COLLECTD_FWDNLOOKUP:+FQDNLookup $RRDTOOL3_COLLECTD_FWDNLOOKUP} ${RRDTOOL3_COLLECTD_INTERVAL:+Interval $RRDTOOL3_COLLECTD_INTERVAL} ${RRDTOOL3_COLLECTD_READTHREADS:+ReadThreads $RRDTOOL3_COLLECTD_READTHREADS} ${RRDTOOL3_COLLECTD_TIMEOUT:+Timeout $RRDTOOL3_COLLECTD_TIMEOUT} ${RRDTOOL3_DIR_COLLECTD_BASE:+BaseDir "$RRDTOOL3_DIR_COLLECTD_BASE"} ${RRDTOOL3_FILE_COLLECTD_PID:+PIDFile "$RRDTOOL3_FILE_COLLECTD_PID"} LoadPlugin rrdcached DaemonAddress "$RRDTOOL3_RRDCACHED_SOCKET" DataDir "$RRDTOOL3_DB_PATH" CreateFiles true CollectStatistics $RRDTOOL3_RRDCACHED_STATISTICS __EOF__ # Each required PlugIn configuration file is called once with all parameters of # all corresponding tab items put into a single line and separated by plus (+) # characters. The parameters are filtered for dupes. So even if the same item # is listed more than once, it will only occure one time in the parameter # string. This is to avoid unnecessary creation of multiple databases with # identical content. ParseTabConfiguration | while read line do local plugin_name=`echo "$line" | cut -d':' -f1` local plugin_file="$RRDTOOL3_DIR_INCLUDE/$plugin_name.inc" if [ -f "$plugin_file" ] then . "$plugin_file" local plugin_routine=CollectdConfig_$plugin_name if type $plugin_routine > /dev/null then $plugin_routine "`echo $line | cut -d':' -f2-`" | sed '\|^[ ]*$|d' >> "$filename" else log_error "Include file for plugin '$plugin_name' does not supply a collectd configuration." fi else log_error "No include file available for plugin '$plugin_name'" fi done fi } case "$OPT_RRDTOOL3" in "yes") : ${RRDTOOL3_OPT:=RRDtool} : ${RRDTOOL3_VERSION:=0.5.1} : ${RRDTOOL3_DB_PATH:=/boot/rrdtool} : ${RRDTOOL3_DIR_DATABASE:=$RRDTOOL3_DB_PATH/$HOSTNAME} : ${RRDTOOL3_DIR_INCLUDE:=/etc/rrdtool3} : ${RRDTOOL3_DIR_GRAPH_IMAGE:=/srv/www/img} : ${RRDTOOL3_GRAPH_WIDTH=600} : ${RRDTOOL3_GRAPH_HEIGHT=200} : ${RRDTOOL3_GRAPH_COLOUR=CANVAS#E0E0E0} : ${RRDTOOL3_GRAPH_LINECOLOURS=0000FF 0077FF 00FFFF 00FF77 00FF00 77FF00 FFFF00 FF7700 FF0000 FF0077 FF00FF 7700FF} : ${RRDTOOL3_DISK_LINECOLOURS:=FF0000 00FF00 BB0000 00BB00 770000 007700 330000 003300} : ${RRDTOOL3_INTERFACE_LINECOLOURS:=FF0000 00FF00 BB0000 00BB00 770000 007700 330000 003300} : ${RRDTOOL3_GRAPH_TIMELINE:=1h 6h 24h 7d 4w 1y} # -- collectd : ${RRDTOOL3_DIR_COLLECTD_PLUGIN:=/usr/lib/collectd} #: ${RRDTOOL3_FILE_COLLECTD_PID:=/var/run/collectd.pid} FIXME: For whatever reason, PID file creation causes collectd to crash : ${RRDTOOL3_FILE_COLLECTD_CONFIG:=/etc/collectd.conf} : ${RRDTOOL3_FILE_COLLECTD_TYPESDB:=/usr/share/collectd/types.db} # -- rrdcached : ${RRDTOOL3_DIR_RRDCACHED_BASE:=$RRDTOOL3_DB_PATH} : ${RRDTOOL3_DIR_RRDCACHED_JOURNAL:=$RRDTOOL3_DB_PATH/$HOSTNAME} : ${RRDTOOL3_FILE_RRDCACHED_PID:=/var/run/rrdcached.pid} : ${RRDTOOL3_RRDCACHED_SOCKET:=unix:/var/run/rrdcached.sock} : ${RRDTOOL3_RRDCACHED_STATISTICS:=true} RRDTOOL3_RRDCACHED_ALWAYSFLUSH=${RRDTOOL3_RRDCACHED_ALWAYSFLUSH#no} begin_script $RRDTOOL3_OPT "starting $RRDTOOL3_OPT..." CreateFolder "$RRDTOOL3_DIR_COLLECTD_BASE" CreateFolder "$RRDTOOL3_DIR_RRDCACHED_BASE" CreateFolder "$RRDTOOL3_DIR_RRDCACHED_JOURNAL" CreateOptConfigurationFile "/var/run/rrdtool3.conf" CreateSoftLink "/usr/lib/lua/5.1/rrd.so.0.0.0" CreateCollectdConfigurationFile "$RRDTOOL3_FILE_COLLECTD_CONFIG" if /usr/bin/rrdcached ${RRDTOOL3_FILE_RRDCACHED_PID:+-p "$RRDTOOL3_FILE_RRDCACHED_PID"} \ ${RRDTOOL3_RRDCACHED_GROUP:+-s "$RRDTOOL3_RRDCACHED_GROUP"} \ ${RRDTOOL3_RRDCACHED_MODE:+-m $RRDTOOL3_RRDCACHED_MODE} \ ${RRDTOOL3_RRDCACHED_COMMAND:+-P $RRDTOOL3_RRDCACHED_COMMAND} \ ${RRDTOOL3_RRDCACHED_DELAY:+-z $RRDTOOL3_RRDCACHED_DELAY} \ ${RRDTOOL3_DIR_RRDCACHED_BASE:+-b "$RRDTOOL3_DIR_RRDCACHED_BASE" -B} \ ${RRDTOOL3_DIR_RRDCACHED_JOURNAL:+-j "$RRDTOOL3_DIR_RRDCACHED_JOURNAL"} \ ${RRDTOOL3_RRDCACHED_TIMEOUT:+-w $RRDTOOL3_RRDCACHED_TIMEOUT} \ ${RRDTOOL3_RRDCACHED_FLUSH:+-f $RRDTOOL3_RRDCACHED_FLUSH} \ ${RRDTOOL3_RRDCACHED_ALWAYSFLUSH:+-F} \ ${RRDTOOL3_RRDCACHED_THREADS:+-t $RRDTOOL3_RRDCACHED_THREADS} \ -l $RRDTOOL3_RRDCACHED_SOCKET then echo "rrdcached started." if /usr/sbin/collectdmon then echo "collectdmon started." else log_error "Failed to start collectdmon." fi else log_error "Failed to start rrdcached." fi # Add Menu Entry /usr/local/bin/httpd-menu.sh add -p 600 "rrdtool3.cgi" "$RRDTOOL3_OPT" "" rrdtool end_script esac