CometVisu/Installation/RRDtool/en

From CometVisu
Jump to: navigation, search

RRDtool

RRDtool needs to provide the data for displaying graphs in the CometVisu.

Two options exist for this purpose. The fast variant is recommended for embedded or thin systems, but includes patching and compiling the rrdtool; the simple variant works with the vanilla rrdtool, but it needs more ressources and so is only recommended for current and more powerful systems.

Fast variant for embedded or thin systems

RRDtool provides an interface for this purpose, but it might be too slow, when used on embedded systems with limited performance.

For this reason, a patch was developed. Unfornuately, this never got integrated into rrdtool. Thus, the user of the CometVisu needs to patch RRDtool himself. Unfortunately, rrdtool has many dependencies, so that this is not an easy task. Below a script to install rrdtool can be found.

Alternatively, give the instructions below for debian a try.

If all fails, you need to wait for someone to make use of the built-in capabilities in rrdtool in CometVisu and life without graphs for now. Follow/check [1] discussion.

Debian

cd 
mkdir rrdtool
cd rrdtool
wget http://repo.wiregate.de/wiregate/pool/wiregate-1.0/main/r/rrdtool_1.3.1-4+nmu2.dsc
wget http://repo.wiregate.de/wiregate/pool/wiregate-1.0/main/r/rrdtool_1.3.1-4+nmu2.diff.gz
wget http://repo.wiregate.de/wiregate/pool/wiregate-1.0/main/r/rrdtool_1.3.1-4+nmu2_i386.changes
wget http://repo.wiregate.de/wiregate/pool/wiregate-1.0/main/r/rrdtool_1.3.1.orig.tar.gz
sudo apt-get build-dep rrdtool
dpkg-source -x rrdtool*dsc
cd rrdtool*
dpkg-buildpackage
sudo dpkg -i ../rrd*.deb

If it complains, that you do not have ruby1.9 and ruby1.9-dev, but you have 1.9.1 open ./debian/control and change it to 1.9.1.


Build from source Here the script to build it from source.

#build-rrdtool.sh
### DEPENDECIES
apt-get install gettext

BUILD_DIR=/root/rrdbuild
INSTALL_DIR=/usr 

mkdir -p $BUILD_DIR
cd $BUILD_DIR

export PATH=$INSTALL_DIR/bin:$PATH
export MAKE=make

wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.23.tar.gz
 gunzip -c pkg-config-0.23.tar.gz | tar xf -
 cd pkg-config-0.23
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
 $MAKE
 $MAKE install
 
export PKG_CONFIG=$INSTALL_DIR/bin/pkg-config

 cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/zlib-1.2.3.tar.gz
 gunzip -c zlib-1.2.3.tar.gz | tar xf -
 cd zlib-1.2.3
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --shared
 $MAKE
 $MAKE install
 
cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/libpng-1.2.18.tar.gz
 gunzip -c libpng-1.2.18.tar.gz | tar xf -
 cd libpng-1.2.18
 env CFLAGS="-O3 -fPIC" ./configure --prefix=$INSTALL_DIR
 $MAKE
 $MAKE install

cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/freetype-2.3.5.tar.gz
 gunzip -c freetype-2.3.5.tar.gz | tar xf -
 cd freetype-2.3.5
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
 $MAKE
 $MAKE install

cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/libxml2-2.6.32.tar.gz
 gunzip -c libxml2-2.6.32.tar.gz | tar xf -
 cd libxml2-2.6.32
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
 $MAKE
 $MAKE install
cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/fontconfig-2.4.2.tar.gz
gunzip -c fontconfig-2.4.2.tar.gz   | tar xf -
cd fontconfig-2.4.2
./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --with-freetype-config=$INSTALL_DIR/freetype-config
$MAKE
$MAKE install

cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/pixman-0.10.0.tar.gz
 gunzip -c pixman-0.10.0.tar.gz  | tar xf -
 cd pixman-0.10.0
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
 $MAKE
 $MAKE install

cd $BUILD_DIR
wget http://oss.oetiker.ch/rrdtool/pub/libs/cairo-1.6.4.tar.gz
gunzip -c cairo-1.6.4.tar.gz   | tar xf -
cd cairo-1.6.4
./configure --prefix=$INSTALL_DIR \
   --enable-xlib=no \
   --enable-xlib-render=no \
   --enable-win32=no \
   CFLAGS="-O3 -fPIC"
$MAKE
$MAKE install

cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/glib-2.15.4.tar.gz
 gunzip -c glib-2.15.4.tar.gz  | tar xf -
 cd glib-2.15.4
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC"
 $MAKE
 $MAKE install
 
cd $BUILD_DIR
 wget http://oss.oetiker.ch/rrdtool/pub/libs/pango-1.21.1.tar.bz2
 bunzip2 -c pango-1.21.1.tar.bz2 | tar xf -
 cd pango-1.21.1
 ./configure --prefix=$INSTALL_DIR CFLAGS="-O3 -fPIC" --without-x
 $MAKE
 $MAKE install
 
### RRD-TOOL  

cd $BUILD_DIR
wget http://repo.wiregate.de/wiregate/pool/main/r/rrdtool_1.3.1-4+nmu2.diff.gz
wget http://repo.wiregate.de/wiregate/pool/main/r/rrdtool_1.3.1.orig.tar.gz
tar xfvz rrdtool_1.3.1.orig.tar.gz
gunzip rrdtool_1.3.1-4+nmu2.diff.gz
cd rrdtool-1.3.1
patch -p1 < ../rrdtool_1.3.1-4+nmu2.diff 
$MAKE clean
./configure --prefix=$INSTALL_DIR
$MAKE
make install
cd ..



Script:

put this script to your cgi-bin

/usr/lib/cgi-bin/rrdfetch
#!/bin/sh
#echo Content-Type: text/plain
echo Content-Type: application/json
echo Content-Encoding: gzip
echo

#rrdtool fetch /var/www/rrd/Luftfeuchte_Bad_knx5-2-79.rrd AVERAGE -s-24h
RRD=`echo "$QUERY_STRING" | sed -n 's/^.*rrd=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
DS=`echo "$QUERY_STRING" | sed -n 's/^.*ds=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
START=`echo "$QUERY_STRING" | sed -n 's/^.*start=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
END=`echo "$QUERY_STRING" | sed -n 's/^.*end=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
RES=`echo "$QUERY_STRING" | sed -n 's/^.*res=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

#FIXME: check path traversal

rrdtool xport -json /var/www/rrd/$RRD $DS -s$START -e$END -r$RES | gzip -c

Simple variant for more powerful systems

This way works with rrdtool out of the box, but uses more ressources. Create the script /usr/lib/cgi-bin/rrdfetch:


#!/bin/bash
#echo Content-Type: text/plain
echo Content-Type: application/json
echo Content-Encoding: gzip
echo

#rrdtool fetch /var/www/rrd/Luftfeuchte_Bad_knx5-2-79.rrd AVERAGE -s-24h
RRD=`echo "$QUERY_STRING" | sed -n 's/^.*rrd=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
DS=`echo "$QUERY_STRING" | sed -n 's/^.*ds=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
START=`echo "$QUERY_STRING" | sed -n 's/^.*start=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
END=`echo "$QUERY_STRING" | sed -n 's/^.*end=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
RES=`echo "$QUERY_STRING" | sed -n 's/^.*res=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`

rrdtool fetch /var/www/rrd/$RRD $DS -s$START -e$END -r$RES | \
{ while read line ;
do
    if [[ "$line" == *:* ]] #matching lines with ":"
    then
    arr=(${line//: / }) #splits string with ": " in array
    a=${arr[0]}
    b=${arr[1]}
    a+="000"   #add zeros
    data+="[$a,[\"$b\"]],"
fi
done
echo "[${data%?}]" | gzip -c #cuts last character of $data and makes [] around
}

Simple variant for more powerful systems for RRDs with more than one variable in the RRD file

This way works with rrdtool out of the box, but uses more ressources. Create the script /usr/lib/cgi-bin/rrdfetch:

#!/bin/bash
#echo Content-Type: text/plain
echo Content-Type: application/json
echo Content-Encoding: gzip
echo
#rrdtool fetch /var/www/html/rrd/Luftfeuchte_Bad_knx5-2-79.rrd AVERAGE -s-24h
RRD=`echo "$QUERY_STRING" | sed -n 's/^.*rrd=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
DS=`echo "$QUERY_STRING" | sed -n 's/^.*ds=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
START=`echo "$QUERY_STRING" | sed -n 's/^.*start=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
END=`echo "$QUERY_STRING" | sed -n 's/^.*end=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
RES=`echo "$QUERY_STRING" | sed -n 's/^.*res=\([^&]*\).*$/\1/p' | sed "s/%20/ /g"`
rrdtool fetch /var/www/html/rrd/$RRD $DS -s$START -e$END -r$RES | \ 
{ while read line ;
do
    if   "$line" == *:*   #matching lines with ":"
    then
    arr=(${line//: / }) #splits string with ": " in array
    a=${arr[0]}
    b=${arr[1]}
    c=${arr[2]}
    d=${arr[3]}
    e=${arr[4]}
    f=${arr[5]}
    g=${arr[6]}
    h=${arr[7]}
    i=${arr[8]}
    j=${arr[9]}
    k=${arr[10]}
    a+="000"   #add zeros
    data+="[$a,[\"$b\",\"$c\",\"$d\",\"$e\",\"$f\",\"$g\",\"$h\",\"$i\",\"$j\",\"$k\"]],"
fi
done
echo "[${data%?}]" | gzip -c #cuts last character of $data and makes [] around
}