crusader |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bash
PATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbin
filename="teplota"
data_dir="/var/statistiky/system"
mkdir -p $data_dir
logdir=/var/log/statistiky
if [ ! -d ${logdir} ]
then
mkdir -p ${logdir}
fi
logfile=${logdir}/${filename}.log
cd ${data_dir}
function create()
{
local filename=$1
echo "creating new ${filename}.rrd"
#
# sbirame s periodou 5 minut, tj. 12 PDP za hodinu
#
# za posledni tyden chceme vsechny 5min udaje => 12*24*9 = 2592 hodnot
# za posledni mesic chceme 20minutove useky (agg 4) => 3*24*38 = 2736 hodnot
# za posledni rok chceme dvouhodinove useky (agg 12) => 12*400 = 4800 hodnot
rrdtool create ${filename}.rrd --step 300 --start `date +%s` \
DS:hdd_temp:GAUGE:500:0:100 \
RRA:AVERAGE:0.7:1:2592 \
RRA:MAX:0.7:4:2736 \
RRA:MIN:0.7:4:2736 \
RRA:AVERAGE:0.7:4:2736 \
RRA:MAX:0.7:24:4800 \
RRA:MIN:0.7:24:4800 \
RRA:AVERAGE:0.7:24:4800
}
function wait_to()
# $1 date for waiting to
{
local time_now=`date +%s`;
while [ $time_now -lt $1 ]
do
time_now=`date +%s`
sleep 10;
done
}
if [ ! -d ${data_dir} ]; then
mkdir -p ${data_dir}
fi
function check_rrd_file()
{
local filename=$1
echo "Looking for ${filename}.rrd"
if [ ! -f ${filename}.rrd ] ; then
create ${filename}
sleep 1;
fi
}
start_time=`date +%s`
maininterval=$(( ( ${start_time} + 60 ) / 60 * 60 ))
while [ true ]
do
check_rrd_file ${filename}
echo "Wait to $maininterval [time: `date +%s`]"
interval=$maininterval
wait_to $interval
timenow=`date +%s`
fmt_time=`date "+%Y-%m-%d %T"`
echo "Time now: ${fmt_time}"
hdd_temp=`smartctl -d ata -a /dev/hda | grep ^194 | gawk '{print $10;}'`
echo "${fmt_time} HDD Temp: $hdd_temp" >>/var/log/statistiky/${filename}.log
rrdtool update ${filename}.rrd ${timenow}:${hdd_temp}
maininterval=$(( $maininterval + 300 ))
done