]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - src/scripts/makegraphs
3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2008 Michael Tremer & Christian Schmidt #
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. #
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. #
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/>. #
21 ###############################################################################
27 require "/var/ipfire/general-functions.pl";
28 require "${General::swroot}/lang.pl";
31 $ENV{PATH
}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
34 my $path_smartctl = "/usr/sbin/smartctl";
37 my %mainsettings = ();
38 &General
::readhash
("${General::swroot}/main/settings", \
%mainsettings);
39 &General
::readhash
("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \
%color);
44 my @array = split(/\//,$disk);
46 if ( ! -e
"$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd"){
47 # database did not exist -> create
48 RRDs
::create
("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300",
49 "DS:standby:GAUGE:600:0:1",
50 "RRA:AVERAGE:0.5:1:576",
51 "RRA:AVERAGE:0.5:6:672",
52 "RRA:AVERAGE:0.5:24:732",
53 "RRA:AVERAGE:0.5:144:1460");
55 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
58 if (-e
"/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
61 RRDs
::update
("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
63 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
65 if ( ! -e
"$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){
66 # database did not exist -> create
67 RRDs
::create
("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300",
68 "DS:temperature:GAUGE:600:0:100",
69 "RRA:AVERAGE:0.5:1:576",
70 "RRA:AVERAGE:0.5:6:672",
71 "RRA:AVERAGE:0.5:24:732",
72 "RRA:AVERAGE:0.5:144:1460");
74 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
77 # Temperaturlesen w�rde die Platte aufwecken!!!
80 my $smart_output = '';
81 system("$path_smartctl -iHA -d ata /dev/$disk > /tmp/smartctl_out_hddtemp-$disk");
82 if ( -e
"/tmp/smartctl_out_hddtemp-".$array[$#array] ){
83 my $hdd_output = `cat /tmp/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`;
84 my @t = split(/\s+/,$hdd_output);
87 print "Temperature for ".$array[$#array]."->".$temp."<-\n";
88 # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
90 RRDs
::update
("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
92 print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
98 system ('/usr/bin/vnstat -u');
100 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
101 system("unlink /tmp/hddstatus && touch /tmp/hddstatus");
105 print "Working on disk ".$disk.".\n";
109 my $newdiskstats = "";
110 my @array = split(/\//,$disk);
112 $diskstats = `cat /tmp/hddstats-$array[$#array]`;
114 my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
116 my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
119 if ($status !~/standby/ || $diskstats ne $newdiskstats){
120 if (-e
"/tmp/hddshutdown-".$array[$#array]){system("unlink /tmp/hddshutdown-".$array[$#array]);}
123 if (-e
"/tmp/hddshutdown-".$array[$#array]){$status = " standby\n";}
124 else{$status = " active\n";}
126 open(DATEI
, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
127 print DATEI
$disk."-".$status;
130 updatehdddata
($disk);