Net::Analysis::Listener::Example3 - looking at HTTP transactions |
Net::Analysis::Listener::Example3 - looking at HTTP transactions
package Net::Analysis::Listener::Example3;
use strict; use warnings; use base qw(Net::Analysis::Listener::Base);
sub http_transaction { my ($self, $args) = @_; my ($req) = $args->{req}; # isa HTTP::Request my ($req_mono) = $args->{req_mono}; # isa Net::Analysis::TCPMonologue my ($resp_mono) = $args->{resp_mono}; # isa Net::Analysis::TCPMonologue
# Print out time between sending last part of request, and receiving # first part of response. # (Note; these are Net::Analsysis::Time objects) my ($network_wait_time) = $resp_mono->t_start() - $req_mono->t_end(); printf "%-50.50s: %8.2f\n", $req->uri(), $network_wait_time; }
1;
You can invoke this example on a TCP capture file from the command line, as follows:
$ perl -MNet::Analysis -e main HTTP Example3 t/t1_google.tcp
Note the regex parameter being passed to the Example2 listener.
How to sit on top of the Net::Analysis::Listener::HTTP manpage. Note that you need to
load the HTTP listener as well as Example3 in the Perl command line ! If you
don't do this, then only the TCP listener will be loaded, no
http_transaction
events will be emitted, and so Example3 will listen in
vain.
Other gotcahs; the t_start
and t_end
methods for TCPMonologue return
the Net::Analysis::Time manpage objects, which while useful for certain things, might
not be what you want. You can turn them into floating point seconds easily
enough though.
the Net::Analysis manpage, the Net::Analysis::Time manpage, the Net::Analysis::Listener::HTTP manpage.
Adam B. Worrall, <worrall@cpan.org>
Copyright (C) 2004 by Adam B. Worrall
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.5 or, at your option, any later version of Perl 5 you may have available.
Net::Analysis::Listener::Example3 - looking at HTTP transactions |