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