Metric...:Stored(3pm)
πΈ "Metrics::Any::AdapterBase::Stored" β the Perl manpage, but make it cute πΈ
okay bestie, you found the manual page for Metrics::Any::AdapterBase::Stored (3pm), from the User Contributed Perl Documentation, and honestly? it's giving base class energy in the best way. let's get into it π
β¨ NAME β¨
"Metrics::Any::AdapterBase::Stored" β a base class for metrics adapters which store values. that's it, that's the whole name, she's straightforward and we respect her π«Ά
π¦ DESCRIPTION π¦
so this base class? she's the little helper that assists you in creating Metrics::Any::Adapter classes which store values of reported metrics directly. like, right there. no detours, no drama π
and then those stored values can be retrieved later β either by the containing application, or by the subclass code itself β by using the "walk" method. iconic.
here's the tea tho: this base class internally stores counter and gauge metrics as single scalar values directly. simple, clean, slay. but because she wants to provide flexibility for a whole variety of use-cases, she requires assistance from the implementing class on how to store distribution and timer metrics. so the implementing class should provide these methods, returning whatever values it wishes to implement them with. those values get stored by the base class, and handed back as part of the "walk" method. teamwork, fr fr π€
and the base class stores a value for each unique set of labels and values on every metric β the subclass does not need to handle this. thank u base class, doing the absolute most so ur subclass doesn't have to π
π METHODS π
π« walk
$stored->walk( $code )
$code->( $type, $name, $labels, $value )
given a CODE reference, this method invokes it once per labelset of every stored metric. no labelset left behind, periodt.
for each labelset:
$typewill give the metric type (as a string, either"counter","distribution","gauge"or"timer")$namegives the name it was registered with$labelswill be a reference to an even-sized array containing label names and values
and for the value:
- for counter and gauge metrics,
$valuewill be a numerical scalar giving the current value - for distribution and timer metrics,
$valuewill be whatever the implementing class's corresponding"store_distribution"or"store_timer"method returns for them
it's giving β¨ delegation β¨ and honestly? correct.
π§Ή clear_values
$stored->clear_values
clears all of the metric storage. every labelset of every metric is deleted. poof. gone. but here's the important bit bestie β the metric definitions themselves remain π
π₯ REQUIRED METHODS π₯
π store_distribution and store_timer
$storage = $stored->store_distribution( $storage, $amount )
$storage = $stored->store_timer( $storage, $duration )
β οΈ the implementing class must provide these two methods β this is not optional, bestie. they assist in the management of storage for distribution and timer metrics.
so when a new observation for the metric is required, the method will be invoked, passing in:
- the currently-stored perl value for the given metric and label values
- the new observation
and whatever the method returns is stored by the base class β to be passed in next time, or used by the "walk" method. the base class stores this value directly and does not otherwise interact with it, letting the implementing class decide what is best π
for example, a simple implementation may just store every observation individually by pushing them into an array β so the $storage would be an ARRAY reference:
sub store_distribution
{
my $self = shift;
my ( $storage, $amount ) = @_;
push @$storage, $amount;
return $storage;
}
look at that. clean, simple, no notes. ate and left no crumbs π
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk> β we stan a legend π
okay that's the whole page bestie, go forth and store those metrics responsibly π β¨
this was perl v5.36.0 from 2023-09-29 and yeah, the footer said Metric...:Stored(3pm) so like, that's the vibe π¦ bye ily
π¦ where this page comes from
- debian trixie: libmetrics-any-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libmetrics-any-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libmetrics-any-perl 0.10-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libmetrics-any-perl 0.10-1 Β· 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