summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow (lxpbuetow) <paul.buetow@1und1.de>2011-11-18 14:46:17 +0100
committerPaul Buetow (lxpbuetow) <paul.buetow@1und1.de>2011-11-18 14:46:17 +0100
commitbe34edcee2100053803dbc56a182a6f17e65b83d (patch)
tree4502bc02104b69109cba0a500eb373dc3b0e701b
parent664bba80b91f03966d1b2fe9101e34327dcd1974 (diff)
Horizontal max. line is now colored
-rwxr-xr-xloadbars.pl35
1 files changed, 22 insertions, 13 deletions
diff --git a/loadbars.pl b/loadbars.pl
index 8148830..98992f5 100755
--- a/loadbars.pl
+++ b/loadbars.pl
@@ -169,14 +169,14 @@ sub normalize_loads (%) {
sub get_cpuaverage ($@) {
my ($factor, @loads) = @_;
- my (%cpucurrent, %cpuaverage);
+ my (%cpumax, %cpuaverage);
for my $l (@loads) {
for (keys %$l) {
$cpuaverage{$_} += $l->{$_};
- $cpucurrent{$_} = $l->{$_}
- if not exists $cpucurrent{$_} or $cpucurrent{$_} < $l->{$_};
+ $cpumax{$_} = $l->{$_}
+ if not exists $cpumax{$_} or $cpumax{$_} < $l->{$_};
}
}
@@ -184,10 +184,10 @@ sub get_cpuaverage ($@) {
for (keys %cpuaverage) {
$cpuaverage{$_} /= $div;
- $cpucurrent{$_} /= $factor;
+ $cpumax{$_} /= $factor;
}
- return (\%cpucurrent, \%cpuaverage);
+ return (\%cpumax, \%cpuaverage);
}
sub draw_background ($$) {
@@ -356,17 +356,17 @@ sub main_loop ($@) {
push @{$last_loads{$key}}, \%loads;
shift @{$last_loads{$key}} while @{$last_loads{$key}} >= $C{average};
- my ($cpucurrent, $cpuaverage) = get_cpuaverage $C{factor}, @{$last_loads{$key}};
+ my ($cpumax, $cpuaverage) = get_cpuaverage $C{factor}, @{$last_loads{$key}};
my %heights = map {
$_ => defined $cpuaverage->{$_} ? $cpuaverage->{$_} * ($C{height}/100) : 1
} keys %$cpuaverage;
- my %currentheights = map {
- $_ => defined $cpucurrent->{$_} ? $cpucurrent->{$_} * ($C{height}/100) : 1
+ my %maxheights = map {
+ $_ => defined $cpumax->{$_} ? $cpumax->{$_} * ($C{height}/100) : 1
- } keys %$cpucurrent;
+ } keys %$cpumax;
my $is_host_summary = exists $is_host_summary{$host};
@@ -414,14 +414,23 @@ sub main_loop ($@) {
$rect_max->width($width);
$rect_max->height(1);
$rect_max->x($x);
- $rect_max->y($C{height} - $currentheights{system} - $currentheights{user});
+ $rect_max->y($C{height} - $maxheights{system} - $maxheights{user});
my $system_n_user = sum @{$cpuaverage}{qw(user system)};
+ my $max_system_n_user = sum @{$cpumax}{qw(user system)};
$app->fill($rect_iowait, Loadbars::BLACK);
$app->fill($rect_nice, Loadbars::GREEN);
- #$app->fill($rect_system, Loadbars::BLUE);
- $app->fill($rect_max, Loadbars::GREY);
+ $app->fill($rect_max, $max_system_n_user > Loadbars::USER_WHITE ? Loadbars::WHITE
+ : ($max_system_n_user > Loadbars::USER_RED ? Loadbars::RED
+ : ($max_system_n_user > Loadbars::USER_ORANGE ? Loadbars::ORANGE
+ : ($max_system_n_user > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0
+ : (Loadbars::YELLOW)))));
+ $app->fill($rect_user, $system_n_user > Loadbars::USER_WHITE ? Loadbars::WHITE
+ : ($system_n_user > Loadbars::USER_RED ? Loadbars::RED
+ : ($system_n_user > Loadbars::USER_ORANGE ? Loadbars::ORANGE
+ : ($system_n_user > Loadbars::USER_YELLOW0 ? Loadbars::YELLOW0
+ : (Loadbars::YELLOW)))));
$app->fill($rect_system, $cpuaverage->{system} > Loadbars::SYSTEM_PURPLE
? Loadbars::PURPLE
: Loadbars::BLUE);
@@ -521,7 +530,7 @@ Explanation colors:
Orange: User usage if system & user cpu is >70%
White: Usage usage if system & user cpu is >99%
Green: Nice cpu usage
- Grey 1px horizontal: Maximum sy+us cpu of last 'avg' samples
+ 1px horizontal line: Maximum sy+us cpu of last 'avg' samples
Explanation text display:
ni = Nice cpu usage in %
us = User cpu usage in %