--- projects/cms/source/host/ihost-perl/ihost.pl 2001/02/01 09:10:52 1.11 +++ projects/cms/source/host/ihost-perl/ihost.pl 2001/02/05 17:38:38 1.15 @@ -2,6 +2,7 @@ # ----------------------------------------------------------- # Perl i-scream Host. +# http://www.i-scream.org.uk # # An all-in-one script to act as an i-scream host on # a typical Unix/Linux box. You may adapt the data-gathering @@ -9,7 +10,7 @@ # - pjm2@ukc.ac.uk # # $Author: pjm2 $ -# $Id: ihost.pl,v 1.11 2001/02/01 09:10:52 pjm2 Exp $ +# $Id: ihost.pl,v 1.15 2001/02/05 17:38:38 pjm2 Exp $ #------------------------------------------------------------ $| = 1; @@ -71,6 +72,13 @@ while (1) { exit(0); + +#----------------------------------------------------------------------- +# tcp_configure +# Establishes a TCP connection to the specified i-scream filter manager. +# The host then requests details from the server, such as the intervals +# at which to send UDP packets. +#----------------------------------------------------------------------- sub tcp_configure() { my($sock) = new IO::Socket::INET( @@ -85,7 +93,7 @@ sub tcp_configure() { exit(1); } - # Now run through the configuration process. + # Now run through the configuration process... my($response); print $sock "STARTCONFIG\n"; @@ -155,13 +163,24 @@ sub tcp_configure() { close($sock); print "Configuration finished sucessfully!\n"; + + return; } + + + +#----------------------------------------------------------------------- +# send_udp_packet +# Sends a UDP packet to an i-scream filter. +# The packet contains XML markup describing some of the machine's state. +# Receipt of UDP packets is not guaranteed. +#----------------------------------------------------------------------- sub send_udp_packet() { my(@statgrab) = `./statgrab.pl`; my(%packet); - for (my($i) = 0; $i < $#statgrab; $i++) { + for (my($i) = 0; $i <= $#statgrab; $i++) { $statgrab[$i] =~ /^([^\s]*) (.*)$/; $packet{$1} = $2; } @@ -171,13 +190,13 @@ sub send_udp_packet() { my($disk_info) = ""; my($i) = 0; while (defined $packet{"packet.disk.p$i.attributes.mount"}) { - $disk_info .= ""; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.name"}<\/name>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.kbytes"}<\/kbytes>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.used"}<\/used>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.avail"}<\/avail>/; - $disk_info .= qq/$packet{"packet.disk.p$i.attributes.mount"}<\/mount>/; - $disk_info .= ""; + $disk_info .= " @@ -226,18 +247,19 @@ sub send_udp_packet() { $packet{"packet.cpu.swap"} - $packet{"packet.memory.real"} + $packet{"packet.memory.total"} $packet{"packet.memory.free"} - $packet{"packet.memory.swap_total"} - $packet{"packet.memory.swap_free"} + $packet{"packet.swap.total"} + $packet{"packet.swap.free"} $disk_info EOF + # Make the packet smaller by stripping out newlines and leading spaces. $xml =~ s/\n\s*//g; my($sock) = new IO::Socket::INET ( @@ -250,8 +272,18 @@ EOF close($sock); $seq_no++; print "-"; + + return; } + + + +#----------------------------------------------------------------------- +# send_tcp_heartbeat +# Establishes a TCP connection to an i-scream filter. +# The heartbeat is used as a guaranteed "I'm alive" delivery mechanism. +#----------------------------------------------------------------------- sub send_tcp_heartbeat() { my($sock) = new IO::Socket::INET( @@ -319,4 +351,6 @@ sub send_tcp_heartbeat() { close($sock); print "^"; + + return; }