| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # tellerstats.sh 3 |
|---|
| 4 | # generate graphs from the data |
|---|
| 5 | # |
|---|
| 6 | # Copyright 2001 The lm_sensors group |
|---|
| 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., 675 Mass Ave, Cambridge, MA 02139, USA. |
|---|
| 21 | # |
|---|
| 22 | |
|---|
| 23 | # generic tellerstats init BEGIN |
|---|
| 24 | |
|---|
| 25 | # get config information from /etc/tellerstats.conf or whereever we are pointed |
|---|
| 26 | |
|---|
| 27 | if [ -z "$TELLERSTATS_CONF" ] |
|---|
| 28 | then |
|---|
| 29 | TELLERSTATS_CONF=/etc/tellerstats.conf |
|---|
| 30 | fi |
|---|
| 31 | |
|---|
| 32 | export TELLERSTATS_CONF |
|---|
| 33 | |
|---|
| 34 | if [ ! -r $TELLERSTATS_CONF ] |
|---|
| 35 | then |
|---|
| 36 | echo "$0: Could not find config file $TELLERSTATS_CONF" |
|---|
| 37 | exit 1 |
|---|
| 38 | fi |
|---|
| 39 | |
|---|
| 40 | . $TELLERSTATS_CONF |
|---|
| 41 | |
|---|
| 42 | if [ ! -d $DBPATH ] |
|---|
| 43 | then |
|---|
| 44 | echo "$0: data directory $DBPATH does not exist" |
|---|
| 45 | exit 1 |
|---|
| 46 | fi |
|---|
| 47 | |
|---|
| 48 | if [ ! -d $SENSORPATH ] |
|---|
| 49 | then |
|---|
| 50 | echo "$0: sensor information directory $SENSORPATH does not exist." |
|---|
| 51 | exit 1 |
|---|
| 52 | fi |
|---|
| 53 | |
|---|
| 54 | if [ ! -d $HTMLROOT ] |
|---|
| 55 | then |
|---|
| 56 | echo "$0: The root of your webserver - $HTMLROOT - does not exist..bailing out" |
|---|
| 57 | exit 1 |
|---|
| 58 | fi |
|---|
| 59 | |
|---|
| 60 | if [ ! -d $HTMLPATH ] |
|---|
| 61 | then |
|---|
| 62 | echo "$0: The place where we keep HTML files and pictures - $HTMLPATH - does not exist..bailing out" |
|---|
| 63 | exit 1 |
|---|
| 64 | fi |
|---|
| 65 | |
|---|
| 66 | if [ ! -r $GNUPLOTSCRIPT_TMPL ] |
|---|
| 67 | then |
|---|
| 68 | echo "$0: The gnuplot script template $GNUPLOTSCRIPT_TMPL does not exist..bailing out" |
|---|
| 69 | exit 1 |
|---|
| 70 | fi |
|---|
| 71 | |
|---|
| 72 | export DBPATH SENSORPATH TEMPPATH HTMLROOT HTMLPATH GNUPLOTSCRIPT_TMPL |
|---|
| 73 | |
|---|
| 74 | if [ -n "$DEBUG" ] |
|---|
| 75 | then |
|---|
| 76 | echo "DBPATH = $DBPATH" |
|---|
| 77 | echo "SENSORPATH = $SENSORPATH" |
|---|
| 78 | echo "TEMPPATH = $TEMPPATH" |
|---|
| 79 | echo "HTMLROOT = $HTMLROOT" |
|---|
| 80 | echo "HTMLPATH = $HTMLPATH" |
|---|
| 81 | echo "GNUPLOTSCRIPT_TMPL = $GNUPLOTSCRIPT_TMPL" |
|---|
| 82 | fi |
|---|
| 83 | |
|---|
| 84 | # generic tellerstats init END |
|---|
| 85 | |
|---|
| 86 | if [ -z "$LINEWIDTH" ] |
|---|
| 87 | then |
|---|
| 88 | LINEWIDTH=5 |
|---|
| 89 | fi |
|---|
| 90 | export LINEWIDTH |
|---|
| 91 | |
|---|
| 92 | if [ -z "$PLOTFORMAT" ] |
|---|
| 93 | then |
|---|
| 94 | PLOTFORMAT=ps |
|---|
| 95 | fi |
|---|
| 96 | export PLOTFORMAT |
|---|
| 97 | |
|---|
| 98 | if [ -z "$PLOTTERMINAL" ] |
|---|
| 99 | then |
|---|
| 100 | PLOTTERMINAL="postscript eps enhanced color \"Helvetica\" 22" |
|---|
| 101 | fi |
|---|
| 102 | export PLOTTERMINAL |
|---|
| 103 | |
|---|
| 104 | if [ -n "$DEBUG" ] |
|---|
| 105 | then |
|---|
| 106 | echo "LINEWIDTH = $LINEWIDTH" |
|---|
| 107 | echo "PLOTFORMAT = $PLOTFORMAT" |
|---|
| 108 | echo "PLOTTERMINAL = $PLOTTERMINAL" |
|---|
| 109 | fi |
|---|
| 110 | |
|---|
| 111 | # Trim files to 48 hour window |
|---|
| 112 | |
|---|
| 113 | cd $DBPATH |
|---|
| 114 | files="`echo *`" |
|---|
| 115 | |
|---|
| 116 | for this in $files |
|---|
| 117 | do |
|---|
| 118 | tail $this -n576 > ${this}.tmp |
|---|
| 119 | mv ${this}.tmp $this |
|---|
| 120 | done |
|---|
| 121 | |
|---|
| 122 | ############################################### |
|---|
| 123 | |
|---|
| 124 | rm -rf $TEMPPATH |
|---|
| 125 | mkdir -p $TEMPPATH |
|---|
| 126 | |
|---|
| 127 | cd $TEMPPATH |
|---|
| 128 | |
|---|
| 129 | # Update primary plots |
|---|
| 130 | GNUPLOTSCRIPT="$TEMPPATH/gnuplotscript" |
|---|
| 131 | cat $GNUPLOTSCRIPT_TMPL | perl -p -e's/\$(\w+)/$ENV{$1}/g' > $GNUPLOTSCRIPT |
|---|
| 132 | gnuplot < $GNUPLOTSCRIPT |
|---|
| 133 | rm $GNUPLOTSCRIPT |
|---|
| 134 | |
|---|
| 135 | files="`echo *`" |
|---|
| 136 | |
|---|
| 137 | CONVERT_OPTS_A="-interlace none -scale 320x240 -quality 100" |
|---|
| 138 | CONVERT_OPTS_B="-interlace none -scale 800x600 -quality 100" |
|---|
| 139 | |
|---|
| 140 | for this in $files |
|---|
| 141 | do |
|---|
| 142 | prefix=`echo $this|perl -p -e's/\.\w+$//'` |
|---|
| 143 | convert $CONVERT_OPTS_A $TEMPPATH/$this $HTMLPATH/${prefix}.png |
|---|
| 144 | convert $CONVERT_OPTS_B $TEMPPATH/$this $HTMLPATH/${prefix}B.png |
|---|
| 145 | touch $HTMLPATH/${prefix}.png $HTMLPATH/${prefix}B.png |
|---|
| 146 | done |
|---|
| 147 | |
|---|
| 148 | # Update timestamp |
|---|
| 149 | |
|---|
| 150 | touch $HTMLPATH/index.shtml |
|---|
| 151 | |
|---|
| 152 | # if this was called as a cgi script, it should redirect to the index.shtml file |
|---|
| 153 | if [ -n "$REMOTE_HOST" ] |
|---|
| 154 | then |
|---|
| 155 | REL_HTML=${HTMLPATH#$HTMLROOT} |
|---|
| 156 | echo "Location: $REL_HTML/index.shtml" |
|---|
| 157 | echo |
|---|
| 158 | fi |
|---|
| 159 | |
|---|
| 160 | if [ -z "$DEBUG" ] |
|---|
| 161 | then |
|---|
| 162 | rm -rf $TEMPPATH |
|---|
| 163 | fi |
|---|
| 164 | |
|---|
| 165 | exit 0 |
|---|