The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Net::Analysis::Listener::Example3 - looking at HTTP transactions

SYNOPSIS

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.

DESCRIPTION

How to sit on top of Net::Analysis::Listener::HTTP. 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 Net::Analysis::Time objects, which while useful for certain things, might not be what you want. You can turn them into floating point seconds easily enough though.

SEE ALSO

Net::Analysis, Net::Analysis::Time, Net::Analysis::Listener::HTTP.

AUTHOR

Adam B. Worrall, <worrall@cpan.org>

COPYRIGHT AND LICENSE

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.