Here's something you might find useful. It's almost straight out of the Ram book, adapted to collect uptimes from little Perl uptime servers.

Here's the server that runs on each of the reporting machines...

#! /usr/bin/perl -w # # loadserv.pl # use strict ; use warnings ; use IO::Socket ; my $server_port = 2048 ; my $server = IO::Socket::INET->new( LocalPort => $server_port, Type => SOCK_STREAM, Reuse => 1, Listen => 10 ) or die "Couldn't be a TCP server on port $server_port: $@\n" ; while ( my $client = $server->accept() ) { print $client `uptime` ; } close( $server ) ;

...and here's the client that collects the uptime information from the various servers.

#! /usr/bin/perl -w # # loadclient.pl # use strict ; use warnings ; use IO::Socket ; my @remote_hosts = ( { addr => '127.0.0.1' }, { addr => '123.123.123.123' } ) ; my $remote_port = 2048 ; foreach my $host ( @remote_hosts ) { my $socket = IO::Socket::INET->new( PeerAddr => $host->{ addr }, PeerPort => $remote_port, Proto => 'tcp', Type => SOCK_STREAM ) or die "Couldn't connect to $host->{ addr }:$remote_port: $@\n" +; $host->{ uptime } = <$socket> ; } # The anonymous hashes in @remote_hosts now also contain # the uptimes of the servers listed.

This worked for me when I ran the server on my local machine as well as a remote machine. Hope this helps. Also, I'd really appreciate knowing what people think of this approach.


_______________
D a m n D i r t y A p e
Home Node | Email

In reply to Re: Getting the load of a remote mashine by DamnDirtyApe
in thread Getting the load of a remote mashine by mpegman

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.