]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Updater create addon backup folder if it was missing
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
CommitLineData
cd1a2927
MT
1#!/usr/bin/perl
2
5468f102
CS
3###############################################################################
4# #
5# IPFire.org - A linux based firewall #
6# Copyright (C) 2008 Michael Tremer & Christian Schmidt #
7# #
8# This program is free software: you can redistribute it and/or modify #
9# it under the terms of the GNU General Public License as published by #
10# the Free Software Foundation, either version 3 of the License, or #
11# (at your option) any later version. #
12# #
13# This program is distributed in the hope that it will be useful, #
14# but WITHOUT ANY WARRANTY; without even the implied warranty of #
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
16# GNU General Public License for more details. #
17# #
18# You should have received a copy of the GNU General Public License #
19# along with this program. If not, see <http://www.gnu.org/licenses/>. #
20# #
21###############################################################################
60cbd6e7 22
cd1a2927
MT
23use strict;
24#use warnings;
25
26use RRDs;
986e08d9 27require "/var/ipfire/general-functions.pl";
cd1a2927
MT
28require "${General::swroot}/lang.pl";
29
cd1a2927 30# Settings
cd1a2927 31$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
a68fedca 32my $temp = '';
52345790 33my $ERROR;
52345790
MT
34my $path_smartctl = "/usr/sbin/smartctl";
35
4b4aec3a
CS
36my %color = ();
37my %mainsettings = ();
38&General::readhash("${General::swroot}/main/settings", \%mainsettings);
39&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
52345790 40
dd7d74eb
AF
41if ( $mainsettings{'RRDLOG'} eq "" ){
42 $mainsettings{'RRDLOG'}="/var/log/rrd";
43 &General::writehash("${General::swroot}/main/settings", \%mainsettings);
44}
45
5468f102
CS
46sub updatehdddata{
47 my $disk = $_[0];
48 my $standby;
49 my @array = split(/\//,$disk);
50
51 if ( ! -e "$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd"){
52 # database did not exist -> create
53 RRDs::create ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300",
54 "DS:standby:GAUGE:600:0:1",
55 "RRA:AVERAGE:0.5:1:576",
56 "RRA:AVERAGE:0.5:6:672",
57 "RRA:AVERAGE:0.5:24:732",
58 "RRA:AVERAGE:0.5:144:1460");
59 $ERROR = RRDs::error;
60 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
61 }
62
63 if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
64 else {$standby = 0;}
65
66 RRDs::update ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
67 $ERROR = RRDs::error;
68 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
69
70 if ( ! -e "$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){
71 # database did not exist -> create
72 RRDs::create ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300",
73 "DS:temperature:GAUGE:600:0:100",
74 "RRA:AVERAGE:0.5:1:576",
75 "RRA:AVERAGE:0.5:6:672",
76 "RRA:AVERAGE:0.5:24:732",
77 "RRA:AVERAGE:0.5:144:1460");
78 $ERROR = RRDs::error;
79 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
80 }
81
82 # Temperaturlesen w�rde die Platte aufwecken!!!
83 if (!$standby){
84 $temp = 0;
85 my $smart_output = '';
86 system("$path_smartctl -iHA -d ata /dev/$disk > /tmp/smartctl_out_hddtemp-$disk");
87 if ( -e "/tmp/smartctl_out_hddtemp-".$array[$#array] ){
88 my $hdd_output = `cat /tmp/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`;
89 my @t = split(/\s+/,$hdd_output);
90 $temp = $t[9];
91 }else{$temp = 0;}
92 print "Temperature for ".$array[$#array]."->".$temp."<-\n";
93 # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
94 if ($temp){
95 RRDs::update ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
96 $ERROR = RRDs::error;
97 print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
98 }
99 }
52345790
MT
100}
101
6c33dc5c
AF
102## Update vnstat
103system ('/usr/bin/vnstat -u');
3bc32eab 104
350b52c5 105my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
3bc32eab 106system("unlink /tmp/hddstatus && touch /tmp/hddstatus");
350b52c5 107foreach (@disks){
5468f102
CS
108 my $disk = $_;
109 chomp $disk;
110 print "Working on disk ".$disk.".\n";
111
112 my $status = "";
113 my $diskstats = "";
114 my $newdiskstats = "";
115 my @array = split(/\//,$disk);
116
117 $diskstats = `cat /tmp/hddstats-$array[$#array]`;
118 chomp $diskstats;
119 my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
120 chomp $newdiskstats;
121 my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
122 chomp $status;
123
124 if ($status !~/standby/ || $diskstats ne $newdiskstats){
125 if (-e "/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);}
126 }
127
128 if (-e "/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";}
129 else{$status = " active\n";}
130
131 open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
132 print DATEI $disk."-".$status;
133 close(DATEI);
134
135 updatehdddata($disk);
6c666a3b 136}