Author image Rafaël Garcia-Suarez

NAME

Graphite::Enumerator - Utility module to recursively enumerate graphite metrics

SYNOPSIS

    my $gren = Graphite::Enumerator->new(
        host => 'https://graphite.example.com',
        basepath => 'general.metrics',
        lwp_options => {
            env_proxy => 1,
            keep_alive => 1,
        },
    );
    $gren->enumerate(sub {
        my ($path) = @_;
        print "Found metric $path !\n";
    });

METHODS

Graphite::Enumerator->new(%args)

The constructor recognizes 3 arguments:

  host => host name (in that case, the protocol defaults to http) or base URL
  basepath => top-level metric namespace to scan
  lwp_options => hash of options to initialize LWP::UserAgent internally

$g->enumerate($coderef)

$g->enumerate([ $coderef, $filter_coderef ])

Calls $coderef for each metric under the basepath, with two parameters: 1. the metric name as a string; 2. the depth level of the metric relative to the base path (starting at 0).

If an array reference of 2 coderefs is provided, the second coderef will be used as an input filter called with the same parameters as above. This will allow, for instance, to stop recursion on a given path by providing a regex, or to stop recursion past a certain level. The code should return false to allow further processing, and true, indicating a match, to prevent further processing along that path.

enumerate() returns the number of metrics found (or 0 on error).

$g->host

Returns the host passed to the constructor (with eventually http:// prepended).

$g->ua

Returns the internal LWP::UserAgent object.

$g->log_message($message)

Prints the $message to STDOUT.

$g->log_warning($message)

Warns about the $message.

ACKNOWLEDGMENT

This module was originally developed for Booking.com. With approval from Booking.com, this module was generalized and put on CPAN, for which the author would like to express his gratitude.

AUTHOR

Rafael Garcia-Suarez, <rgs@consttype.org>

This code is available under the same license as Perl version 5.10.1 or higher.

A git repository for this module is available at https://github.com/rgs/Graphite-Enumerator.