]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/scripts/makegraphs
Changed makegraphs to rrdlog
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
CommitLineData
cd1a2927
MT
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############################################################################
60cbd6e7 24
cd1a2927
MT
25use strict;
26#use warnings;
27
28use RRDs;
986e08d9 29require "/var/ipfire/general-functions.pl";
cd1a2927
MT
30require "${General::swroot}/lang.pl";
31
cd1a2927 32# Settings
cd1a2927 33$ENV{PATH}="/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin";
a68fedca 34my $temp = '';
52345790 35my $ERROR;
52345790
MT
36my $path_smartctl = "/usr/sbin/smartctl";
37
4b4aec3a
CS
38my %color = ();
39my %mainsettings = ();
40&General::readhash("${General::swroot}/main/settings", \%mainsettings);
41&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color);
52345790 42
eecaf145 43sub updatehdddata
60cbd6e7 44{
e1e3dbe5
CS
45 my $disk = $_[0];
46 my $standby;
47 my @array = split(/\//,$disk);
48
49 if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd"){
50 # database did not exist -> create
42ae148e 51 RRDs::create ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "--step=300",
e1e3dbe5
CS
52 "DS:standby:GAUGE:600:0:1",
53 "RRA:AVERAGE:0.5:1:576",
54 "RRA:AVERAGE:0.5:6:672",
55 "RRA:AVERAGE:0.5:24:732",
56 "RRA:AVERAGE:0.5:144:1460");
57 $ERROR = RRDs::error;
58 print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
59 }
60
61 if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
62 else {$standby = 0;}
63
42ae148e 64 RRDs::update ("$mainsettings{'RRDLOG'}/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
e1e3dbe5
CS
65 $ERROR = RRDs::error;
66 print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
67
42ae148e 68 if ( ! -e "$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd"){
e1e3dbe5 69 # database did not exist -> create
42ae148e 70 RRDs::create ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "--step=300",
e1e3dbe5
CS
71 "DS:temperature:GAUGE:600:0:100",
72 "RRA:AVERAGE:0.5:1:576",
73 "RRA:AVERAGE:0.5:6:672",
74 "RRA:AVERAGE:0.5:24:732",
75 "RRA:AVERAGE:0.5:144:1460");
76 $ERROR = RRDs::error;
77 print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
78 }
79
80 # Temperaturlesen w�rde die Platte aufwecken!!!
81 if (!$standby){
82 $temp = 0;
83 my $smart_output = '';
84 system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
85 if ( -e "/var/log/smartctl_out_hddtemp-".$array[$#array] ){
86 my $hdd_output = `cat /var/log/smartctl_out_hddtemp-$array[$#array] | grep Temperature_`;
87 my @t = split(/\s+/,$hdd_output);
88 $temp = $t[9];
89 }else{$temp = 0;}
90 print "Temperature for ".$array[$#array]."->".$temp."<-\n";
91 # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
92 if ($temp){
42ae148e 93 RRDs::update ("$mainsettings{'RRDLOG'}/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
e1e3dbe5
CS
94 $ERROR = RRDs::error;
95 print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
96 }
97 }
52345790
MT
98}
99
cd1a2927 100## Update ipac logs
c130ab12 101#system ('/usr/sbin/fetchipac');
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){
e1e3dbe5
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}