.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Prometheus::Tiny 3pm" .TH Prometheus::Tiny 3pm "2022-02-01" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Prometheus::Tiny \- A tiny Prometheus client .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& use Prometheus::Tiny; \& \& my $prom = Prometheus::Tiny\->new; \& $prom\->set(\*(Aqsome_metric\*(Aq, 5, { some_label => "aaa" }); \& print $prom\->format; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" \&\f(CW\*(C`Prometheus::Tiny\*(C'\fR is a minimal metrics client for the Prometheus time-series database. .PP It does the following things differently to Net::Prometheus: .IP "\(bu" 4 No setup. You don't need to pre-declare metrics to get something useful. .IP "\(bu" 4 Labels are passed in a hash. Positional parameters get awkward. .IP "\(bu" 4 No inbuilt collectors, \s-1PSGI\s0 apps, etc. Just the metrics. .IP "\(bu" 4 Doesn't know anything about different metric types. You get what you ask for. .PP These could all be pros or cons, depending on what you need. For me, I needed a compact base that I could back on a shared memory region. See Prometheus::Tiny::Shared for that! .SH "CONSTRUCTOR" .IX Header "CONSTRUCTOR" .SS "new" .IX Subsection "new" .Vb 2 \& my $prom = Prometheus::Tiny\->new; \& my $prom = Promethus::Tiny\->new(default_labels => { my_label => "frob" }); .Ve .PP If you pass a \f(CW\*(C`default_labels\*(C'\fR key to the constructor, these labels will be included in every metric created on this object. .SH "METHODS" .IX Header "METHODS" .SS "set" .IX Subsection "set" .Vb 1 \& $prom\->set($name, $value, { labels }, [timestamp]) .Ve .PP 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. .PP Trying to set a metric to a non-numeric value will emit a warning and the metric will be set to zero. .SS "add" .IX Subsection "add" .Vb 1 \& $prom\->add($name, $amount, { labels }) .Ve .PP Add the given amount to the already-stored value (or 0 if it doesn't exist). The labels hashref is optional. .PP 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). .SS "inc" .IX Subsection "inc" .Vb 1 \& $prom\->inc($name, { labels }) .Ve .PP A shortcut for .PP .Vb 1 \& $prom\->add($name, 1, { labels }) .Ve .SS "dec" .IX Subsection "dec" .Vb 1 \& $prom\->dec($name, { labels }) .Ve .PP A shortcut for .PP .Vb 1 \& $prom\->add($name, \-1, { labels }) .Ve .SS "clear" .IX Subsection "clear" .Vb 1 \& $prom\->clear; .Ve .PP Remove all stored metric values. Metric metadata (set by \f(CW\*(C`declare\*(C'\fR) is preserved. .SS "histogram_observe" .IX Subsection "histogram_observe" .Vb 1 \& $prom\->histogram_observe($name, $value, { labels }) .Ve .PP Record a histogram observation. The labels hashref is optional. .PP You should declare your metric beforehand, using the \f(CW\*(C`buckets\*(C'\fR key to set the buckets you want to use. If you don't, the following buckets will be used. .PP .Vb 1 \& [ 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 ] .Ve .SS "enum_set" .IX Subsection "enum_set" .Vb 1 \& $prom\->enum_set($name, $value, { labels }, [timestamp]) .Ve .PP Set an enum value for the named metric. The labels hashref is optiona. The timestamp is optional. .PP You should declare your metric beforehand, using the \f(CW\*(C`enum\*(C'\fR key to set the label to use for the enum value, and the \f(CW\*(C`enum_values\*(C'\fR key to list the possible values for the enum. .SS "declare" .IX Subsection "declare" .Vb 1 \& $prom\->declare($name, help => $help, type => $type, buckets => [...]) .Ve .PP \&\*(L"Declare\*(R" a metric by associating metadata with it. Valid keys are: .ie n .IP """help""" 4 .el .IP "\f(CWhelp\fR" 4 .IX Item "help" Text describing the metric. This will appear in the formatted output sent to Prometheus. .ie n .IP """type""" 4 .el .IP "\f(CWtype\fR" 4 .IX Item "type" Type of the metric, typically \f(CW\*(C`gauge\*(C'\fR or \f(CW\*(C`counter\*(C'\fR. .ie n .IP """buckets""" 4 .el .IP "\f(CWbuckets\fR" 4 .IX Item "buckets" For \f(CW\*(C`histogram\*(C'\fR metrics, an arrayref of the buckets to use. See \f(CW\*(C`histogram_observe\*(C'\fR. .ie n .IP """enum""" 4 .el .IP "\f(CWenum\fR" 4 .IX Item "enum" For \f(CW\*(C`enum\*(C'\fR metrics, the name of the label to use for the enum value. See \f(CW\*(C`enum_set\*(C'\fR. .ie n .IP """enum_values""" 4 .el .IP "\f(CWenum_values\fR" 4 .IX Item "enum_values" For \f(CW\*(C`enum\*(C'\fR metrics, the possible values the enum can take. See \f(CW\*(C`enum_set\*(C'\fR. .PP Declaring a already-declared metric will work, but only if the metadata keys and values match the previous call. If not, \f(CW\*(C`declare\*(C'\fR will throw an exception. .SS "format" .IX Subsection "format" .Vb 1 \& my $metrics = $prom\->format .Ve .PP Output the stored metrics, values, help text and types in the Prometheus exposition format . .SS "psgi" .IX Subsection "psgi" .Vb 4 \& use Plack::Builder \& builder { \& mount "/metrics" => $prom\->psgi; \& }; .Ve .PP Returns a simple \s-1PSGI\s0 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 \f(CW\*(C`format\*(C'\fR, namely: .PP .Vb 4 \& sub app { \& my $env = shift; \& return [ 200, [ \*(AqContent\-Type\*(Aq => \*(Aqtext/plain\*(Aq ], [ $prom\->format ] ]; \& } .Ve .PP 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 \f(CW\*(C`format\*(C'\fR. .SH "SUPPORT" .IX Header "SUPPORT" .SS "Bugs / Feature Requests" .IX Subsection "Bugs / Feature Requests" Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. .SS "Source Code" .IX Subsection "Source Code" This is open source software. The code repository is available for public review and contribution under the terms of the license. .PP .PP .Vb 1 \& git clone https://github.com/robn/Prometheus\-Tiny.git .Ve .SH "AUTHORS" .IX Header "AUTHORS" .IP "\(bu" 4 Rob N ★ .SH "CONTRIBUTORS" .IX Header "CONTRIBUTORS" .IP "\(bu" 4 ben hengst .IP "\(bu" 4 Danijel Tasov .IP "\(bu" 4 Michael McClimon .SH "COPYRIGHT AND LICENSE" .IX Header "COPYRIGHT AND LICENSE" This software is copyright (c) 2017 by Rob N ★ .PP This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.