From bd8b50b966318cf014a177cb3e5cb9e77c6b8a20 Mon Sep 17 00:00:00 2001 From: bustico Date: Fri, 28 Jul 2006 11:30:08 +0000 Subject: Implementation des messages ping et pong polling des agents via les messages ping et pong pour sortir des stats sur la charge des agents --- example/ivystat.pl | 103 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 89 insertions(+), 14 deletions(-) (limited to 'example/ivystat.pl') diff --git a/example/ivystat.pl b/example/ivystat.pl index f81da88..681bb01 100755 --- a/example/ivystat.pl +++ b/example/ivystat.pl @@ -17,18 +17,17 @@ # #TODO : -# ° pour les simili rpc : fichier de config avec des templates de question et des templates -# de réponse pour qu'ivystat mesure les temps entre la question et la réponse +# ° version avec une interface graphique mise à jour en temps reel ? # # ° version multithread pour ne pas ralentir les agents que l'on observe si # le traitement est long : pas possible partout car sous mandriva perl est compilé -# sans support des threads par exemple. -# -# ° version avec une interface graphique mise à jour en temps reel ? +# sans support des threads par exemple, timeline : attendre mandriva 2007 pour voir si +# perl est compilé avec le support des threads + use strict; -use IvyN; +use Ivy; use Getopt::Long; use Carp; @@ -39,6 +38,8 @@ sub statusFunc ($$$$$$$); sub newMessageCb ($$); sub writeLogs (); sub sigHandler (); +sub sendPings (); +sub receivePongCb($$); my $appliname = "IVYSTAT.PL"; my %options; @@ -48,6 +49,7 @@ my %appByRegexp = (); # $appByRegexp{"regexp"} = [{app1=>1 or 0 if unsubscribe, # \&matchProcedure] my %compteurByApp = (); # $compteurByApp{"app from"}->{"app to"}->[nb msg, nb octets] my %appNameByhostAndPort = (); +my %diedApp = (); my $startTime = time(); my $stopTime; @@ -62,7 +64,8 @@ my %receiveMessByApp; my %receiveBytesByApp; my %connectedAppByAppFrom; my %connectedAppByAppTo; - +my %badlyAttachedRegexp; # value = [nbNoAnchor, nbDoubleAnchor] +my %pingResponse; # value = [min, max, total, nb} END { writeLogs ();} @@ -70,7 +73,7 @@ $SIG{'QUIT'} = $SIG{'INT'} = \&sigHandler; # on traite la ligne de commande -GetOptions(\%options, "help", "bus:s", "file:s", "interval:i", "running:i"); +GetOptions(\%options, "help", "bus:s", "file:s", "interval:i", "running:i", "ping:i"); usage () if (defined $options{help}); usage ("log file name is mandatory") unless defined $options{file}; @@ -92,6 +95,7 @@ $Ivyobj->start; $Ivyobj->bindRegexp ('(.*)', [\&newMessageCb], 1); $Ivyobj->repeat ($options{interval}*1000, [\&writeLogs]) if exists $options{interval}; +$Ivyobj->repeat ($options{ping}*1000, [\&sendPings]) if exists $options{ping}; $Ivyobj->after ($options{running}*1000, sub {exit 0;}) if exists $options{running}; $Ivyobj->mainLoop(); @@ -105,9 +109,10 @@ $Ivyobj->mainLoop(); # |___/ \__| \__,_| \__| \__,_| |___/ |_| \__,_| |_| |_| \___| sub statusFunc ($$$$$$$) { my ($ref_ready, $ref_nonReady, $ref_hashReady, $appname, $status, $host, $regexp) = @_; + my $fqan = sprintf "%s@%s", $appname, $host; if ($status eq "new") { - print "$appname connected from $host\n"; +# print "$appname connected from $host\n"; $appNameByhostAndPort{$host} = $appname; $nbActiveAgent ++; $sendMessByApp{$host} = 0; @@ -116,25 +121,41 @@ sub statusFunc ($$$$$$$) { $receiveBytesByApp{$host} = 0; $connectedAppByAppFrom{$host} =0; $receiveMessByApp{$host} =0; + $pingResponse{$host} = [1e6,0,0,0,0]; #($min, $max, $total, $received, $sent) + delete $diedApp{$host}; # $regexpByApp{$host} = []; } elsif ($status eq "died") { print "$appname disconnected from $host\n"; $nbDeconnecteedAgent ++; $nbActiveAgent --; + $diedApp{$host} = 1; } elsif ($status eq 'subscribing') { - print "$appname subscribed to '$regexp'\n"; + my @anchorType=('', 'NOT ANCHORED', 'DOUBLE ANCHORED'); + my $anchor=0; + study $regexp; unless (exists $appByRegexp{$regexp}) { $appByRegexp{$regexp} = [{$host => 1}, # sub {@{$_[1]} = ${$_[0]} =~ /$regexp/i;}]; eval ('sub {@{$_[1]} = ${$_[0]} =~ /$regexp/io;}')]; } else { + $badlyAttachedRegexp{$host} = [0,0]; ${$appByRegexp{$regexp}->[0]}{$host} = 1; } + + $badlyAttachedRegexp{$host} = [0,0] unless exists $badlyAttachedRegexp{$host}; + if (($regexp !~ m|^\^|) && ($regexp !~ m|\$$|)) { + ($badlyAttachedRegexp{$host}->[0])++; + $anchor=1; + } elsif (($regexp =~ m|^\^|) && ($regexp =~ m|\$$|)) { + ($badlyAttachedRegexp{$host}->[1])++; + $anchor=2; + } + print "$fqan subscribed to $anchorType[$anchor] '$regexp'\n"; } elsif ($status eq 'unsubscribing') { - print "$appname unsubscribed to '$regexp'\n"; + print "$fqan unsubscribed to '$regexp'\n"; ${$appByRegexp{$regexp}->[0]}{$regexp} = 0; } elsif ($status eq 'filtered') { - print "$appname subscribed to *FILTERED* '$regexp'\n"; + print "$fqan subscribed to *FILTERED* '$regexp'\n"; } else { warn "Bug: unkown status; $status in &statusFunc\n"; } @@ -213,7 +234,7 @@ sub writeLogs () # total : nb octets envoyés, nb mess envoyés, nb octets reçus, nb mess reçus # pour chaque agents en receptions : # nb octets envoyés, nb mess envoyés, - my (@sortedApp, $appf, $appt); + my (@sortedApp, $appf, $appn, $appt); # il faut que le filehandle LOG soit valide return unless fileno LOG; @@ -233,20 +254,39 @@ sub writeLogs () } keys (%appNameByhostAndPort); foreach $appf (@sortedApp) { + $appn = $appNameByhostAndPort{$appf}; print "----------------------------------------------\n"; - printf "%s@%s ",$appNameByhostAndPort{$appf}, $appf; + printf "%s@%s ",$appn, $appf; printf "has sent %d messages [%d bytes] to %d agents\n", $sendMessByApp{$appf}, $sendBytesByApp{$appf}, $connectedAppByAppFrom{$appf} if $sendBytesByApp{$appf}; printf "\t\t\ has received %d messages [%d bytes] from %d agents\n", $receiveMessByApp{$appf}, $receiveBytesByApp{$appf}, $connectedAppByAppTo{$appf} if $receiveMessByApp{$appf}; + printf "\t\t\ subscribe to %d NOT ANCHORED regexps\n", $badlyAttachedRegexp{$appf}->[0] + if ($badlyAttachedRegexp{$appf}->[0]); + printf "\t\t\ subscribe to %d DOUBLE ANCHORED regexps\n", $badlyAttachedRegexp{$appf}->[1] + if ($badlyAttachedRegexp{$appf}->[1]); + + printf "\t\t\ has received %d messages [%d bytes] from %d agents\n", + $receiveMessByApp{$appf}, $receiveBytesByApp{$appf}, $connectedAppByAppTo{$appf} + if $receiveMessByApp{$appf}; foreach $appt (keys %{$compteurByApp{$appf}}) { printf "\t\t\t has sent %d messages [%d bytes] to %s@%s\n", $compteurByApp{$appf}->{$appt}->[0], $compteurByApp{$appf}->{$appt}->[1], $appNameByhostAndPort{$appt}, $appt; } + + + if ($pingResponse{$appf}->[3]) { + printf "\t\t\t ping time in milliseconds (%d send, %d received): [min:%.2f avg:%.2f max:%.2f]\n", $pingResponse{$appf}->[4], $pingResponse{$appf}->[3], + $pingResponse{$appf}->[0], $pingResponse{$appf}->[2]/$pingResponse{$appf}->[3], + $pingResponse{$appf}->[1]; + } elsif ($pingResponse{$appf}->[4]) { + print "\t\t\t does NOT respond to ping\n", + } + print "\n\n"; } @@ -254,6 +294,39 @@ sub writeLogs () select ($stdout); } +# _ _____ _ __ _ +# | | | __ \ (_) / _` | +# ___ ___ _ __ __| | | |__) | _ _ __ | (_| | ___ +# / __| / _ \ | '_ \ / _` | | ___/ | | | '_ \ \__, | / __| +# \__ \ | __/ | | | | | (_| | | | | | | | | | __/ | \__ \ +# |___/ \___| |_| |_| \__,_| |_| |_| |_| |_| |___/ |___/ +sub sendPings () +{ + my $appf; + + foreach $appf (keys (%appNameByhostAndPort)) { + next if exists $diedApp{$appf}; + $pingResponse{$appf}->[4]++; + $Ivyobj->ping ($appf, \&receivePongCb); + } +} + + + +sub receivePongCb($$) +{ + my ($time, $appf) = @_; + my ($min, $max, $total, $received, $sent) = @{$pingResponse{$appf}}; + + $min = $time if $time < $min; + $max = $time if $time > $max; + $total += $time; + $received ++; +# printf ("DBG> :$received: $appf [$min, $time, $max]\n"); + @{$pingResponse{$appf}} = ($min, $max, $total, $received, $sent); +} + + # _ __ _ _ _ _ _ # (_) / _` | | | | | | | | | @@ -282,6 +355,8 @@ sub usage (;$) { print " mandatory filename for the log, use - to dump on stdout\n"; print " -r running time\n"; print " run 'running time' second, generate log and exit\n"; + print " -p interval\n"; + print " ping all apps every interval, and gather response time\n"; print " \n"; exit; } -- cgit v1.1