-
Notifications
You must be signed in to change notification settings - Fork 1
/
DRAW.pl
executable file
·96 lines (75 loc) · 2.26 KB
/
DRAW.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/perl -w
use strict;
my %config;
#### CONFIG SECTION ####
$config{'in'} = "Serverraum";
$config{'1'} = "Raum ITS";
$config{'2'} = "Raum Operative Leitung";
$config{'3'} = "Raum FL";
$config{'4'} = "Rezeption";
$config{'5'} = "Kueche";
$config{'datadir'} = "/srv/klimalogger/data/";
$config{'outputdir'} = "/srv/klimalogger/web/out/";
#### END CONFIG ####
while ( my $db = <$config{'datadir'}/sensor_*.rrd> ) {
$db =~ s/.*sensor_([\da-z]+)\.rrd.*/$1/g;
graph($db, 'Day');
graph($db, 'Week');
graph($db, 'Month');
graph($db, 'Year');
}
sub graph {
my ($db, $time ) = ( @_ );
my $start;
my $output_temp = $config{'outputdir'} . "/graph_${db}_${time}_Temperature.png";
my $output_hum = $config{'outputdir'} . "/graph_${db}_${time}_Humidity.png";
if ( $time eq 'Day' ) {
$start = 'end-1d';
} elsif ( $time eq 'Week' ) {
$start = 'end-1w';
} elsif ( $time eq 'Month' ) {
$start = 'end-1m';
} elsif ( $time eq 'Year' ) {
$start = 'end-1y';
}
my $dbalias;
if ( defined $config{$db} ) {
$dbalias = $config{$db};
} else {
$dbalias = $db;
}
my $cmd = "rrdtool graph $output_temp \\
-w 650 \\
-h 160 \\
--start $start \\
--vertical-label=\"Degree Celsius\" \\
DEF:temp=$config{'datadir'}/sensor_${db}.rrd:temp:AVERAGE \\
LINE2:temp#FF0000:\"Temperature\" \\
GPRINT:temp:MIN:\" Min\\: %4.1lf\" \\
GPRINT:temp:MAX:\" Max\\: %4.1lf\" \\
GPRINT:temp:AVERAGE:\" Avg\\: %4.1lf\" \\";
if ($time eq 'Day') {
$cmd .= "GPRINT:temp:LAST:\" Current\\: %4.1lf\" \\";
}
$cmd .= "" .
"-t \" $time - Sensor $dbalias (Temperature) \" ";
#print $cmd;
system( $cmd . " > /dev/null");
$cmd = "rrdtool graph $output_hum \\
-w 650 \\
-h 160 \\
--start $start \\
--vertical-label=\"%\" \\
DEF:hum=$config{'datadir'}/sensor_${db}.rrd:humidity:AVERAGE \\
LINE2:hum#00FF00:\"Humidity\" \\
GPRINT:hum:MIN:\" Min\\: %4.1lf\" \\
GPRINT:hum:MAX:\" Max\\: %4.1lf\" \\
GPRINT:hum:AVERAGE:\" Avg\\: %4.1lf\" \\";
if ($time eq 'Day') {
$cmd .= "GPRINT:hum:LAST:\" Current\\: %4.1lf\" \\";
}
$cmd .= "" .
"-t \" $time - Sensor $dbalias (Humidity) \" ";
#print $cmd;
system( $cmd . " > /dev/null");
}