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