Prometheus-Tiny-0.011/0000755000175000017500000000000014476215320013255 5ustar robnrobnPrometheus-Tiny-0.011/META.yml0000644000175000017500000001474714476215320014543 0ustar robnrobn--- abstract: 'A tiny Prometheus client' author: - 'Rob Norris ' build_requires: HTTP::Request::Common: '0' Plack::Test: '0' Test::Exception: '0' Test::More: '0' Test::Warn: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: Prometheus-Tiny requires: Carp: '0' Scalar::Util: '0' strict: '0' warnings: '0' resources: bugtracker: https://github.com/robn/Prometheus-Tiny/issues homepage: https://github.com/robn/Prometheus-Tiny repository: https://github.com/robn/Prometheus-Tiny.git version: '0.011' x_Dist_Zilla: perl: version: '5.036000' plugins: - class: Dist::Zilla::Plugin::PruneCruft name: '@Filter/PruneCruft' version: '6.030' - class: Dist::Zilla::Plugin::ManifestSkip name: '@Filter/ManifestSkip' version: '6.030' - class: Dist::Zilla::Plugin::MetaYAML name: '@Filter/MetaYAML' version: '6.030' - class: Dist::Zilla::Plugin::License name: '@Filter/License' version: '6.030' - class: Dist::Zilla::Plugin::Readme name: '@Filter/Readme' version: '6.030' - class: Dist::Zilla::Plugin::ExtraTests name: '@Filter/ExtraTests' version: '6.030' - class: Dist::Zilla::Plugin::ExecDir name: '@Filter/ExecDir' version: '6.030' - class: Dist::Zilla::Plugin::ShareDir name: '@Filter/ShareDir' version: '6.030' - class: Dist::Zilla::Plugin::MakeMaker config: Dist::Zilla::Role::TestRunner: default_jobs: 1 name: '@Filter/MakeMaker' version: '6.030' - class: Dist::Zilla::Plugin::Manifest name: '@Filter/Manifest' version: '6.030' - class: Dist::Zilla::Plugin::TestRelease name: '@Filter/TestRelease' version: '6.030' - class: Dist::Zilla::Plugin::ConfirmRelease name: '@Filter/ConfirmRelease' version: '6.030' - class: Dist::Zilla::Plugin::UploadToCPAN name: '@Filter/UploadToCPAN' version: '6.030' - class: Dist::Zilla::Plugin::GatherDir config: Dist::Zilla::Plugin::GatherDir: exclude_filename: - LICENSE - Makefile.PL exclude_match: [] follow_symlinks: 0 include_dotfiles: 0 prefix: '' prune_directory: [] root: . name: GatherDir version: '6.030' - class: Dist::Zilla::Plugin::AutoPrereqs name: AutoPrereqs version: '6.030' - class: Dist::Zilla::Plugin::PkgVersion name: PkgVersion version: '6.030' - class: Dist::Zilla::Plugin::MetaConfig name: MetaConfig version: '6.030' - class: Dist::Zilla::Plugin::MetaJSON name: MetaJSON version: '6.030' - class: Dist::Zilla::Plugin::NextRelease name: NextRelease version: '6.030' - class: Dist::Zilla::Plugin::GithubMeta name: GithubMeta version: '0.58' - class: Dist::Zilla::Plugin::Git::Check config: Dist::Zilla::Plugin::Git::Check: untracked_files: die Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - Makefile.PL - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.39.2 repo_root: . name: '@Git/Check' version: '2.048' - class: Dist::Zilla::Plugin::Git::Commit config: Dist::Zilla::Plugin::Git::Commit: add_files_in: [] commit_msg: v%V%n%n%c signoff: 0 Dist::Zilla::Role::Git::DirtyFiles: allow_dirty: - Changes - Makefile.PL - dist.ini allow_dirty_match: [] changelog: Changes Dist::Zilla::Role::Git::Repo: git_version: 2.39.2 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Commit' version: '2.048' - class: Dist::Zilla::Plugin::Git::Tag config: Dist::Zilla::Plugin::Git::Tag: branch: ~ changelog: Changes signed: 0 tag: '0.011' tag_format: '%v' tag_message: v%V Dist::Zilla::Role::Git::Repo: git_version: 2.39.2 repo_root: . Dist::Zilla::Role::Git::StringFormatter: time_zone: local name: '@Git/Tag' version: '2.048' - class: Dist::Zilla::Plugin::Git::Push config: Dist::Zilla::Plugin::Git::Push: push_to: - origin remotes_must_exist: 1 Dist::Zilla::Role::Git::Repo: git_version: 2.39.2 repo_root: . name: '@Git/Push' version: '2.048' - class: Dist::Zilla::Plugin::ReadmeAnyFromPod config: Dist::Zilla::Role::FileWatcher: version: '0.006' name: MarkdownInRoot version: '0.163250' - class: Dist::Zilla::Plugin::CopyFilesFromBuild name: CopyFilesFromBuild version: '0.170880' - class: Dist::Zilla::Plugin::FinderCode name: ':InstallModules' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':IncModules' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':TestFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':ExtraTestFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':ExecFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':PerlExecFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':ShareFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':MainModule' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':AllFiles' version: '6.030' - class: Dist::Zilla::Plugin::FinderCode name: ':NoFiles' version: '6.030' zilla: class: Dist::Zilla::Dist::Builder config: is_trial: 0 version: '6.030' x_generated_by_perl: v5.36.0 x_serialization_backend: 'YAML::Tiny version 1.74' x_spdx_expression: 'Artistic-1.0-Perl OR GPL-1.0-or-later' Prometheus-Tiny-0.011/dist.ini0000644000175000017500000000117114476215320014721 0ustar robnrobnname = Prometheus-Tiny author = Rob Norris license = Perl_5 copyright_holder = Rob Norris copyright_year = 2018 version = 0.011 [@Filter] -bundle = @Basic -remove = GatherDir [GatherDir] exclude_filename = Makefile.PL exclude_filename = LICENSE [AutoPrereqs] [PkgVersion] die_on_existing_version = 1 die_on_line_insertion = 1 [MetaConfig] [MetaJSON] [NextRelease] [GithubMeta] issues = 1 [@Git] tag_format = %v allow_dirty = Changes allow_dirty = dist.ini allow_dirty = Makefile.PL [ReadmeAnyFromPod / MarkdownInRoot] filename = README.md [CopyFilesFromBuild] copy = Makefile.PL copy = LICENSE Prometheus-Tiny-0.011/t/0000755000175000017500000000000014476215320013520 5ustar robnrobnPrometheus-Tiny-0.011/t/11-add.t0000644000175000017500000000131014476215320014647 0ustar robnrobn#!perl use warnings; use strict; use Test::More; use Prometheus::Tiny; { my $p = Prometheus::Tiny->new; is $p->format, '', 'no metrics produces no output'; } { my $p = Prometheus::Tiny->new; $p->add('some_metric', 2); is $p->format, <new; $p->set('some_metric', 5); $p->add('some_metric', 10); is $p->format, <new; $p->add('some_metric', 3); $p->add('some_metric', 8); $p->add('some_metric', 2); is $p->format, <new; $p->declare('some_metric', help => 'My great metric'); is $p->format, <new; $p->declare('some_metric', type => 'counter'); is $p->format, <new; $p->declare('some_metric', help => 'My great metric', type => 'counter'); is $p->format, <new; $p->declare('some_metric', help => 'My great metric', type => 'counter'); $p->declare('other_metric', help => 'My other great metric', type => 'gauge'); $p->set('some_metric', 5); $p->set('other_metric', 10); is $p->format, <new; $p->declare('some_metric', help => 'My great metric', type => 'counter'); $p->set('some_metric', 5); $p->set('other_metric', 10); is $p->format, <new; $p->add('some_metric', 5, { some_label => 'aaa' }); is $p->format, <new; $p->inc('some_metric', { some_label => "aaa" }); is $p->format, <new; $p->dec('some_metric', { some_label => "aaa" }); is $p->format, <new; is $p->format, '', 'no metrics produces no output'; } { my $p = Prometheus::Tiny->new; $p->inc('some_metric'); is $p->format, <new; $p->set('some_metric', 5); $p->inc('some_metric'); is $p->format, <new; $p->set('some_metric', 5); $p->dec('some_metric'); is $p->format, <new; $p->inc('some_metric'); $p->inc('some_metric'); $p->dec('some_metric'); $p->inc('some_metric'); $p->dec('some_metric'); $p->dec('some_metric'); is $p->format, <new; $p->histogram_observe('h', .273); is $p->format, <new; $p->histogram_observe('h', .2); $p->histogram_observe('h', .4); $p->histogram_observe('h', .6); $p->histogram_observe('h', .8); is $p->format, <new; $p->declare("h", buckets => [1,2,3,4,5]); $p->histogram_observe('h', .5); $p->histogram_observe('h', 1.5); $p->histogram_observe('h', 2.5); $p->histogram_observe('h', 3.5); is $p->format, < 1; require_ok('Prometheus::Tiny'); local $Prometheus::Tiny::VERSION = $Prometheus::Tiny::VERSION || 'from repo'; note("Prometheus::Tny $Prometheus::Tiny::VERSION, Perl $], $^X"); Prometheus-Tiny-0.011/t/22-declare-unique.t0000644000175000017500000000402614476215320017033 0ustar robnrobn#!perl use warnings; use strict; use Test::More; use Test::Exception; use Prometheus::Tiny; my $p = Prometheus::Tiny->new; $p->declare('some_metric', type => 'counter', help => 'my great metric'); lives_ok(sub { $p->declare('some_metric', type => 'counter', help => 'my great metric'); }, 'redeclaring metric with same meta is allowed'); dies_ok(sub { $p->declare('some_metric', type => 'gauge', help => 'my great metric'); }, 'redeclaring metric with different meta values crashes'); dies_ok(sub { $p->declare('some_metric', help => 'my great metric'); }, 'redeclaring metric with missing meta values crashes'); dies_ok(sub { $p->declare('some_metric', type => 'counter', help => 'my great metric', buckets => []); }, 'redeclaring metric with added meta values crashes'); $p->declare('h', buckets => [1,2,3,4,5]); lives_ok(sub { $p->declare('h', buckets => [1,2,3,4,5]); }, 'redeclaring histogram metric with same buckets is allowed'); dies_ok(sub { $p->declare('h'); }, 'redeclaring histogram metric with missing buckets crashes'); dies_ok(sub { $p->declare('h', buckets => [1,2,3]); }, 'redeclaring histogram metric with different number of buckets crashes'); dies_ok(sub { $p->declare('h', buckets => [1,2,3,4,8]); }, 'redeclaring histogram metric with different buckets crashes'); $p->declare('e', enum => 'v', enum_values => [qw(foo bar baz)]); lives_ok(sub { $p->declare('e', enum => 'v', enum_values => [qw(foo bar baz)]); }, 'redeclaring enum metric with same buckets is allowed'); dies_ok(sub { $p->declare('e'); }, 'redeclaring enum metric with missing meta crashes'); dies_ok(sub { $p->declare('e', enum => 'w', enum_values => [qw(foo bar baz)]); }, 'redeclaring enum metric with different enum label crashes'); dies_ok(sub { $p->declare('e', enum => 'v', enum_values => [qw(foo)]); }, 'redeclaring enum metric with different number of enum values crashes'); dies_ok(sub { $p->declare('e', enum => 'v', enum_values => [qw(one two three)]); }, 'redeclaring enum metric with different enum values crashes'); done_testing; Prometheus-Tiny-0.011/t/50-warn-undef.t0000644000175000017500000000200414476215320016171 0ustar robnrobn#!perl use warnings; use strict; use Test::More; use Test::Warn; use Prometheus::Tiny; { my $p = Prometheus::Tiny->new; $p->set('some_metric', 10); warning_like { $p->set('some_metric') } qr/setting '.+' to non-numeric value, using 0 instead/, 'setting undef value emits a warning'; is $p->format, <new; $p->set('some_metric', 10); warning_like { $p->add('some_metric') } qr/adjusting '.+' by non-numeric value, adding 0 instead/, 'adding undef value emits a warning'; is $p->format, <new; $p->set('some_metric', 10); warning_like { $p->add('some_metric', 10, { foo => undef }) } qr/label '.+' has an undefined value, dropping it/, 'undef label value emits a warning'; is $p->format, <new; $p->declare('some_metric', help => 'My great metric', type => 'counter'); $p->set('some_metric', 5); my $t = Plack::Test->create($p->psgi); my $res = $t->request(GET '/'); is $res->content, <new; $p->set('some_metric', 5, { some_label => 'aaa' }); is $p->format, <new; $p->set('some_metric', 5, { some_label => "aaa" }); $p->set('other_metric', 10, { other_label => "bbb" }); is $p->format, <new; $p->set('some_metric', 5, { some_label => "aaa" }); $p->set('other_metric', 10); is $p->format, <new; $p->set('some_metric', 3, { some_label => "aaa" }); $p->set('some_metric', 8, { some_label => "aaa" }); is $p->format, <new; $p->set('some_metric', 2, { some_label => "aaa" }); $p->set('some_metric', 7, { other_label => "bbb" }); is $p->format, <new; $p->set('some_metric', 3, { some_label => "aaa" }); $p->set('some_metric', 8, { some_label => "bbb" }); is $p->format, <new; $p->set('some_metric', 5, { some_label => 'aaa' }, 1234); is $p->format, <new; $p->set('some_metric', 5, { some_label => "aaa" }, 1234); $p->set('other_metric', 10, { other_label => "bbb" }, 2345); is $p->format, <new; $p->set('some_metric', 5, { some_label => "aaa" }, 1234); $p->set('some_metric', 5, { some_label => "bbb" }, 2345); $p->set('some_metric', 5, { some_label => "ccc" }, 3456); $p->set('other_metric', 10, { other_label => "bbb" }, 4567); is $p->format, <new; $p->set('some_metric', 5, { some_label => "a\\\n\n\\aa\\" }, 1234); $p->set('some_metric', 5, { some_label => "b\nbb\nx" }, 2345); $p->set('some_metric', 5, { some_label => 'ccc""' }, 3456); $p->set('other_metric', 10, { other_label => "bbb" }, 4567); is $p->format, <<'EOF', 'multiple metrics with escaped char labels and timestamps formatted correctly'; other_metric{other_label="bbb"} 10 4567 some_metric{some_label="a\\\n\n\\aa\\"} 5 1234 some_metric{some_label="b\nbb\nx"} 5 2345 some_metric{some_label="ccc\"\""} 5 3456 EOF } { my $p = Prometheus::Tiny->new; $p->set('some_metric', 5, { some_label => "aaa" }, 1234); $p->set('other_metric', 10); is $p->format, <new(default_labels => { default_label => 'frob' }); $p->set('some_metric', 10); is $p->format, <new(default_labels => { default_one => 'whiz', default_two => 'bang', }); $p->set('some_metric', 10); is $p->format, <new(default_labels => { default_one => 'whiz', default_two => 'bang', }); $p->set('some_metric', 10, { other => 'pow', default_two => 'blam' }); is $p->format, <new; $p->declare('some_metric', help => 'My great metric', type => 'counter'); $p->declare('other_metric', help => 'My other great metric', type => 'gauge'); $p->set('some_metric', 5); $p->set('other_metric', 10); is $p->format, <clear; is $p->format, <set('some_metric', 20); $p->set('other_metric', 30); is $p->format, <new; $p->declare('help', help => 'my help metric', type => 'gauge'); $p->set('help', 1234); is $p->format, <set('help', 2345, {}, 3456); is $p->format, <new; is $p->format, '', 'no metrics produces no output'; } { my $p = Prometheus::Tiny->new; $p->set('some_metric', 5); is $p->format, <new; $p->set('some_metric', 5); $p->set('other_metric', 10); is $p->format, <new; $p->set('some_metric', 3); $p->set('some_metric', 8); is $p->format, <new; $p->set('some_metric', 5, {}, 1234); is $p->format, <new; $p->set('some_metric', 5, {}, 2345); $p->set('other_metric', 10, {}, 1234); is $p->format, <new; $p->set('some_metric', 3, {}, 1234); $p->set('some_metric', 8, {}, 2345); is $p->format, <new; $p->declare('some_state', enum => 'state', enum_values => [qw(FOO BAR BAZ)]); $p->enum_set('some_state', 'FOO'); is $p->format, <new; $p->declare('some_state', enum => 'state', enum_values => [qw(FOO BAR BAZ)]); $p->enum_set('some_state', 'BAR', { one => "1", two => "2" }); is $p->format, < Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Perl Artistic License 1.0 --- This software is Copyright (c) 2018 by Rob Norris. This is free software, licensed under: The Perl Artistic License 1.0 The "Artistic License" Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whoever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End Prometheus-Tiny-0.011/Makefile.PL0000644000175000017500000000244014476215320015227 0ustar robnrobn# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.030. use strict; use warnings; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "A tiny Prometheus client", "AUTHOR" => "Rob Norris ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "Prometheus-Tiny", "LICENSE" => "perl", "NAME" => "Prometheus::Tiny", "PREREQ_PM" => { "Carp" => 0, "Scalar::Util" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "HTTP::Request::Common" => 0, "Plack::Test" => 0, "Test::Exception" => 0, "Test::More" => 0, "Test::Warn" => 0 }, "VERSION" => "0.011", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "HTTP::Request::Common" => 0, "Plack::Test" => 0, "Scalar::Util" => 0, "Test::Exception" => 0, "Test::More" => 0, "Test::Warn" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); Prometheus-Tiny-0.011/META.json0000644000175000017500000002425114476215320014702 0ustar robnrobn{ "abstract" : "A tiny Prometheus client", "author" : [ "Rob Norris " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.030, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "Prometheus-Tiny", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "runtime" : { "requires" : { "Carp" : "0", "Scalar::Util" : "0", "strict" : "0", "warnings" : "0" } }, "test" : { "requires" : { "HTTP::Request::Common" : "0", "Plack::Test" : "0", "Test::Exception" : "0", "Test::More" : "0", "Test::Warn" : "0" } } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/robn/Prometheus-Tiny/issues" }, "homepage" : "https://github.com/robn/Prometheus-Tiny", "repository" : { "type" : "git", "url" : "https://github.com/robn/Prometheus-Tiny.git", "web" : "https://github.com/robn/Prometheus-Tiny" } }, "version" : "0.011", "x_Dist_Zilla" : { "perl" : { "version" : "5.036000" }, "plugins" : [ { "class" : "Dist::Zilla::Plugin::PruneCruft", "name" : "@Filter/PruneCruft", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::ManifestSkip", "name" : "@Filter/ManifestSkip", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::MetaYAML", "name" : "@Filter/MetaYAML", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::License", "name" : "@Filter/License", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::Readme", "name" : "@Filter/Readme", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::ExtraTests", "name" : "@Filter/ExtraTests", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::ExecDir", "name" : "@Filter/ExecDir", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::ShareDir", "name" : "@Filter/ShareDir", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::MakeMaker", "config" : { "Dist::Zilla::Role::TestRunner" : { "default_jobs" : 1 } }, "name" : "@Filter/MakeMaker", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::Manifest", "name" : "@Filter/Manifest", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::TestRelease", "name" : "@Filter/TestRelease", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::ConfirmRelease", "name" : "@Filter/ConfirmRelease", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::UploadToCPAN", "name" : "@Filter/UploadToCPAN", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::GatherDir", "config" : { "Dist::Zilla::Plugin::GatherDir" : { "exclude_filename" : [ "LICENSE", "Makefile.PL" ], "exclude_match" : [], "follow_symlinks" : 0, "include_dotfiles" : 0, "prefix" : "", "prune_directory" : [], "root" : "." } }, "name" : "GatherDir", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::AutoPrereqs", "name" : "AutoPrereqs", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::PkgVersion", "name" : "PkgVersion", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::MetaConfig", "name" : "MetaConfig", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::MetaJSON", "name" : "MetaJSON", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::NextRelease", "name" : "NextRelease", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::GithubMeta", "name" : "GithubMeta", "version" : "0.58" }, { "class" : "Dist::Zilla::Plugin::Git::Check", "config" : { "Dist::Zilla::Plugin::Git::Check" : { "untracked_files" : "die" }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "Makefile.PL", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.39.2", "repo_root" : "." } }, "name" : "@Git/Check", "version" : "2.048" }, { "class" : "Dist::Zilla::Plugin::Git::Commit", "config" : { "Dist::Zilla::Plugin::Git::Commit" : { "add_files_in" : [], "commit_msg" : "v%V%n%n%c", "signoff" : 0 }, "Dist::Zilla::Role::Git::DirtyFiles" : { "allow_dirty" : [ "Changes", "Makefile.PL", "dist.ini" ], "allow_dirty_match" : [], "changelog" : "Changes" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.39.2", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Commit", "version" : "2.048" }, { "class" : "Dist::Zilla::Plugin::Git::Tag", "config" : { "Dist::Zilla::Plugin::Git::Tag" : { "branch" : null, "changelog" : "Changes", "signed" : 0, "tag" : "0.011", "tag_format" : "%v", "tag_message" : "v%V" }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.39.2", "repo_root" : "." }, "Dist::Zilla::Role::Git::StringFormatter" : { "time_zone" : "local" } }, "name" : "@Git/Tag", "version" : "2.048" }, { "class" : "Dist::Zilla::Plugin::Git::Push", "config" : { "Dist::Zilla::Plugin::Git::Push" : { "push_to" : [ "origin" ], "remotes_must_exist" : 1 }, "Dist::Zilla::Role::Git::Repo" : { "git_version" : "2.39.2", "repo_root" : "." } }, "name" : "@Git/Push", "version" : "2.048" }, { "class" : "Dist::Zilla::Plugin::ReadmeAnyFromPod", "config" : { "Dist::Zilla::Role::FileWatcher" : { "version" : "0.006" } }, "name" : "MarkdownInRoot", "version" : "0.163250" }, { "class" : "Dist::Zilla::Plugin::CopyFilesFromBuild", "name" : "CopyFilesFromBuild", "version" : "0.170880" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":InstallModules", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":IncModules", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":TestFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExtraTestFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ExecFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":PerlExecFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":ShareFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":MainModule", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":AllFiles", "version" : "6.030" }, { "class" : "Dist::Zilla::Plugin::FinderCode", "name" : ":NoFiles", "version" : "6.030" } ], "zilla" : { "class" : "Dist::Zilla::Dist::Builder", "config" : { "is_trial" : 0 }, "version" : "6.030" } }, "x_generated_by_perl" : "v5.36.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.37", "x_spdx_expression" : "Artistic-1.0-Perl OR GPL-1.0-or-later" } Prometheus-Tiny-0.011/README0000644000175000017500000000054714476215320014143 0ustar robnrobnThis archive contains the distribution Prometheus-Tiny, version 0.011: A tiny Prometheus client This software is copyright (c) 2018 by Rob Norris. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. This README file was generated by Dist::Zilla::Plugin::Readme v6.030. Prometheus-Tiny-0.011/MANIFEST0000644000175000017500000000060114476215320014403 0ustar robnrobn# This file was automatically generated by Dist::Zilla::Plugin::Manifest v6.030. Changes LICENSE MANIFEST META.json META.yml Makefile.PL README dist.ini lib/Prometheus/Tiny.pm t/00-load.t t/10-set.t t/11-add.t t/12-inc-dec.t t/15-labels.t t/16-labels-add.t t/20-declare.t t/21-clear.t t/22-declare-unique.t t/30-psgi.t t/40-histogram.t t/41-enum.t t/50-warn-undef.t t/900-regression.t Prometheus-Tiny-0.011/lib/0000755000175000017500000000000014476215320014023 5ustar robnrobnPrometheus-Tiny-0.011/lib/Prometheus/0000755000175000017500000000000014476215320016156 5ustar robnrobnPrometheus-Tiny-0.011/lib/Prometheus/Tiny.pm0000644000175000017500000002524014476215320017442 0ustar robnrobnpackage Prometheus::Tiny; $Prometheus::Tiny::VERSION = '0.011'; # ABSTRACT: A tiny Prometheus client use warnings; use strict; use Carp qw(croak carp); use Scalar::Util qw(looks_like_number); my $DEFAULT_BUCKETS = [ 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 ]; sub new { my ($class, %arg) = @_; my %defaults = $arg{default_labels} ? %{$arg{default_labels}} : (); return bless { metrics => {}, meta => {}, default_labels => \%defaults, }, $class; } sub _format_labels { my ($self, $labels) = @_; # Avoid copying the labels hash unless we need to add defaults. my $to_format = $self->{default_labels} ? { %{$self->{default_labels}}, %{$labels || {}} } : $labels; join ',', map { my $lv = $to_format->{$_}; if (defined $lv) { $lv =~ s/(["\\])/\\$1/sg; $lv =~ s/\n/\\n/sg; qq{$_="$lv"} } else { carp "label '$_' has an undefined value, dropping it"; () } } sort keys %$to_format; } sub set { my ($self, $name, $value, $labels, $timestamp) = @_; unless (looks_like_number $value) { carp "setting '$name' to non-numeric value, using 0 instead"; $value = 0; } my $f_label = $self->_format_labels($labels); $self->{metrics}{$name}{$f_label} = [ $value, $timestamp ]; return; } sub add { my ($self, $name, $value, $labels) = @_; unless (looks_like_number $value) { carp "adjusting '$name' by non-numeric value, adding 0 instead"; $value = 0; } $self->{metrics}{$name}{$self->_format_labels($labels)}->[0] += $value; return; } sub inc { my ($self, $name, $labels) = @_; return $self->add($name, 1, $labels); } sub dec { my ($self, $name, $labels) = @_; return $self->add($name, -1, $labels); } sub clear { my ($self, $name) = @_; $self->{metrics} = {}; return; } sub histogram_observe { my ($self, $name, $value, $labels) = @_; $self->inc($name.'_count', $labels); $self->add($name.'_sum', $value, $labels); my @buckets = @{$self->{meta}{$name}{buckets} || $DEFAULT_BUCKETS}; my $bucket_metric = $name.'_bucket'; for my $bucket (@buckets) { $self->add($bucket_metric, $value <= $bucket ? 1 : 0, { %{$labels || {}} , le => $bucket }); } $self->inc($bucket_metric, { %{$labels || {}}, le => '+Inf' }); return; } sub enum_set { my ($self, $name, $value, $labels, $timestamp) = @_; my $enum_label = $self->{meta}{$name}{enum} || croak "enum not declared for '$name'"; for my $ev (@{$self->{meta}{$name}{enum_values} || []}) { $self->set($name, $value eq $ev ? 1 : 0, { %{$labels || {}}, $enum_label => $ev }, $timestamp); } } sub declare { my ($self, $name, %meta) = @_; if (my $old = $self->{meta}{$name}) { if ( ((exists $old->{type} ^ exists $meta{type}) || (exists $old->{type} && $old->{type} ne $meta{type})) || ((exists $old->{help} ^ exists $meta{help}) || (exists $old->{help} && $old->{help} ne $meta{help})) || ((exists $old->{enum} ^ exists $meta{enum}) || (exists $old->{enum} && $old->{enum} ne $meta{enum})) || ((exists $old->{buckets} ^ exists $meta{buckets}) || (exists $old->{buckets} && ( @{$old->{buckets}} ne @{$meta{buckets}} || grep { $old->{buckets}[$_] != $meta{buckets}[$_] } (0 .. $#{$meta{buckets}}) )) ) || ((exists $old->{enum_values} ^ exists $meta{enum_values}) || (exists $old->{enum_values} && ( @{$old->{enum_values}} ne @{$meta{enum_values}} || grep { $old->{enum_values}[$_] ne $meta{enum_values}[$_] } (0 .. $#{$meta{enum_values}}) )) ) ) { croak "redeclaration of '$name' with mismatched meta"; } } $self->{meta}{$name} = { %meta }; return; } sub format { my ($self) = @_; my %names = map { $_ => 1 } (keys %{$self->{metrics}}, keys %{$self->{meta}}); return join '', map { my $name = $_; ( (defined $self->{meta}{$name}{help} ? ("# HELP $name $self->{meta}{$name}{help}\n") : ()), (defined $self->{meta}{$name}{type} ? ("# TYPE $name $self->{meta}{$name}{type}\n") : ()), (map { my $v = join ' ', grep { defined $_ } @{$self->{metrics}{$name}{$_}}; $_ ? join '', $name, '{', $_, '} ', $v, "\n" : join '', $name, ' ', $v, "\n" } sort { $name =~ m/_bucket$/ ? do { my $t_a = $a; $t_a =~ s/le="([^"]+)"//; my $le_a = $1; my $t_b = $b; $t_b =~ s/le="([^"]+)"//; my $le_b = $1; $t_a eq $t_b ? do { $le_a eq '+Inf' ? 1 : $le_b eq '+Inf' ? -1 : ($a cmp $b) } : ($a cmp $b) } : ($a cmp $b) } keys %{$self->{metrics}{$name}}), ) } sort keys %names; } sub psgi { my ($self) = @_; return sub { my ($env) = @_; return [ 405, [], [] ] unless $env->{REQUEST_METHOD} eq 'GET'; return [ 200, [ 'Content-Type' => 'text/plain' ], [ $self->format ] ]; }; } 1; __END__ =pod =encoding UTF-8 =for markdown [![Build Status](https://secure.travis-ci.org/robn/Prometheus-Tiny.png)](http://travis-ci.org/robn/Prometheus-Tiny) =head1 NAME Prometheus::Tiny - A tiny Prometheus client =head1 SYNOPSIS use Prometheus::Tiny; my $prom = Prometheus::Tiny->new; $prom->set('some_metric', 5, { some_label => "aaa" }); print $prom->format; =head1 DESCRIPTION C is a minimal metrics client for the L time-series database. It does the following things differently to L: =over 4 =item * No setup. You don't need to pre-declare metrics to get something useful. =item * Labels are passed in a hash. Positional parameters get awkward. =item * No inbuilt collectors, PSGI apps, etc. Just the metrics. =item * Doesn't know anything about different metric types. You get what you ask for. =back 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 L for that! =head1 CONSTRUCTOR =head2 new my $prom = Prometheus::Tiny->new; my $prom = Promethus::Tiny->new(default_labels => { my_label => "frob" }); If you pass a C key to the constructor, these labels will be included in every metric created on this object. =head1 METHODS =head2 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. =head2 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). =head2 inc $prom->inc($name, { labels }) A shortcut for $prom->add($name, 1, { labels }) =head2 dec $prom->dec($name, { labels }) A shortcut for $prom->add($name, -1, { labels }) =head2 clear $prom->clear; Remove all stored metric values. Metric metadata (set by C) is preserved. =head2 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 C 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 ] =head2 enum_set $prom->enum_set($name, $value, { labels }, [timestamp]) Set an enum value for the named metric. The labels hashref is optiona. The timestamp is optional. You should declare your metric beforehand, using the C key to set the label to use for the enum value, and the C key to list the possible values for the enum. =head2 declare $prom->declare($name, help => $help, type => $type, buckets => [...]) "Declare" a metric by associating metadata with it. Valid keys are: =over 4 =item C Text describing the metric. This will appear in the formatted output sent to Prometheus. =item C Type of the metric, typically C or C. =item C For C metrics, an arrayref of the buckets to use. See C. =item C For C metrics, the name of the label to use for the enum value. See C. =item C For C metrics, the possible values the enum can take. See C. =back Declaring a already-declared metric will work, but only if the metadata keys and values match the previous call. If not, C will throw an exception. =head2 format my $metrics = $prom->format Output the stored metrics, values, help text and types in the L. =head2 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 C, 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 C. =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 Source Code This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/robn/Prometheus-Tiny.git =head1 AUTHORS =over 4 =item * Rob Norris =back =head1 CONTRIBUTORS =over 4 =item * ben hengst =item * Danijel Tasov =item * Michael McClimon =back =head1 COPYRIGHT AND LICENSE This software is copyright (c) 2017 by Rob Norris This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. =cut Prometheus-Tiny-0.011/Changes0000644000175000017500000000225014476215320014547 0ustar robnrobnRevision history for Prometheus-Tiny 0.011 2023-09-07 10:35:27+10:00 Australia/Melbourne - Warn and handle attempts to set label values to undef 0.010 2022-02-01 08:25:56+11:00 Australia/Melbourne - Warn and handle attempts to set or add non-numbers 0.009 2021-12-07 16:46:15+11:00 Australia/Melbourne - Add default_labels parameter (thanks, Michael McClimon!) 0.008 2021-07-21 14:27:16+10:00 Australia/Melbourne - Add enum support 0.007 2021-06-04 09:57:21+10:00 Australia/Melbourne - Ensure that a metric is not redeclared with different metadata 0.006 2021-04-14 16:25:31+10:00 Australia/Melbourne - Add clear method, to remove metric values 0.005 2020-12-03 21:41:43+11:00 Australia/Melbourne - Escape special chars in label values (thanks, Danijel Tasov!) 0.004 2019-12-22 12:17:34+11:00 Australia/Melbourne - Fix bug where metrics named "help" or "type" with timestamps would break 0.003 2019-12-22 11:17:22+11:00 Australia/Melbourne - Add histogram support - Add timestamp support (ben hengst) 0.002 2018-08-09 12:58:34+10:00 Australia/Melbourne - Add simple PSGI app generator 0.001 2018-07-27 23:20:19+10:00 Australia/Melbourne