Metric...Adapter(3pm)
π Metrics::Any::Adapter π
okay so bestie, gather round, because this one is literally the plug for your whole metrics sitch π«Ά it's Metrics::Any::Adapter β the thing that sets the Metrics::Any adapter for the program. that's it, that's the whole job, and she does it flawlessly π
β¨ SYNOPSIS β¨
you drop this bad boy in a program or a top-level program-like module:
use Metrics::Any::Adapter 'Prometheus';
and boom π₯ metrics go brrr. that's the vibe.
πΈ DESCRIPTION πΈ
so here's the tea β β the use statement that loads this module sets the adapter module for Metrics::Any so it can report all the metrics generated by the modules your program uses. very main character of it, honestly.
the first value you pass in should be a string with the name of an adapter module, and that name is expected to live under the Metrics::Any::Adapter:: prefix. this module gets loaded and set as the adapter to use, periodt. any additional arguments you tack on get handed straight to the constructor of that adapter instance. slay.
use Metrics::Any::Adapter Custom => "another arg";
# implies
$adapter = Metrics::Any::Adapter::Custom->new( "another arg" );
see how that works? the extra stuff just gets yeeted into new. iconic π«
π ENVIRONMENT π
π¦ METRICS_ANY_ADAPTER
okay so this one's been around since version 0.04 β
it sets the default adapter type to use if the program has not otherwise requested one. like, a lil fallback bestie. a safety net. we love her.
normally this is set to Null, which loads Metrics::Any::Adapter::Null. but if you override it to a different value, you can load a default adapter without modifying the program at all. chef's kiss π super handy for stuff like running unit tests:
$ METRICS_ANY_ADAPTER=Stderr ./Build test
and yes, you can pass additional arguments after a colon, separated by commas or equals signs. go off:
$ METRICS_ANY_ADAPTER=File:path=metrics.log ./program.pl
β οΈ but heads up bestie: if a program requests a specific adapter, that request will override this variable. the program's choice wins, no cap.
there's also a limited attempt at supporting nested arguments wrapped in square brackets, so the Metrics::Any::Adapter::Tee adapter can do its lil thing via this variable and pass arguments into child adapters:
$ METRICS_ANY_ADAPTER=Tee:Prometheus,[File:path=metrics.log] perl ...
now, this is very much a best-effort scenario β useful for short-term testing and debugging, and that's it. for anything more complex in your script or program, it's better to use the import arguments directly, because then any perl data structures can be passed around. lowkey the superior move, fr fr.
π AUTHOR π
Paul Evans <leonerd@leonerd.org.uk>
and that's the whole page, bestie π this was Metric...Adapter(3pm) from perl v5.36.0, dated 2023-09-29 β go forth and instrument everything, you've got this ππβ¨
π¦ 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