]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - src/scripts/makegraphs
Samba default Freigabe angepasst
[people/pmueller/ipfire-2.x.git] / src / scripts / makegraphs
index c8a6bb3a8d94cb7f06e441ba2c2a081d9891b55a..92eba691b5ff1835fb2766c71a7393277f2ff111 100644 (file)
@@ -38,6 +38,8 @@ my %mbmon_settings = ();
 use Encode 'from_to';
 my %tr=();
 
+system("chmod 777 /srv/web/ipfire/html/graphs");
+
 # Force language back to English (ugly hack!)
 # Modified to only force if we are unable to convert charset 
 # from utf-8
@@ -233,8 +235,9 @@ sub updatememdata {
 sub updatediskdata {
         my $disk = $_[0];
         my ($readsect, $writesect, $trash);
-        if ( ! -e "$rrdlog/disk-$disk.rrd") {
-                RRDs::create ("$rrdlog/disk-$disk.rrd", "--step=300",
+                               my @array = split(/\//,$disk);
+        if ( ! -e "$rrdlog/disk-".$array[$#array].".rrd") {
+                RRDs::create ("$rrdlog/disk-".$array[$#array].".rrd", "--step=300",
                         "DS:readsect:COUNTER:600:0:5000000000",
                         "DS:writesect:COUNTER:600:0:5000000000",
                         "RRA:AVERAGE:0.5:1:576",
@@ -251,7 +254,7 @@ sub updatediskdata {
         print "\nread:".$readsect."write:".$writesect."\n";
 
         if ($readsect && $writesect) {
-                RRDs::update ("$rrdlog/disk-$disk.rrd",
+                RRDs::update ("$rrdlog/disk-".$array[$#array].".rrd",
                         "-t", "readsect:writesect",
                         "N:$readsect:$writesect");
                 $ERROR = RRDs::error;
@@ -374,13 +377,25 @@ sub updatelq {
         my $roundtrip=0;
         my $test=0;
 #       LQ_GATEWAY is the ip of your isp's public ip facing you
-        my $LQ_GATEWAY=`netstat -rn | grep ^0.0.0.0 | awk '{print \$2}'`;
-        my $NUMPINGS=10;
-        my $pingoutput = `ping -c $NUMPINGS -q $LQ_GATEWAY`;
-        chomp;
+        my $LQ_GATEWAY=`cat /var/ipfire/red/remote-ipaddress`;
+        chomp($LQ_GATEWAY);
+        my $NUMPINGS=5;
+        my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q $LQ_GATEWAY | tail -2`;
+        my @temp = split (/\/|\%|\s/, $pingoutput);
+        $packetloss = $temp[5];
+        $roundtrip = $temp[17];
+        
+        print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
+       
+        if ( $packetloss eq "100" ){
+        my $pingoutput = `/usr/bin/ping -w 10 -c $NUMPINGS -q ping.ipfire.org  | tail -2`;
         my @temp = split (/\/|\%|\s/, $pingoutput);
-        $packetloss   = $temp[17];
-        $roundtrip    = $temp[28];
+        $packetloss = $temp[5];
+        $roundtrip = $temp[17];
+        
+        print "Paketlos->".$packetloss."<-Roundtrip->".$roundtrip."<-\n";
+        }
+        
         RRDs::update ("$rrdlog/lq.rrd", "N:$packetloss:$roundtrip");
         $ERROR = RRDs::error;
         print "Error in RRD::update for line quality: $ERROR\n" if $ERROR;
@@ -389,76 +404,105 @@ sub updatelq {
 sub updatehdddata 
 {
   my $disk = $_[0];
-  if ( ! -e "$rrdlog/hddtemp-$disk.rrd") 
+  my $standby;
+  my @array = split(/\//,$disk);
+  
+  if ( ! -e "$rrdlog/hddshutdown-".$array[$#array].".rrd") 
   {
     # database did not exist -> create
-    RRDs::create ("$rrdlog/hddtemp-$disk.rrd", "--step=300",
-      "DS:temperature:GAUGE:600:0:100",
+    RRDs::create ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "--step=300",
+      "DS:standby:GAUGE:600:0:1",
       "RRA:AVERAGE:0.5:1:576",
       "RRA:AVERAGE:0.5:6:672",
       "RRA:AVERAGE:0.5:24:732",
       "RRA:AVERAGE:0.5:144:1460");
     $ERROR = RRDs::error;
-    print "Error in RRD::create for hdd-$disk: $ERROR\n" if $ERROR;
+    print "Error in RRD::create for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
   }
 
-  $temp = 0;
-  my $hdd_output = '';
-  my $smart_output = '';
+  if (-e "/tmp/hddshutdown-".$array[$#array]) {$standby = 1;}
+    else {$standby = 0;}
 
-  if ( -e "$path_smartctl" )
+  RRDs::update ("$rrdlog/hddshutdown-".$array[$#array].".rrd", "-t", "standby", "N:$standby");
+  $ERROR = RRDs::error;
+  print "Error in RRD::update for hddshutdown-".$array[$#array].": $ERROR\n" if $ERROR;
+
+  if ( ! -e "$rrdlog/hddtemp-".$array[$#array].".rrd") 
   {
-    system("$path_smartctl -iHA /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
+    # database did not exist -> create
+    RRDs::create ("$rrdlog/hddtemp-".$array[$#array].".rrd", "--step=300",
+      "DS:temperature:GAUGE:600:0:100",
+      "RRA:AVERAGE:0.5:1:576",
+      "RRA:AVERAGE:0.5:6:672",
+      "RRA:AVERAGE:0.5:24:732",
+      "RRA:AVERAGE:0.5:144:1460");
+    $ERROR = RRDs::error;
+    print "Error in RRD::create for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
   }
 
-  if ( -e "$path_hddtemp" )
+  # Temperaturlesen wÃrde die Platte aufwecken!!!
+  if (!$standby) 
   {
-    $hdd_output = `$path_hddtemp -qn /dev/$disk`;
-
-    # I know 4 response possible responses:
-    #
-    # /dev/harddisk: harddisk type: S.M.A.R.T. not available
-    # /dev/harddisk: harddisk type: no sensor
-    # /dev/harddisk: harddisk type: 37?C or ?F
-    # 37
-
-    if ( index($hdd_output, "S.M.A.R.T.") != -1 )
+    $temp = 0;
+    my $hdd_output = '';
+    my $smart_output = '';
+  
+    if ( -e "$path_smartctl" )
     {
-      $temp = 0;
+       system("$path_smartctl -iHA -d ata /dev/$disk > /var/log/smartctl_out_hddtemp-$disk");
     }
-    elsif ( index($hdd_output, "no sensor") != -1 )
+
+    if ( -e "$path_hddtemp" )
     {
-      $temp = 1;
+       $hdd_output = `$path_hddtemp -qn /dev/$disk`;
+    
+       # I know 4 response possible responses:
+       #
+       # /dev/harddisk: harddisk type: S.M.A.R.T. not available
+       # /dev/harddisk: harddisk type: no sensor
+       # /dev/harddisk: harddisk type: 37?C or ?F
+       # 37
+
+       if ( index($hdd_output, "S.M.A.R.T.") != -1 )
+       {
+           $temp = 0;
+       }
+       elsif ( index($hdd_output, "no sensor") != -1 )
+       {
+           $temp = 1;
+       }
+       elsif ( index($hdd_output, "$disk") != -1 )
+       {
+           $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
+           $temp = $1;
+       }
+       else
+       {
+           $hdd_output =~ /(\d+)\s/;
+           $temp = $1;
+       }
     }
-    elsif ( index($hdd_output, "$disk") != -1 )
+    elsif ( -e "/var/log/smartctl_out_hddtemp-".$array[$#array] )
     {
-      $hdd_output =~ /.*:.*:\s*(\d+).*\s/;
-      $temp = $1;
+       $hdd_output = `cat /var/log/smartctl_out_hddtemp-".$array[$#array]." | grep Temperature_`;
+       my @t = split(/\s+/,$hdd_output);
+       $temp = $t[9];
     }
     else
     {
-      $hdd_output =~ /(\d+)\s/;
-      $temp = $1;
+       $temp = 0;
     }
-  }
-  elsif ( -e "/var/log/smartctl_out_hddtemp-$disk" )
-  {
-    $hdd_output = `cat /var/log/smartctl_out_hddtemp-$disk | grep Temperature_`;
-    my @t = split(/\s+/,$hdd_output);
-    $temp = $t[9];
-  }
-  else
-  {
-    $temp = 0;
-  }
+  
 
-#  print "hdd  $hdd_output \n";
-#  print "temp $temp \n";
-
-  RRDs::update ("$rrdlog/hddtemp-$disk.rrd", "-t", "temperature", "N:$temp");
-
-  $ERROR = RRDs::error;
-  print "Error in RRD::update for hdd-$disk: $ERROR\n" if $ERROR;
+    print "Temperature for ".$array[$#array]."->".$temp."<-\n";
+    # Nur ins RDD wenn nicht 0 (sonst klappt die min Anzeige nicht)
+    if ($temp)
+    {
+       RRDs::update ("$rrdlog/hddtemp-".$array[$#array].".rrd", "-t", "temperature", "N:$temp");
+       $ERROR = RRDs::error;
+       print "Error in RRD::update for hdd-".$array[$#array].": $ERROR\n" if $ERROR;
+    }
+  }
 }
 
 sub updatembmondata 
@@ -547,13 +591,56 @@ updatecpudata();
 updateloaddata();
 updatememdata();
 
+###
+### HDD graphs
+###
+
+
 my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
+system("unlink /tmp/hddstatus && touch /tmp/hddstatus");
 print "\nFound following amount of disks:".@disks."\n";
 foreach (@disks){
 my $disk = $_;
 chomp $disk;
 print "Working on disk ".$disk.".\n";
+
+my $status = "";
+my $diskstats = "";
+my $newdiskstats = "";
+my @array = split(/\//,$disk);
+
+$diskstats = `cat /tmp/hddstats-$array[$#array]`;
+chomp $diskstats;
+my $newdiskstats = `/usr/bin/iostat -d -t $disk | tail -2 | head -1 | awk '{ print \$5","\$6}'`;
+chomp $newdiskstats;
+my $status = `hdparm -C /dev/$disk | tail -1 | cut -d: -f2`;
+chomp $status;
+
+if ($status !~/standby/ || $diskstats ne $newdiskstats)
+{
+    if (-e "/tmp/hddshutdown-".$array[$#array]) 
+    {
+      system("unlink /tmp/hddshutdown-".$array[$#array]);
+    }
+}
+
+if (-e "/tmp/hddshutdown-".$array[$#array])  
+{
+    $status = " standby\n";
+}
+else
+{
+    $status = " active\n";
+}
+
+
+open(DATEI, ">>/tmp/hddstatus") || die "Datei nicht gefunden";
+print DATEI $disk."-".$status;
+close(DATEI);
+
 updatediskdata($disk);
+updatehdddata($disk);
+
 }
 
 ###
@@ -567,16 +654,9 @@ updatefwhitsdata();
 updatelq();
 
 ###
-### HDDTEMP-Graphs for /dev/harddisk
+### Mbmon Data
 ###
-
-my @disks = `kudzu -qps -c HD | grep device: | cut -d" " -f2 | sort | uniq`;
-print "\nFound following amount of disks for hddtemp:".@disks."\n";
-foreach (@disks){
-my $disk = $_;
-chomp $disk;
-updatehdddata ($disk);
-}
+updatembmondata();
 
 ###
 ### Network Graphs