]>
git.ipfire.org Git - ipfire-2.x.git/blob - src/scripts/makegraphs
3 ###############################################################################
5 # IPFire.org - A linux based firewall #
6 # Copyright (C) 2008-2013 IPFire Team <info@ipfire.org> #
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);
41 if ( $mainsettings{'RRDLOG'} eq "" ){
42 $mainsettings{'RRDLOG'}="/var/log/rrd";
43 &General
::writehash
("${General::swroot}/main/settings", \
%mainsettings);
49 my @array = split(/\//,$disk);
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");
60 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
63 if (-e
"/var/run/hddshutdown-".$array[$#array]) {$standby = 1;}
66 RRDs
::update
("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
68 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
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");
79 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
82 # Temperaturlesen w�rde die Platte aufwecken!!!
85 my $smart_output = '';
86 system("$path_smartctl -iHA /dev/$disk > /var/run/smartctl_out_hddtemp-$disk");
87 if ( -e
"/var/run/smartctl_out_hddtemp-".$array[$#array] ){
88 my $hdd_nvme = `grep "NVMe Log" /var/run/smartctl_out_hddtemp-$array[$#array]`;
89 if ( $hdd_nvme !~/NVMe Log/ ) {
90 my $hdd_output = `cat /var/run/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`;
91 my @t = split(/\s+/,$hdd_output);
94 my $hdd_output = `cat /var/run/smartctl_out_hddtemp-$array[$#array] | grep Temperature:`;
95 my @t = split(/\s+/,$hdd_output);
99 print "Temperature for ".$array[$#array]."->".$temp."<-\n";
100 # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
102 RRDs
::update
("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
103 $ERROR = RRDs
::error
;
104 print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
109 my @disks = `ls -1 /sys/block | grep -E '^sd|^nvme|^mmcblk|^xvd|^vd|^md' | sort | uniq`;
110 system("unlink /var/run/hddstatus 2>/dev/null && touch /var/run/hddstatus");
114 print "Working on disk ".$disk.".\n";
118 my $newdiskstats = "";
119 my @array = split(/\//,$disk);
121 $diskstats = `cat /var/run/hddstats-$array[$#array] 2>/dev/null`;
123 my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
125 my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
128 if ($status !~/standby/ || $diskstats ne $newdiskstats){
129 if (-e
"/var/run/hddshutdown-".$array[$#array]){system("unlink /var/run/hddshutdown-".$array[$#array]." 2>/dev/null");}
132 if (-e
"/var/run/hddshutdown-".$array[$#array]){$status = " standby\n";}
133 else{$status = " active\n";}
135 open(DATEI
, ">>/var/run/hddstatus") || die "Datei nicht gefunden";
136 print DATEI
$disk."-".$status;
139 updatehdddata
($disk);