]> git.ipfire.org Git - people/ms/ipfire-2.x.git/commitdiff
speed.cgi: replave parsing of ip show output
authorArne Fitzenreiter <arne_f@ipfire.org>
Mon, 25 Oct 2021 10:58:10 +0000 (12:58 +0200)
committerArne Fitzenreiter <arne_f@ipfire.org>
Mon, 25 Oct 2021 10:58:10 +0000 (12:58 +0200)
latest ipfroute2 update change the output so this repkace it by reading /sys/class/net/*/statistics

Signed-off-by: Arne Fitzenreiter <arne_f@ipfire.org>
config/qos/makeqosscripts.pl
html/cgi-bin/speed.cgi

index 0694bb78cfd05eb8878e735ae61677c87c18b8ce..878e4bb43e6972c810062fe73fbed0d5ad649f86 100644 (file)
@@ -4,7 +4,7 @@
 # IPFire.org - A linux based firewall                                         #
 # Copyright (C) 2007-2021  IPFire Team  <info@ipfire.org>                     #
 #                                                                             #
-# This program is free software: you can redistribute it and/or modify        #
+# This program is free software: you c:an redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
 # the Free Software Foundation, either version 3 of the License, or           #
 # (at your option) any later version.                                         #
index 651c3c0b3137b66b9e285266c2a6abf3b5cb3753..d4b83df4f61349d9f9399f236b63606f12449877 100644 (file)
@@ -2,7 +2,7 @@
 ###############################################################################
 #                                                                             #
 # IPFire.org - A linux based firewall                                         #
-# Copyright (C) 2007  Michael Tremer & Christian Schmidt                      #
+# Copyright (C) 2007-2021  IPFire Twan  <info@ipfire.org>                     #
 #                                                                             #
 # This program is free software: you can redistribute it and/or modify        #
 # it under the terms of the GNU General Public License as published by        #
 # high system load                                                            #
 ###########################################OA##################################
 #
-# Returns the output of a shell command
-sub General__system_output($) {
-    my @command = @_;
-    my $pid;
-    my @output = ();
-
-    unless ($pid = open(OUTPUT, "-|")) {
-            open(STDERR, ">&STDOUT");
-            exec { ${command[0]} } @command;
-            die "Could not execute @command: $!";
-    }
-
-    waitpid($pid, 0);
-
-    while (<OUTPUT>) {
-            push(@output, $_);
-    }
-
-    close(OUTPUT);
-    return @output;
-}
-#
 # Function which will return the used interface for the red network zone (red0, ppp0, etc).
 sub General__get_red_interface() {
 
@@ -79,21 +57,16 @@ foreach $field (@fields) {
 }
 
 my $interface = &General__get_red_interface();
-my @data_now = &General__system_output("ip", "-s", "link", "show", "$interface");
 
-my $lastline;
-my $rxb_now = 0;
-my $txb_now = 0;
-foreach (@data_now) {
-       if ( $lastline =~ /RX/ ) {
-               @fields = split(/ /, $_);
-               $rxb_now = $fields[4];
-       } elsif ( $lastline =~ /TX/ ) {
-               @fields = split(/ /, $_);
-               $txb_now = $fields[4];
-       }
-       $lastline = $_;
-}
+open(RX, "/sys/class/net/$interface/statistics/rx_bytes") or die "Could not open /sys/class/net/$interface/statistics/rx_bytes";
+my $rxb_now = <RX>;
+close(RX);
+chomp $rxb_now;
+
+open(TX, "/sys/class/net/$interface/statistics/tx_bytes") or die "Could not open /sys/class/net/$interface/statistics/tx_bytes";
+my $txb_now = <TX>;
+close(TX);
+chomp $txb_now;
 
 my ($rx_kbs, $tx_kbs);
 my $rxb_diff   = $rxb_now - $rxb_last;