NAME

Net::Prometheus - export monitoring metrics for prometheus

SYNOPSIS

use Net::Prometheus;

my $client = Net::Prometheus->new;

my $counter = $client->new_counter(
   name => "requests",
   help => "Number of received requests",
);

sub handle_request
{
   $counter->inc;
   ...
}

use Plack::Builder;

builder {
   mount "/metrics" => $client->psgi_app;
   ...
}

DESCRIPTION

This module provides the ability for a program to collect monitoring metrics and export them to the prometheus.io monitoring server.

As prometheus will expect to collect the metrics by making an HTTP request, facilities are provided to yield a PSGI application that the containing program can embed in its own structure to provide the results, or the application can generate a plain-text result directly and serve them by its own means.

CONSTRUCTOR

new

$prometheus = Net::Prometheus->new;

Returns a new Net::Prometheus instance.

METHODS

register

unregister

new_gauge

$gauge = $prometheus->new_gauge( %args )

Constructs a new Net::Prometheus::Gauge using the arguments given and registers it with the exporter. The newly-constructed gauge is returned.

new_counter

$counter = $prometheus->new_counter( %args )

Constructs a new Net::Prometheus::Counter using the arguments given and registers it with the exporter. The newly-constructed counter is returned.

new_summary

$summary = $prometheus->new_summary( %args )

Constructs a new Net::Prometheus::Summary using the arguments given and registers it with the exporter. The newly-constructed summary is returned.

render

$str = $prometheus->render

Returns a string in the Prometheus text exposition format containing the current values of all the registered metrics.

psgi_app

$app = $prometheus->psgi_app

Returns a new PSGI application as a CODE reference. This application will render the metrics in the Prometheus text exposition format, suitable for scraping by the Prometheus collector.

This application will respond to any GET request, and reject requests for any other method.

TODO

  • Document the Collector / Metric distinction. Document how to make custom Collectors

  • Process collector.

  • Callback gauges.

  • Split Registry out from toplevel instance.

  • Write some actual example programs.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>