#!/usr/bin/perl -w use strict; use Tk; # CPAN use Tk::Graph; # CPAN my $HOST = "blue.stonehenge.comm"; my $mw = MainWindow->new; ## create the Graph widget: my $graph = $mw->Graph ( -type => 'LINE', -linewidth => 3, -look => 60, -sortnames => 'alpha', -legend => 0, -headroom => 10, -ylabel => 'load', -xlabel => '5 sec units', -yformat => '%.2f', -config => { av_01 => { -title => 'One', -color => 'red', }, av_05 => { -title => 'Five', -color => 'orange', }, av_15 => { -title => 'Fifteen', -color => 'yellow', }, }, ); $graph->pack(-expand => 1, -fill => 'both'); ## setup the uptime process open UPTIME, "ssh $HOST 'sh -c \"while uptime; do sleep 5; done\"'|" or die "child: $!"; $mw->fileevent(\*UPTIME, readable => \&uptime_ready_to_read); BEGIN { my $buffer = ""; sub uptime_ready_to_read { sysread(\*UPTIME, $buffer, 1024, length $buffer); while ($buffer =~ s/^(.*)\n//) { my $input = $1; my ($one, $five, $fifteen) = $input =~ /load av[^0-9.]+([0-9.]+)[^0-9.]+([0-9.]+)[^0-9.]+([0-9.]+)$/ or die "cannot grok $input"; ## warn "saw $one $five $fifteen"; $mw->configure(-title => "$HOST: $one, $five, $fifteen"); $graph->set({ av_01 => $one, av_05 => $five, av_15 => $fifteen }); } } } MainLoop;