Author image Rafaël Garcia-Suarez


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


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



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, $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).


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


Returns the internal LWP::UserAgent object.


Prints the $message to STDOUT.


Warns about the $message.


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


Rafael Garcia-Suarez, <>

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