Next Previous Contents

2. How to do this in a sane way:

I suggest that you make a '/var/log/rrd' and make a hierarchy from there. Then, you can easily clone this hierarchy somewhere else to store the pictures.

2.1 Script for cloning the hierarchy:

#! /bin/sh

cd /var/log/rrd
for i in `find . -type d | cut -c3-`;
do
  mkdir -p /var/www/rrd/$i
done
cd -

2.2 Script for updating the image files in a cloned hierarchy

#! /bin/sh

cd /var/log/rrd
rrds=`find . -type f -name '*.rrd' | cut -c3-`

for i in $rrds;
  do
  j=`echo $i | sed 's/.rrd//'`
  rrdtool graph /var/www/rrd/$j-day.png --start -1d DEF:pkt=$i:packet:AVERAGE LINE1:pkt#ff0000:Packets/sec 
  rrdtool graph /var/www/rrd/$j-week.png --start -1w DEF:pkt=$i:packet:AVERAGE LINE1:pkt#ff0000:Packets/sec
  rrdtool graph /var/www/rrd/$j-month.png --start -1m DEF:pkt=$i:packet:AVERAGE LINE1:pkt#ff0000:Packets/sec
  rrdtool graph /var/www/rrd/$j-year.png --start -1y DEF:pkt=$i:packet:AVERAGE LINE1:pkt#ff0000:Packets/sec
done
cd -

2.3 Script that builds plain-jane HTML around this structure:

#! /bin/sh

cd /var/log/rrd
dirs=`find . -type d | grep -v images`
for i in $dirs;
  do
  html=/var/www/rrd/$i/index.html

  echo "<html><body>" > $html

  j=`echo $i | cut -c3-`
  echo "Processing $html "

  rrds=`find $i -type f -name '*.rrd' -maxdepth 1 | cut -c2-`
 
  for k in $rrds;
    do
    l=`echo $k | sed 's/.rrd//' | cut -c2-`
    m=`basename $k .rrd`
    if [ -d ./$l ];
      then
 
      echo "<a HREF=$m/>$m<br>" >> $html
      echo "<img src=$m-day.png border=0>" >> $html
      echo "<img src=$m-week.png border=0>" >> $html
      echo "<img src=$m-month.png border=0>" >> $html
      echo "<img src=$m-year.png border=0>" >> $html
      echo "</a><br>" >> $html

    else
      echo "$m<br>" >> $html
      echo "<img src=$m-day.png border=0>" >> $html
      echo "<img src=$m-week.png border=0>" >> $html
      echo "<img src=$m-month.png border=0>" >> $html
      echo "<img src=$m-year.png border=0>" >> $html
      echo "<br>" >> $html
    fi
  done
  cat "</body></html>" >> $html
done
cd -


Next Previous Contents