Net::P...:Metric(3pm)
โจ NAME โจ
Net::Prometheus::Metric โ the base class for observed metrics ๐
(yes bestie, this page came out of the User Contributed Perl Documentation, and it's giving very much "foundation class that runs the whole friend group" energy ๐ซถ)
๐ธ DESCRIPTION ๐ธ
okay so this class is the mother of the whole squad โ it hands out all the basic methods that every concrete subclass has in common. no cap. here's who's in the group chat:
Net::Prometheus::Gaugeโ a snapshot value-reporting metric ๐ธNet::Prometheus::Counterโ a monotonically-increasing counter metric ๐ (only ever goes up, she does not do "down")Net::Prometheus::Summaryโ summarise individual numeric observations ๐งฎNet::Prometheus::Histogramโ count the distribution of numeric observations ๐
๐ CONSTRUCTOR ๐
new
$metric = Net::Prometheus::Metric->new(
name => $name,
help => $help,
);
lowkey important: the constructor is not normally used directly by instrumented code ๐. instead, the main character move is to use one of the new_* methods on the containing Net::Prometheus client instance, so that your shiny new metric gets automatically registered as a collector and gets exported by the render method. iykyk.
$metric = $prometheus->new_counter(
name => $name,
help => $help,
);
either way you do it, it returns a newly-constructed metric. slay.
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 ๐งต
๐ METHODS ๐
fullname
$fullname = $metric->fullname;
Returns the full name for the metric ๐ซ. it's formed by joining any of the defined values for "namespace", "subsystem" and "name" with '_'. so cute, so tidy.
labelcount
$labels = $metric->labelcount;
Returns the number of labels defined for this metric ๐ข.
labels
$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 ๐ถโจ. you can hand over those label values two ways: either in a list that matches the list of label names you gave at construction time, or by name inside a single HASH reference.
the child instance supports the same methods for controlling the value of the reported metric as the parent metric object โ only difference is all the label values are already provided. no extra work, just vibes.
pro tip from the source: this object may be cached for efficiency ๐ฅ
make_sample
$sample = $metric->make_sample( $suffix, $labelkey, $value, $extralabels );
Returns a new Sample in Net::Prometheus::Types structure to represent the given value ๐งช โ it does this 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, that suffix gets separated by an underscore '_'. and if provided, $extralabels gives you even more label names and values to add to the sample. the more the merrier fr fr.
samples
@samples = $metric->samples;
this one is an abstract method in this class โ meaning it's intended to be overridden by subclasses, bestie, don't come for her ๐ญ.
it gets called during the value collection process, and it should return a list of Sample in Net::Prometheus::Types instances containing the values to report from this metric.
remove
$metric->remove( @values );
$metric->remove( { name => $value, name => $value, ... } );
Since version 0.14. ๐๏ธ
Removes a single labelset from the metric. this stops it being reported by future calls to samples. bye girl, we won't see you in the report ๐
clear
$metric->clear;
Since version 0.14. ๐๏ธ
Removes all the labelsets from the metric, resetting it back to an initial empty state. full factory reset, fresh start, new era ๐
๐ AUTHOR ๐
Paul Evans <leonerd@leonerd.org.uk> ๐
and that's the whole page, bestie โ every option, every default, every version note, nothing skipped, periodt ๐
this beautiful piece of documentation was brought to you by perl v5.42.3, dated 2026-08-20, under the watchful eye of the User Contributed Perl Documentation crew ๐ โ go forth and export your metrics, you absolute icon ๐
๐ฆ where this page comes from
- ubuntu stonking: libnet-prometheus-perl 0.16-1build1 ยท Artistic-1.0-Perl OR GPL-1.0-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms