summaryrefslogtreecommitdiff
path: root/cpupload.pl
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-11-06 09:16:47 +0000
committerPaul Buetow <paul@buetow.org>2010-11-06 09:16:47 +0000
commit9d10be98ad7133b98d3cba99511eae35873b044c (patch)
tree1e4b1996d455358ed2d4867fa269a939fbf4141c /cpupload.pl
parentf561c31faf96ac385e184ac022298ef1450dcc30 (diff)
jo
Diffstat (limited to 'cpupload.pl')
-rwxr-xr-xcpupload.pl58
1 files changed, 28 insertions, 30 deletions
diff --git a/cpupload.pl b/cpupload.pl
index 8fdc711..2315459 100755
--- a/cpupload.pl
+++ b/cpupload.pl
@@ -7,6 +7,9 @@ use warnings;
use IPC::Open2;
use Data::Dumper;
+use Tk;
+use Tk::Graph;
+
use threads;
use threads::shared;
@@ -17,8 +20,6 @@ my %GLOBAL_CONF :shared;
%GLOBAL_CONF = (
events => 20,
- header => 10,
- size => 10,
'sleep' => 1,
);
@@ -77,42 +78,40 @@ sub get_remote_stat ($) {
}
}
-sub display_stats () {
- $SIG{STOP} = sub {
- say "Shutting down display_stats";
- threads->exit();
- };
+sub graph_stats ($) {
+ my $mw = shift;
- my $size = $GLOBAL_CONF{size};
- my $line_counter = $GLOBAL_CONF{header} - 1;
+ my $data = { };
+ my $ca = $mw->Graph(-type => 'BARS')->pack(-expand => 1, -fill => 'both');
- # Wait until first results are available
- sleep 1 until %GLOBAL_STATS;
+ $ca->configure(-variable => $data);
+ $mw->repeat($GLOBAL_CONF{sleep}*100, sub {
+ for my $key (sort keys %GLOBAL_STATS) {
+ my ($host, $name) = split ';', $key;
+ $host = substr $host, 0, 16 if length $host > 16;
+ $data->{"$host $name"} = $GLOBAL_STATS{$key};
+ }
- my $header_closure = sub {
- return if ++$line_counter % $GLOBAL_CONF{header};
- $line_counter = 0;
+ $ca->set($data);
+ }
+ );
- my (@header) = ('', '');
+ return undef;
+}
- for my $key (sort keys %GLOBAL_STATS) {
- my ($host, $name) = split ';', $key;
- $header[0] .= sprintf "%${size}s ", $host;
- $header[1] .= sprintf "%${size}s ", $name;
- }
+sub display_stats () {
+ my $mw = MainWindow->new;
- say @header;
+ $SIG{STOP} = sub {
+ say "Shutting down display_stats";
+ threads->exit();
};
- loop {
- $header_closure->();
-
- my $line = '';
- $line .= sprintf "%${size}d", $GLOBAL_STATS{$_} for sort keys %GLOBAL_STATS;
- say $line;
+ # Wait until first results are available
+ sleep 1 until %GLOBAL_STATS;
+ graph_stats $mw;
- sleep $GLOBAL_CONF{sleep};
- }
+ MainLoop;
}
sub main () {
@@ -124,7 +123,6 @@ sub main () {
/^q/ && last;
/^s/ && do { $GLOBAL_CONF{sleep} = <STDIN> };
/^e/ && do { $GLOBAL_CONF{events} = <STDIN> };
- /^h/ && do { $GLOBAL_CONF{header} = <STDIN> };
}
for (@threads) {