![]() ![]() |
crusader |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/bin/bashPATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbinfilename="teplota"data_dir="/var/statistiky/system"mkdir -p $data_dirlogdir=/var/log/statistikyif [ ! -d ${logdir} ]thenmkdir -p ${logdir}filogfile=${logdir}/${filename}.logcd ${data_dir}function create(){local filename=$1echo "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 hodnotrrdtool 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 ]dotime_now=`date +%s`sleep 10;done}if [ ! -d ${data_dir} ]; thenmkdir -p ${data_dir}fifunction check_rrd_file(){local filename=$1echo "Looking for ${filename}.rrd"if [ ! -f ${filename}.rrd ] ; thencreate ${filename}sleep 1;fi}start_time=`date +%s`maininterval=$(( ( ${start_time} + 60 ) / 60 * 60 ))while [ true ]docheck_rrd_file ${filename}echo "Wait to $maininterval [time: `date +%s`]"interval=$mainintervalwait_to $intervaltimenow=`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}.logrrdtool update ${filename}.rrd ${timenow}:${hdd_temp}maininterval=$(( $maininterval + 300 ))done