| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# tellerstats.sh 3 |
| 4 |
# generate graphs from the data |
| 5 |
# |
| 6 |
# Copyright (C) 2001 Philip Edelbrock |
| 7 |
# |
| 8 |
# This program is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 2 of the License, or |
| 11 |
# (at your option) any later version. |
| 12 |
# |
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
# |
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
| 21 |
# MA 02110-1301 USA. |
| 22 |
# |
| 23 |
|
| 24 |
# generic tellerstats init BEGIN |
| 25 |
|
| 26 |
# get config information from /etc/tellerstats.conf or wherever we are pointed |
| 27 |
|
| 28 |
if [ -z "$TELLERSTATS_CONF" ] |
| 29 |
then |
| 30 |
TELLERSTATS_CONF=/etc/tellerstats.conf |
| 31 |
fi |
| 32 |
|
| 33 |
export TELLERSTATS_CONF |
| 34 |
|
| 35 |
if [ ! -r $TELLERSTATS_CONF ] |
| 36 |
then |
| 37 |
echo "$0: Could not find config file $TELLERSTATS_CONF" |
| 38 |
exit 1 |
| 39 |
fi |
| 40 |
|
| 41 |
. $TELLERSTATS_CONF |
| 42 |
|
| 43 |
if [ ! -d $DBPATH ] |
| 44 |
then |
| 45 |
echo "$0: data directory $DBPATH does not exist" |
| 46 |
exit 1 |
| 47 |
fi |
| 48 |
|
| 49 |
if [ ! -d $SENSORPATH ] |
| 50 |
then |
| 51 |
echo "$0: sensor information directory $SENSORPATH does not exist." |
| 52 |
exit 1 |
| 53 |
fi |
| 54 |
|
| 55 |
if [ ! -d $HTMLROOT ] |
| 56 |
then |
| 57 |
echo "$0: The root of your webserver - $HTMLROOT - does not exist..bailing out" |
| 58 |
exit 1 |
| 59 |
fi |
| 60 |
|
| 61 |
if [ ! -d $HTMLPATH ] |
| 62 |
then |
| 63 |
echo "$0: The place where we keep HTML files and pictures - $HTMLPATH - does not exist..bailing out" |
| 64 |
exit 1 |
| 65 |
fi |
| 66 |
|
| 67 |
if [ ! -r $GNUPLOTSCRIPT_TMPL ] |
| 68 |
then |
| 69 |
echo "$0: The gnuplot script template $GNUPLOTSCRIPT_TMPL does not exist..bailing out" |
| 70 |
exit 1 |
| 71 |
fi |
| 72 |
|
| 73 |
export DBPATH SENSORPATH TEMPPATH HTMLROOT HTMLPATH GNUPLOTSCRIPT_TMPL |
| 74 |
|
| 75 |
if [ -n "$DEBUG" ] |
| 76 |
then |
| 77 |
echo "DBPATH = $DBPATH" |
| 78 |
echo "SENSORPATH = $SENSORPATH" |
| 79 |
echo "TEMPPATH = $TEMPPATH" |
| 80 |
echo "HTMLROOT = $HTMLROOT" |
| 81 |
echo "HTMLPATH = $HTMLPATH" |
| 82 |
echo "GNUPLOTSCRIPT_TMPL = $GNUPLOTSCRIPT_TMPL" |
| 83 |
fi |
| 84 |
|
| 85 |
# generic tellerstats init END |
| 86 |
|
| 87 |
if [ -z "$LINEWIDTH" ] |
| 88 |
then |
| 89 |
LINEWIDTH=5 |
| 90 |
fi |
| 91 |
export LINEWIDTH |
| 92 |
|
| 93 |
if [ -z "$PLOTFORMAT" ] |
| 94 |
then |
| 95 |
PLOTFORMAT=ps |
| 96 |
fi |
| 97 |
export PLOTFORMAT |
| 98 |
|
| 99 |
if [ -z "$PLOTTERMINAL" ] |
| 100 |
then |
| 101 |
PLOTTERMINAL="postscript eps enhanced color \"Helvetica\" 22" |
| 102 |
fi |
| 103 |
export PLOTTERMINAL |
| 104 |
|
| 105 |
if [ -n "$DEBUG" ] |
| 106 |
then |
| 107 |
echo "LINEWIDTH = $LINEWIDTH" |
| 108 |
echo "PLOTFORMAT = $PLOTFORMAT" |
| 109 |
echo "PLOTTERMINAL = $PLOTTERMINAL" |
| 110 |
fi |
| 111 |
|
| 112 |
# Trim files to 48 hour window |
| 113 |
|
| 114 |
cd $DBPATH |
| 115 |
files="`echo *`" |
| 116 |
|
| 117 |
for this in $files |
| 118 |
do |
| 119 |
tail $this -n576 > ${this}.tmp |
| 120 |
mv ${this}.tmp $this |
| 121 |
done |
| 122 |
|
| 123 |
############################################### |
| 124 |
|
| 125 |
rm -rf $TEMPPATH |
| 126 |
mkdir -p $TEMPPATH |
| 127 |
|
| 128 |
cd $TEMPPATH |
| 129 |
|
| 130 |
# Update primary plots |
| 131 |
GNUPLOTSCRIPT="$TEMPPATH/gnuplotscript" |
| 132 |
cat $GNUPLOTSCRIPT_TMPL | perl -p -e's/\$(\w+)/$ENV{$1}/g' > $GNUPLOTSCRIPT |
| 133 |
gnuplot < $GNUPLOTSCRIPT |
| 134 |
rm $GNUPLOTSCRIPT |
| 135 |
|
| 136 |
files="`echo *`" |
| 137 |
|
| 138 |
CONVERT_OPTS_A="-interlace none -scale 320x240 -quality 100" |
| 139 |
CONVERT_OPTS_B="-interlace none -scale 800x600 -quality 100" |
| 140 |
|
| 141 |
for this in $files |
| 142 |
do |
| 143 |
prefix=`echo $this|perl -p -e's/\.\w+$//'` |
| 144 |
convert $CONVERT_OPTS_A $TEMPPATH/$this $HTMLPATH/${prefix}.png |
| 145 |
convert $CONVERT_OPTS_B $TEMPPATH/$this $HTMLPATH/${prefix}B.png |
| 146 |
touch $HTMLPATH/${prefix}.png $HTMLPATH/${prefix}B.png |
| 147 |
done |
| 148 |
|
| 149 |
# Update timestamp |
| 150 |
|
| 151 |
touch $HTMLPATH/index.shtml |
| 152 |
|
| 153 |
# if this was called as a cgi script, it should redirect to the index.shtml file |
| 154 |
if [ -n "$REMOTE_HOST" ] |
| 155 |
then |
| 156 |
REL_HTML=${HTMLPATH#$HTMLROOT} |
| 157 |
echo "Location: $REL_HTML/index.shtml" |
| 158 |
echo |
| 159 |
fi |
| 160 |
|
| 161 |
if [ -z "$DEBUG" ] |
| 162 |
then |
| 163 |
rm -rf $TEMPPATH |
| 164 |
fi |
| 165 |
|
| 166 |
exit 0 |