View on
MetaCPAN is shutting down
For details read Perl NOC. After June 25th this page will redirect to
Scott Lanning > Net-Graphite > Net::Graphite



Annotate this POD

View/Report Bugs
Module Version: 0.17   Source  


Net::Graphite - Interface to Graphite


  use Net::Graphite;
  my $graphite = Net::Graphite->new(
      # except for host, these hopefully have reasonable defaults, so are optional
      host                  => '',
      port                  => 2003,
      trace                 => 0,                # if true, copy what's sent to STDERR
      proto                 => 'tcp',            # can be 'udp'
      timeout               => 1,                # timeout of socket connect in seconds
      fire_and_forget       => 0,                # if true, ignore sending errors
      return_connect_error  => 0,                # if true, forward connect error to caller

      path                  => '', # optional, use when sending single values

  # to check for connection error (when return_connect_error => 1) do:
  die "connection error: $!" unless $graphite->connect;

  # send a single value,
  # need to set path in the call to new
  # or call $graphite->path('some.path') beforehand
  $graphite->send(6);        # default time is "now"


  # send a metric with named parameters
      path => '',
      value => 6,
      time => time(),        # time defaults to "now"


  # send text with one line per metric, following the plaintext protocol
  $graphite->send(data => $string_with_one_line_per_metric);


  # send a data structure,
  # here using the default transformer for Hash of Hash: epoch => key => key .... => value
  $graphite->send(path => 'foo', data => $hash);

  # example of hash structure:
  1234567890 => {
      bar => {
          db1 => 3,
          db2 => 7,
          db3 => 2,
      baz => 42,
  would be: = 3 = 7 = 2
  foo.baz = 42


  # send a data structure, providing your own plaintext transformer
  # (the callback's only arg is the data structure, return a text string one metric on each line)
  $graphite->send(data => $whatever, transformer => \&make_whatever_into_plaintext);


Interface to Graphite which doesn't depend on AnyEvent.



Explicitly close the socket to the graphite server. Not normally needed, because the socket will close when the $graphite object goes out of scope.


Get an open a socket to the graphite server, either the currently connected one or, if not already connected, a new one. Not normally needed.


Set the default path (corresponds to 'path' argument to new), for use when sending single values.


Normally all you need to use. See the SYNOPSIS. (FIXME)


If you pass a 'data' argument to send, use this coderef to transform from the data structure to plaintext. The coderef receives the data structure as its only parameter. There are default transformers for certain reftypes.




Scott Lanning <>

syntax highlighting: