Provided by: libnet-prometheus-perl_0.05-1_all
NAME
"Net::Prometheus::Gauge" - a snapshot value-reporting metric
SYNOPSIS
use Net::Prometheus; my $client = Net::Prometheus->new; my $gauge = $client->new_gauge( name => "users", help => "Number of current users", ); my %users; ... $gauge->set( scalar keys %users );
DESCRIPTION
This class provides a gauge metric - an arbitrary value that observes some snapshot of state at some instant in time. This is often used to report on the current usage of resources by the instrumented program, in a way that can decrease as well as increase. It is a subclass of Net::Prometheus::Metric. Value-Reporting Functions As an alternative to using the "set" method to update the value of the gauge, a callback function can be used instead which should return the current value to report for that gauge. This function is invoked at collection time, meaning the reported value is up-to- date. These functions are invoked inline as part of the collection process, so they should be as small and lightweight as possible. Typical applications involve reporting the size of an array or hash within the implementation's code. $gauge->set_function( sub { scalar @items } ); $gauge->set_function( sub { scalar keys %things } );
CONSTRUCTOR
Instances of this class are not usually constructed directly, but instead via the Net::Prometheus object that will serve it: $gauge = $prometheus->new_gauge( %args ) This takes the same constructor arguments as documented in Net::Prometheus::Metric.
METHODS
set $gauge->set( [ @label_values ], $value ) $child->set( $value ) Sets the current value for the gauge. If the gauge has any labels defined, the values for them must be given first. set_function $gauge->set_function( [ @label_values ], $func ) $child->set_function( $func ) Sets a value-returning callback function for the gauge. If the gauge is labeled, each label combination requires its own function. When invoked, the function will be passed no arguments and is expected to return a single value $value = $func->() inc $gauge->inc( [ @label_values ], $delta ) $child->inc( $delta ) Increment the current value for the gauge. $delta will default to 1 if not supplied. dec $gauge->dec( [ @label_values ], $delta ) $child->dec( $delta ) Decrement the current value for the gauge. $delta will default to 1 if not supplied.
AUTHOR
Paul Evans <leonerd@leonerd.org.uk>