Net::Prometheus::Metric - the base class for observed metrics


This class provides the basic methods shared by the concrete subclasses,



   $metric = Net::Prometheus::Metric->new(
      name => $name,
      help => $help,

The constructor is not normally used directly by instrumented code. Instead it is more common to use one of the new_* methods on the containing Net::Prometheus client instance so that the new metric is automatically registered as a collector, and gets exported by the render method.

   $metric = $prometheus->new_counter(
      name => $name,
      help => $help,

In either case, it returns a newly-constructed metric.

Takes the following named arguments:

namespace => STR
subsystem => STR

Optional strings giving the namespace and subsystem name parts of the variable name.

name => STR

The basename of the exported variable.

help => STR

Descriptive help text for the variable.

labels => ARRAY of STR

Optional ARRAY reference giving the names of labels for the metric.



   $fullname = $metric->fullname

Returns the full name for the metric. This is formed by joining any of the defined values for namespace, subsystem and name with '_'.


   $labels = $metric->labelcount

Returns the number of labels defined for this metric.


   $child = $metric->labels( @values )

   $child = $metric->labels( { name => $value, name => $value, ... } )

Returns a child metric to represent the general one with the given set of labels. The label values may be provided either in a list corresponding to the list of label names given at construction time, or by name in a single HASH reference.

The child instance supports the same methods to control the value of the reported metric as the parent metric object, except that any label values are already provided.

This object may be cached for efficiency.


   $sample = $metric->make_sample( $suffix, $labelkey, $value, $extralabels )

Returns a new "Sample" in Net::Prometheus::Types structure to represent the given value, by expanding the opaque $labelkey value into its actual label names and values and appending the given suffix (which may be an empty string) to the metric's fullname. If provided, the suffix will be separated by an underscore '_'. If provided, $extralabels provides more label names and values to be added to the sample.


   @samples = $metric->samples

An abstract method in this class, this method is intended to be overridden by subclasses.

Called during the value collection process, this method should return a list of "Sample" in Net::Prometheus::Types instances containing the values to report from this metric.


Paul Evans <>