#!/usr/bin/perl use warnings; use strict; use IO::Handle; use IO::Select; use Win32::SelectablePipe qw( winpipe ); use POSIX ":sys_wait_h"; use Net::Telnet; use Tk; use Tk::Graph; local ( *PIPE_READ, *PIPE_WRITE ); Win32::SelectablePipe::winpipe( *PIPE_READ, *PIPE_WRITE ); #pipe( *PIPE_READ, *PIPE_WRITE ); PIPE_READ->autoflush(1); PIPE_WRITE->autoflush(1); print "Pipes open\n"; if ( defined( my $pid = fork() ) ) { if ( $pid ) { my $io = new IO::Select( *PIPE_READ ); my $mw = MainWindow->new(); my $chart =$mw->Graph( -type => 'CIRCLE' )->pack; my ( $cpu_user, $cpu_sys, $cpu_idle, $cpu_wait, $data, @line ); while( waitpid( $pid, WNOHANG ) != -1 ) { if ( $io->can_read( 0 ) ) { print "Reading from handle\n"; $data = ; print "Got $data\n"; @line = split(/\s+/, $data ); ( $cpu_user, $cpu_sys, $cpu_idle, $cpu_wait ) = @line[14..17]; if ( $cpu_wait =~ /^\d+$/ and $cpu_idle =~ /^\d+$/ and $cpu_sys =~ /^\d+$/ and $cpu_user =~ /^\d+$/ ) { $chart->set( { 'Wait' => $cpu_wait, 'Idle' => $cpu_idle, 'System' => $cpu_sys, 'User' => $cpu_user } ); $chart->redraw; } } else { print "No data, sleeping\n"; sleep 0.1 } } } else { print "Username: "; my $username = ; print "Password: "; my $password = ; chomp $username; chomp $password; my $obj = new Net::Telnet( 'server.server.com' ); $obj->prompt( '/:\s*$/' ); $obj->login( $username, $password ); $obj->print( "vmstat 10" ); while ( my $line = $obj->getline() ) { print PIPE_WRITE $line; } $obj->cmd( "exit" ); } }