Net::Statsd::Client::Timer - Measure event timings and send them to StatsD


version 0.34


    use Net::Statsd::Client;
    my $stats = Net::Statsd::Client->new(prefix => "service.frobnitzer.");

    my $timer = $stats->timer("request_duration");
    # ... do something expensive ...



To build a timer object, call Net::Statsd::Client's timer method, instead of calling this constructor directly.

A timer has an associated statsd object, metric name, and sample rate, and begins counting as soon as it's constructed.


Stop timing, and send the elapsed time to the server. Returns the elapsed time in milliseconds.


Stop timing, but do not send the elapsed time to the server. A timer that goes out of scope without having finish or cancel called on it will generate a warning, since this probably points to bugs and lost timing information.


Change the metric name of a timer on the fly. This is useful if you don't know what kind of event you're timing until it's finished. Harebrained example:

    my $timer = $statsd->timer("item.fetch");
    my $item = $cache->get("blah");
    if ($item) {
    } else {
        $item = get_it_the_long_way();


Andrew Rodland <>


This software is copyright (c) 2018 by Andrew Rodland.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.