diff options
| author | pbuetow <puppet@mx.buetow.org> | 2012-06-29 09:20:25 +0200 |
|---|---|---|
| committer | pbuetow <puppet@mx.buetow.org> | 2012-06-29 09:20:25 +0200 |
| commit | b92c885ca42785613412c6078ba15be6a8a81a50 (patch) | |
| tree | 08fff44e73d3f307592163d01cfbf0510d77f299 | |
| parent | e006f9a5d226d9ce19ccea9e631f9bb66686a4b7 (diff) | |
rudimentary netstats work now
| -rw-r--r-- | lib/Loadbars/Constants.pm | 4 | ||||
| -rw-r--r-- | lib/Loadbars/Main.pm | 37 | ||||
| -rw-r--r-- | lib/Loadbars/Shared.pm | 2 |
3 files changed, 32 insertions, 11 deletions
diff --git a/lib/Loadbars/Constants.pm b/lib/Loadbars/Constants.pm index f7cda36..7ea0439 100644 --- a/lib/Loadbars/Constants.pm +++ b/lib/Loadbars/Constants.pm @@ -17,7 +17,7 @@ use constant { LIGHT_BLUE0 => SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0xcc ), BLUE => SDL::Color->new( -r => 0x00, -g => 0x00, -b => 0x88 ), GREEN => SDL::Color->new( -r => 0x00, -g => 0x90, -b => 0x00 ), - LIGHT_GREEN => SDL::Color->new( -r => 0x00, -g => 0xb0, -b => 0x00 ), + LIGHT_GREEN => SDL::Color->new( -r => 0x00, -g => 0xf0, -b => 0x00 ), ORANGE => SDL::Color->new( -r => 0xff, -g => 0x70, -b => 0x00 ), PURPLE => SDL::Color->new( -r => 0xa0, -g => 0x20, -b => 0xf0 ), RED => SDL::Color->new( -r => 0xff, -g => 0x00, -b => 0x00 ), @@ -31,7 +31,7 @@ use constant { USER_ORANGE => 70, USER_YELLOW0 => 50, INTERVAL => 0.14, - INTERVAL_NET => 1.0, + INTERVAL_NET => 3.0, INTERVAL_MEM => 1.0, INTERVAL_SDL => 0.14, INTERVAL_SDL_WARN => 1.0, diff --git a/lib/Loadbars/Main.pm b/lib/Loadbars/Main.pm index 34ad8fa..deb3303 100644 --- a/lib/Loadbars/Main.pm +++ b/lib/Loadbars/Main.pm @@ -36,6 +36,12 @@ sub percentage ($$) { return int( null($part) / notnull( null($total) / 100 ) ); } +sub percentage_norm ($$$) { + my ( $total, $part, $norm ) = @_; + + return int( null($part) / notnull( null($total) / 100 ) / notnull $norm); +} + sub norm ($) { my $n = shift; @@ -127,6 +133,11 @@ sub threads_stats ($;$) { close FH; } + sub mem { + printf qq(M MEMSTATS\n); + cat(qq(/proc/meminfo)); + } + sub net { printf qq(M NETSTATS\n); open FH, qq(/proc/net/dev); @@ -148,9 +159,7 @@ sub threads_stats ($;$) { for (1..10000) { load(); - - printf qq(M MEMSTATS\n); - cat(qq(/proc/meminfo)); + mem(); net(); printf qq(M CPUSTATS\n); @@ -220,6 +229,7 @@ REMOTECODE elsif ( $mode == 3 ) { my ($int, @stats) = split ':', $_; $NETSTATS{"$host;$int"} = "@stats"; + $NETSTATS{"$host;$int;stamp"} = Time::HiRes::time(); $NETSTATS_INT{$int} = 1 unless defined $NETSTATS_INT{$int}; $NETSTATS_HAS{$host} = 1 unless defined $NETSTATS_HAS{$host}; } @@ -273,7 +283,6 @@ sub net_parse ($) { my ($line_r) = shift; my ($a, $b) = split ' ', $$line_r; - my %a = map { my ($k, $v) = split '=', $_; $k => $v; @@ -402,6 +411,7 @@ sub loop ($@) { my %cpu_max; my %net_history; + my %net_history_stamps; my $net_max_bytes = Loadbars::Constants->BYTES_GBIT; @@ -750,8 +760,18 @@ sub loop ($@) { if (exists $NETSTATS{$key}) { - $net_history{$key} = [net_parse \$NETSTATS{$key}] - unless exists $net_history{$key}; + unless (exists $net_history{$key}) { + $net_history{$key} = [net_parse \$NETSTATS{$key}]; + $net_history_stamps{$key} = [$NETSTATS{"$key;stamp"}]; + } + + my $now_stat_stamp = $NETSTATS{"$key;stamp"}; + my $prev_stat_stamp = $net_history_stamps{$key}[0]; + + my $net_max = $net_max_bytes * ($now_stat_stamp - $prev_stat_stamp); + + push @{$net_history_stamps{$key}}, $now_stat_stamp; + shift @{$net_history_stamps{$key}} while $C{netaverage} < @{$net_history_stamps{$key}}; my $now_stat_r = net_parse \$NETSTATS{$key}; my $prev_stat_r = $net_history{$key}[0]; @@ -759,10 +779,11 @@ sub loop ($@) { push @{$net_history{$key}}, $now_stat_r; shift @{$net_history{$key}} while $C{netaverage} < @{$net_history{$key}}; + my $diff_stat_r = net_diff $now_stat_r->[0], $prev_stat_r->[0]; - my $net_per = percentage $net_max_bytes, $diff_stat_r->{b}; - my $tnet_per = percentage $net_max_bytes, $diff_stat_r->{tb}; + my $net_per = percentage($net_max, $diff_stat_r->{b}); + my $tnet_per = percentage($net_max, $diff_stat_r->{tb}); my %heights = ( NetUsed => $net_per * ( $C{height} / 100 ), diff --git a/lib/Loadbars/Shared.pm b/lib/Loadbars/Shared.pm index d049800..6ef7d68 100644 --- a/lib/Loadbars/Shared.pm +++ b/lib/Loadbars/Shared.pm @@ -42,7 +42,7 @@ our %I : shared; %C = ( title => undef, cpuaverage => 15, - netaverage => 5, + netaverage => 15, barwidth => 35, extended => 0, factor => 1, |
