summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpbuetow <puppet@mx.buetow.org>2012-07-04 19:31:27 +0200
committerpbuetow <puppet@mx.buetow.org>2012-07-04 19:31:27 +0200
commit5692c8a1210340ed38bbbf4c1097b4609f25de7b (patch)
treed7f6e4a9b54e71dd8b9205c6e79e78cb8b13d9e1
parent103ed622771688896728372f40997016aade144e (diff)
add some nice features and tweaks
-rw-r--r--lib/Loadbars/HelpDispatch.pm15
-rw-r--r--lib/Loadbars/Main.pm60
-rw-r--r--lib/Loadbars/Shared.pm2
3 files changed, 61 insertions, 16 deletions
diff --git a/lib/Loadbars/HelpDispatch.pm b/lib/Loadbars/HelpDispatch.pm
index 97216e2..36e0e78 100644
--- a/lib/Loadbars/HelpDispatch.pm
+++ b/lib/Loadbars/HelpDispatch.pm
@@ -10,7 +10,7 @@ sub create () {
my $hosts = '';
my $textdesc = <<END;
- CPU stuff:
+CPU stuff:
st = Steal in % [see man proc] (extended)
Color: Red
gt = Guest in % [see man proc] (extended)
@@ -39,6 +39,15 @@ Memory stuff:
Color: Dark grey
Swp: System swap usage in %
Color: Grey
+Network stuff:
+ Rxb: Incoming (received) traffic in %
+ Color: Light green, normal green if >100% while using low netlink ref
+ Bar comes from top and is half width
+ Txb: Outgoing (transmitted) traffic in %
+ Color: Light green, normal green if >100% while using low netlink ref
+ Bar comes from bottom and is half width
+ When network bar is red: The interface does not exist on the specific
+ remote host.
Config file support:
Loadbars tries to read ~/.loadbarsrc and it's possible to configure any
option you find in --help but without leading '--'. For comments just use
@@ -116,13 +125,13 @@ END
netlink_hot_up => {
menupos => 9,
cmd => 'f',
- help => 'Doubles net interface link speed reference',
+ help => 'Increases net interface link speed reference by factor 10',
mode => 1
},
netlink_hot_dn => {
menupos => 10,
cmd => 'v',
- help => 'Halfs net interface link speed reference',
+ help => 'Decreases net interface link speed reference by factor 10',
mode => 1
},
diff --git a/lib/Loadbars/Main.pm b/lib/Loadbars/Main.pm
index e464059..9213627 100644
--- a/lib/Loadbars/Main.pm
+++ b/lib/Loadbars/Main.pm
@@ -36,6 +36,10 @@ sub percentage ($$) {
return int( null($part) / notnull( null($total) / 100 ) );
}
+sub max_100 ($) {
+ return $_[0] > 100 ? 100 : $_[0];
+}
+
sub percentage_norm ($$$) {
my ( $total, $part, $norm ) = @_;
@@ -309,6 +313,9 @@ sub net_link () {
sub net_next_int ($;$) {
my ( $num, $initial_device_flag ) = @_;
+
+ return $C{netint} if defined $initial_device_flag && $C{netint} ne '';
+
my $int = undef;
for ( ; ; ) {
@@ -594,15 +601,16 @@ sub loop ($@) {
}
elsif ( $key_name eq 'f' ) {
- $net_max_bytes *= 2;
+ $net_max_bytes *= 10;
display_info "Set net interface speed reference to "
. ( $net_max_bytes / $I{bytes_mbit} )
. 'mbit/s';
}
elsif ( $key_name eq 'v' ) {
- $net_max_bytes = int( $net_max_bytes / 2 );
+ $net_max_bytes = int( $net_max_bytes / 10 );
+ $net_max_bytes = $I{bytes_mbit} if $net_max_bytes < $I{bytes_mbit};
display_info "Set net interface speed reference to "
- . ( $net_max_bytes / $I{bytes_mbit} )
+ . int ( $net_max_bytes / $I{bytes_mbit} )
. 'mbit/s';
}
@@ -847,6 +855,7 @@ sub loop ($@) {
$add_x += $width + 1;
my $key = "$host;$net_int";
+ my %heights;
if ( exists $NETSTATS{$key} ) {
@@ -896,12 +905,15 @@ sub loop ($@) {
$net_last_value{"$key;tper"} = $tnet_per;
}
- my %heights = (
- NetUsed => $net_per * ( $C{height} / 100 ),
- NetFree => ( 100 - $net_per ) *
+ my $net_per_100 = max_100 $net_per;
+ my $tnet_per_100 = max_100 $tnet_per;
+
+ %heights = (
+ NetUsed => $net_per_100 * ( $C{height} / 100 ),
+ NetFree => ( 100 - $net_per_100 ) *
( $C{height} / 100 ),
- TNetFree => $tnet_per * ( $C{height} / 100 ),
- TNetUsed => ( 100 - $tnet_per ) *
+ TNetFree => $tnet_per_100 * ( $C{height} / 100 ),
+ TNetUsed => ( 100 - $tnet_per_100 ) *
( $C{height} / 100 ),
);
@@ -931,13 +943,18 @@ sub loop ($@) {
$app->fill( $rect_netused, Loadbars::Constants->BLACK );
$app->fill( $rect_netfree,
- Loadbars::Constants->LIGHT_GREEN );
+ $net_per > 100
+ ? Loadbars::Constants->GREEN
+ : Loadbars::Constants->LIGHT_GREEN );
$app->fill( $rect_tnetused,
- Loadbars::Constants->LIGHT_GREEN );
+ $tnet_per > 100
+ ? Loadbars::Constants->GREEN
+ : Loadbars::Constants->LIGHT_GREEN );
$app->fill( $rect_tnetfree,
Loadbars::Constants->BLACK );
+
if ( $C{showtext} ) {
my $y_ = 5;
$app->print( $x + $add_x, $y_, $net_int );
@@ -946,7 +963,7 @@ sub loop ($@) {
$app->print(
$x + $add_x,
$y_ += $sdl_font_height,
- sprintf '%02d%%',
+ sprintf '%02d',
($net_per)
);
$app->print( $x + $add_x,
@@ -954,12 +971,31 @@ sub loop ($@) {
$app->print(
$x + $add_x,
$y_ += $sdl_font_height,
- sprintf '%02d%%',
+ sprintf '%02d',
($tnet_per)
);
}
+ # No netstats available for this host;device pair.
+ } else {
+ $rect_netused->width($width);
+ $rect_netused->height( $C{height} );
+ $rect_netused->x( $x + $add_x );
+ $rect_netused->y($y);
+
+ $app->fill( $rect_netused, Loadbars::Constants->RED );
+ $app->fill( $rect_tnetused, Loadbars::Constants->RED );
+ $app->fill( $rect_netfree, Loadbars::Constants->RED );
+ $app->fill( $rect_tnetfree, Loadbars::Constants->RED );
+
+ if ( $C{showtext} ) {
+ my $y_ = 5;
+ $app->print( $x + $add_x, $y_, $net_int);
+ $app->print( $x + $add_x,
+ $y_ += $sdl_font_height, 'n/a' );
+ }
}
+
}
if ( $C{showcores} ) {
diff --git a/lib/Loadbars/Shared.pm b/lib/Loadbars/Shared.pm
index 8630276..0aa302d 100644
--- a/lib/Loadbars/Shared.pm
+++ b/lib/Loadbars/Shared.pm
@@ -49,7 +49,7 @@ our %I : shared;
height => 230,
maxwidth => 1250,
netaverage => 15,
- netint => 'eth0',
+ netint => '',
netlink => 'gbit',
showcores => 0,
showmem => 0,