No Description

avidmq-cons.pl 1.3KB

    #!/usr/bin/perl -w use strict; use warnings; use FindBin; use lib $FindBin::Bin."/../lib"; use AvidMQ::Client; use Getopt::Long; my $config=$FindBin::Bin."/../etc/avidmq-cons.conf"; my $queue="/numbers/random/"; my $node=qx{hostname}; GetOptions( "configfile=s" => \$config, ); our $statstime=time()+10; our $inittime=time(); our %count=(); our %avg=(); our %tot=(); our $msgcnt=0; AvidMQ::Client->new( configfile => $config, Publish => \&get_numbers, subscribe => [$queue], )->run(); sub get_numbers { my $avidmq=shift; my $message=shift; our ($statstime,$inittime,%count,%avg,%tot); my $node=$message->{node}; my $number=$message->{number}; $count{$node}=0 unless $count{$node}; $avg{$node}=0 unless $avg{$node}; $tot{$node}=0 unless $tot{$node}; $msgcnt++; $avg{$node}=($avg{$node}*$count{$node}+$number)/++$count{$node}; $tot{$node}+=$number; if (time() > $statstime) { my $tottime=time()-$inittime; my $avgsec=$msgcnt/$tottime; print STDERR <<EOS; Runned for: $tottime [since $inittime] Messages Recieved: $msgcnt [$avgsec per sec] EOS for my $node (keys %count) { print STDERR <<EOS; Producer Node: $node Recieved Numbers: $count{$node} Avg number: $avg{$node} Sum of all numbers: $tot{$node} EOS } print STDERR "\n\n"; $statstime=time()+10; } }