Es posible monitorizar el estado de los vigilantes usando el módulo NetServer::Portal. Para instrumentar la aplicación es necesario añadirle unas líneas de código que arrancan un servidor que monitoriza a los vigilantes. Es posible entonces obtener información de ese servidor conectándose a un determinado puerto. La información se presenta en un formato similar a la de la tradicional utilidad Unix top :
% !top ----------------------------------------------------- watchthewatchers.pl PID=6901 @ nereida.deioc.ull.es | 10:45:41 [ 60s] 7 events; load averages: 0.00, 0.00, 0.00; lag 0% EID PRI STATE RAN TIME CPU TYPE DESCRIPTION P1 0 7 10 0:07100.0% sys idle 2 3 cpu 1 0:00 0.0% io NetServer::Portal::Client localhost 5 4 sleep 4 0:00 0.0% time ?? watchthewatchers.pl:20 4 4 sleep 8 0:00 0.0% var ?? watchthewatchers.pl:26 3 4 sleep 4 0:00 0.0% var ?? watchthewatchers.pl:32 1 3 sleep 2 0:00 0.0% time Event::Stats 6 3 sleep 0 0:00 0.0% io NetServer::Portal 7 5 wait 0 0:00 0.0% idle NetServer::Portal /var/tmp/watchthewatch 0 -1 0 0:00 0.0% sys other processes
Los pasos para monitorizar un programa Event son:
'NetServer::Portal'->default_start(); # creates server warn "NetServer::Portal listening on port ".(7000+($$ % 1000))."\n";
pp2@nereida:~/src/perl/Event$ watchthewatchers.pl can't open /var/tmp/watchthewatcherspl.npc: No existe el fichero o el directorio at /usr/local/share/perl/5.8.8/NetServer/Portal.pm line 73 NetServer::Portal listening on port 7901 1209462175.88446: Modified variable 1209462175.88465: Write detected. new value: 1 1209462175.88478: Read detected 1209462177.88442: Modified variable 1209462177.88451: Read detected 1209462177.88453: Write detected. new value: 2 1209462177.88456: Read detected 1209462179.88436: Modified variable .................................
pp2@nereida:~/src/perl/Event$ telnet localhost 7901 Trying 127.0.0.1... Connected to localhost. Escape character is '^]'. [nereida.deioc.ull.es] ./watchthewatchers.pl #6901 login: pp2 ----------------------------------------------------- NetServer::Portal v1.08 HOST: nereida.deioc.ull.es PID: 6901 USER: pp2 !about About This Extension !menu Main Menu !pi Perl Introspector !top Process Top !exit End Session dim r,c Change screen dimensions from [24,80]
!top
% !top ----------------------------------------------------- watchthewatchers.pl PID=6901 @ nereida.deioc.ull.es | 10:45:41 [ 60s] 7 events; load averages: 0.00, 0.00, 0.00; lag 0% EID PRI STATE RAN TIME CPU TYPE DESCRIPTION P1 0 7 10 0:07100.0% sys idle 2 3 cpu 1 0:00 0.0% io NetServer::Portal::Client localhost 5 4 sleep 4 0:00 0.0% time ?? watchthewatchers.pl:20 4 4 sleep 8 0:00 0.0% var ?? watchthewatchers.pl:26 3 4 sleep 4 0:00 0.0% var ?? watchthewatchers.pl:32 1 3 sleep 2 0:00 0.0% time Event::Stats 6 3 sleep 0 0:00 0.0% io NetServer::Portal 7 5 wait 0 0:00 0.0% idle NetServer::Portal /var/tmp/watchthewatch 0 -1 0 0:00 0.0% sys other processes
?
Sigue el programa monitorizado en este ejemplo:
pp2@nereida:~/src/perl/Event$ cat -n watchthewatchers.pl 1 #!/usr/bin/perl 2 use warnings; 3 use strict; 4 5 use Event qw{time}; 6 require NetServer::Portal; 7 8 'NetServer::Portal'->default_start(); # creates server 9 warn "NetServer::Portal listening on port ".(7000+($$ % 1000))."\n"; 10 11 my $var = 0; 12 13 Event->timer( 14 interval => 2, 15 cb => sub { 16 $var++; 17 warn time.": Modified variable\n"; 18 return; 19 } 20 ); 21 22 Event->var( 23 var => \$var, 24 poll => 'r', 25 cb => sub { print time.": Read detected\n"; }, 26 ); 27 28 Event->var( 29 var => \$var, 30 poll => 'w', 31 cb => sub { print time.": Write detected. new value: $var\n" }, 32 ); 33 34 Event::loop;
Casiano Rodríguez León