Prometheus::Tiny(3pm)
π Prometheus::Tiny π
okay so bestie, you're looking at the User Contributed Perl Documentation page for Prometheus::Tiny (that's the 3pm one, the perl module manual) and honestly? it's a whole vibe. let's get into it π«Ά
β¨ NAME β¨
Prometheus::Tiny β a tiny Prometheus client. yes, tiny. compact. cute. iconic. π
πΈ SYNOPSIS πΈ
look at how little you need. no cap, this is the whole thing:
use Prometheus::Tiny;
my $prom = Prometheus::Tiny->new;
$prom->set('some_metric', 5, { some_label => "aaa" });
print $prom->format;
that's it. that's the setup. we love a low-effort main character β¨
π DESCRIPTION π
Prometheus::Tiny is a minimal metrics client for the Prometheus <http://prometheus.io/> time-series database. minimal as in it does not do the most, and that is the entire point.
here's the way it does things differently to Net::Prometheus:
- No setup. You don't need to pre-declare metrics to get something useful. just vibe and set a metric, it works.
- Labels are passed in a hash. Positional parameters get awkward, periodt.
- No inbuilt collectors, PSGI apps, etc. Just the metrics. nothing extra, nothing you didn't ask for.
- Doesn't know anything about different metric types. You get what you ask for. it's giving "I'm not your therapist, I'm your metrics client".
ngl these could all be pros or cons, depending on what you need. for the author, what was needed was a compact base that could be backed on a shared memory region. see Prometheus::Tiny::Shared for that! π
π CONSTRUCTOR π
new
my $prom = Prometheus::Tiny->new;
my $prom = Promethus::Tiny->new(default_labels => { my_label => "frob" });
(yes the second one is spelled Promethus::Tiny in the original, we are preserving it character for character, do not come for me π)
If you pass a default_labels key to the constructor, these labels will be included in every metric created on this object. every single one. they're part of the family now.
π METHODS π
set
$prom->set($name, $value, { labels }, [timestamp])
Set the value for the named metric. The labels hashref is optional. The timestamp (milliseconds since epoch) is optional, but requires labels to be provided to use. An empty hashref will work in the case of no labels.
β οΈ Trying to set a metric to a non-numeric value will emit a warning and the metric will be set to zero. it's giving "we tried, bestie". π
add
$prom->add($name, $amount, { labels })
Add the given amount to the already-stored value (or 0 if it doesn't exist). The labels hashref is optional.
β οΈ Trying to add a non-numeric value to a metric will emit a warning and 0 will be added instead (this will still create the metric if it didn't exist, and will update timestamps etc). so like, it's fine, it's still doing the thing, just with a zero.
inc
$prom->inc($name, { labels })
A shortcut for
$prom->add($name, 1, { labels })
plus one. that's the whole method. slay. β
dec
$prom->dec($name, { labels })
A shortcut for
$prom->add($name, -1, { labels })
minus one. the little sibling of inc. π¦
clear
$prom->clear;
Remove all stored metric values. Metric metadata (set by declare) is preserved β so the values are gone but the lore remains. π
histogram_observe
$prom->histogram_observe($name, $value, { labels })
Record a histogram observation. The labels hashref is optional.
You should declare your metric beforehand, using the buckets key to set the buckets you want to use. If you don't, the following buckets will be used.
[ 0.005, 0.01, 0.025, 0.05, 0.075, 0.1, 0.25, 0.5, 0.75, 1.0, 2.5, 5.0, 7.5, 10 ]
those are the defaults, bestie. take them or declare your own. β¨
enum_set
$prom->enum_set($name, $value, { labels }, [timestamp])
Set an enum value for the named metric. The labels hashref is optional. The timestamp is optional.
You should declare your metric beforehand, using the enum key to set the label to use for the enum value, and the enum_values key to list the possible values for the enum.
declare
$prom->declare($name, help => $help, type => $type, buckets => [...])
"Declare" a metric by associating metadata with it. (scare quotes fully intentional, that's the original's energy.) valid keys are:
helpβ Text describing the metric. This will appear in the formatted output sent to Prometheus.typeβ Type of the metric, typicallygaugeorcounter.bucketsβ Forhistogrammetrics, an arrayref of the buckets to use. Seehistogram_observe.enumβ Forenummetrics, the name of the label to use for the enum value. Seeenum_set.enum_valuesβ Forenummetrics, the possible values the enum can take. Seeenum_set.
β οΈ Declaring a already-declared metric will work, but only if the metadata keys and values match the previous call. If not, declare will throw an exception. no take-backs, no glow-ups, the metadata is locked in. π₯
format
my $metrics = $prom->format
Output the stored metrics, values, help text and types in the Prometheus exposition format <https://github.com/prometheus/docs/blob/master/content/docs/instrumenting/exposition_formats.md>. this is the moment. this is what it was all for. π
psgi
use Plack::Builder
builder {
mount "/metrics" => $prom->psgi;
};
Returns a simple PSGI app that, when hooked up to a web server and called, will return formatted metrics for Prometheus. This is little more than a wrapper around format, namely:
sub app {
my $env = shift;
return [ 200, [ 'Content-Type' => 'text/plain' ], [ $prom->format ] ];
}
This is just a convenience; if you already have a web server or you want to ship metrics via some other means (eg the Node Exporter's textfile collector), just use format. do it your way, bestie, it's your metrics journey π«Ά
π§ SUPPORT π§
Bugs / Feature Requests
Please report any bugs or feature requests through the issue tracker at <https://github.com/robn/Prometheus-Tiny/issues>. You will be notified automatically of any progress on your issue. it's giving accountability. π
Source Code
This is open source software. The code repository is available for public review and contribution under the terms of the license.
<https://github.com/robn/Prometheus-Tiny>
git clone https://github.com/robn/Prometheus-Tiny.git
clone it. read it. contribute. main character behaviour fr fr π
π AUTHORS π
- Rob Norris <robn@despairlabs.com>
πΈ CONTRIBUTORS πΈ
- ben hengst <ben.hengst@dreamhost.com>
- Danijel Tasov <data@consol.de>
- Michael McClimon <michael@mcclimon.org>
these people made it happen and we are obsessed with them π
π COPYRIGHT AND LICENSE π
This software is copyright (c) 2017 by Rob Norris <robn@despairlabs.com>
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
and that's the whole page, bestie!! this beauty lives at perl v5.36.0, dated 2023-09-30 β literally Prometheus::Tiny(3pm) and nothing less. go forth and emit metrics responsibly π
β¨π
π¦ where this page comes from
- debian trixie: libprometheus-tiny-perl 0.011-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libprometheus-tiny-perl 0.011-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libprometheus-tiny-perl 0.011-1 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libprometheus-tiny-perl 0.011-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