1 | 1 | simandl | #!/bin/bash |
2 | | | |
3 | | | PATH=/opt/rrdtool/bin:$PATH:/sbin:/usr/sbin |
4 | | | |
5 | | | filename="teplota" |
6 | | | |
7 | | | data_dir="/var/statistiky/system" |
8 | | | mkdir -p $data_dir |
9 | | | |
10 | | | logdir=/var/log/statistiky |
11 | | | if [ ! -d ${logdir} ] |
12 | | | then |
13 | | | mkdir -p ${logdir} |
14 | | | fi |
15 | | | logfile=${logdir}/${filename}.log |
16 | | | |
17 | | | cd ${data_dir} |
18 | | | |
19 | | | function 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 |
29 | | | rrdtool 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 | | | |
40 | | | function 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 | | | |
51 | | | if [ ! -d ${data_dir} ]; then |
52 | | | mkdir -p ${data_dir} |
53 | | | fi |
54 | | | |
55 | | | function 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 | | | |
65 | | | start_time=`date +%s` |
66 | | | maininterval=$(( ( ${start_time} + 60 ) / 60 * 60 )) |
67 | | | |
68 | | | while [ true ] |
69 | | | do |
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 )) |
86 | | | done |
87 | | | |