jablonka.czprosek.czf

crusader

Subversion Repositories:
[/] [trunk/] [statistiky/] [opt/] [statistiky/] [collect_temp.sh] - Blame information for rev 2

 

Line No. Rev Author Line
11simandl#!/bin/bash
2 
3PATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbin
4 
5filename="teplota"
6 
7data_dir="/var/statistiky/system"
8mkdir -p $data_dir
9 
10logdir=/var/log/statistiky
11if [ ! -d ${logdir} ]
12then
13 mkdir -p ${logdir}
14fi
15logfile=${logdir}/${filename}.log
16 
17cd ${data_dir}
18 
19function create()
20{
21 local filename=$1
22 echo "creating new ${filename}.rrd"
23#
24# sbirame s periodou 5 minut, tj. 12 PDP za hodinu
25#
26# za posledni tyden chceme vsechny 5min udaje => 12*24*9 = 2592 hodnot
27# za posledni mesic chceme 20minutove useky (agg 4) => 3*24*38 = 2736 hodnot
28# za posledni rok chceme dvouhodinove useky (agg 12) => 12*400 = 4800 hodnot
29rrdtool create ${filename}.rrd --step 300 --start `date +%s` \
30 DS:hdd_temp:GAUGE:500:0:100 \
31 RRA:AVERAGE:0.7:1:2592 \
32 RRA:MAX:0.7:4:2736 \
33 RRA:MIN:0.7:4:2736 \
34 RRA:AVERAGE:0.7:4:2736 \
35 RRA:MAX:0.7:24:4800 \
36 RRA:MIN:0.7:24:4800 \
37 RRA:AVERAGE:0.7:24:4800
38}
39 
40function wait_to()
41# $1 date for waiting to
42{
43 local time_now=`date +%s`;
44 while [ $time_now -lt $1 ]
45 do
46 time_now=`date +%s`
47 sleep 10;
48 done
49}
50 
51if [ ! -d ${data_dir} ]; then
52 mkdir -p ${data_dir}
53fi
54 
55function check_rrd_file()
56{
57 local filename=$1
58 echo "Looking for ${filename}.rrd"
59 if [ ! -f ${filename}.rrd ] ; then
60 create ${filename}
61 sleep 1;
62 fi
63}
64 
65start_time=`date +%s`
66maininterval=$(( ( ${start_time} + 60 ) / 60 * 60 ))
67 
68while [ true ]
69do
70 
71 check_rrd_file ${filename}
72 
73 echo "Wait to $maininterval [time: `date +%s`]"
74 interval=$maininterval
75 wait_to $interval
76 timenow=`date +%s`
77 fmt_time=`date "+%Y-%m-%d %T"`
78 echo "Time now: ${fmt_time}"
79 
80 hdd_temp=`smartctl -d ata -a /dev/hda | grep ^194 | gawk '{print $10;}'`
81 
82 echo "${fmt_time} HDD Temp: $hdd_temp" >>/var/log/statistiky/${filename}.log
83 rrdtool update ${filename}.rrd ${timenow}:${hdd_temp}
84 
85 maininterval=$(( $maininterval + 300 ))
86done
87 

Powered by WebSVN 2.2.1