Dancer2-Plugin-PrometheusTiny
view release on metacpan or search on metacpan
Changes
lib/Dancer2/Plugin/PrometheusTiny.pm
maint/Makefile.PL.include
Makefile.PL
MANIFEST This list of files
t/config.yml
t/endpoint.t
t/include_default_metrics.t
t/metrics.t
t/environments/endpoint.yml
t/environments/include_default_metrics.yml
t/environments/metrics.yml
t/lib/TestApp.pm
META.yml Module YAML meta-data (added by MakeMaker)
META.json Module JSON meta-data (added by MakeMaker)
README README file (added by Distar)
LICENSE LICENSE file (added by Distar)
NAME
Dancer2::Plugin::PrometheusTiny - use Prometheus::Tiny with Dancer2
SYNOPSIS
DESCRIPTION
This plugin integrates Prometheus::Tiny::Shared with your Dancer2 app,
providing some default metrics for requests and responses, with the
ability to easily add further metrics to your app. A route is added
which makes the metrics available via the configured "endpoint".
See Prometheus::Tiny for more details of the kind of metrics supported.
The following metrics are included by default:
http_request_duration_seconds => {
help => 'Request durations in seconds',
type => 'histogram',
},
http_request_size_bytes => {
prometheus->inc(...);
}
Returns the "Prometheus::Tiny::Shared" instance.
CONFIGURATION
Example:
plugins:
PrometheusTiny:
endpoint: /prometheus-metrics # default: /metrics
filename: /run/d2prometheus # default: (undef)
include_default_metrics: 0 # default: 1
metrics: # default: {}
http_request_count:
help: HTTP Request count
type: counter
See below for full details of each configuration setting.
endpoint
The endpoint from which metrics are served. Defaults to "/metrics".
filename
It is recommended that this is set to a directory on a memory-backed
filesystem. See "filename" in Prometheus::Tiny::Shared for details and
default value.
include_default_metrics
Defaults to true. If set to false, then the default metrics shown in
"DESCRIPTION" will not be added.
lib/Dancer2/Plugin/PrometheusTiny.pm view on Meta::CPAN
http_response_size_bytes => {
help => 'Response sizes in bytes',
type => 'histogram',
buckets => [ 1, 50, 100, 1_000, 50_000, 500_000, 1_000_000 ],
}
};
}
# CONFIG
has endpoint => (
is => 'ro',
isa => Str,
from_config => sub {'/metrics'},
);
has filename => (
is => 'ro',
isa => Maybe [Str],
from_config => sub {undef},
);
lib/Dancer2/Plugin/PrometheusTiny.pm view on Meta::CPAN
code => sub {
my $response = shift;
$plugin->_add_default_metrics($response);
},
)
);
}
$app->add_route(
method => 'get',
regexp => $plugin->endpoint,
code => sub {
my $app = shift;
$plugin->execute_plugin_hook(
'before_format', $app,
$prometheus
);
my $response = $app->response;
$response->content_type('text/plain');
$response->content( $plugin->prometheus->format );
$response->halt;
lib/Dancer2/Plugin/PrometheusTiny.pm view on Meta::CPAN
Dancer2::Plugin::PrometheusTiny - use Prometheus::Tiny with Dancer2
=head1 SYNOPSIS
=head1 DESCRIPTION
This plugin integrates L<Prometheus::Tiny::Shared> with your L<Dancer2> app,
providing some default metrics for requests and responses, with the ability
to easily add further metrics to your app. A route is added which makes
the metrics available via the configured L</endpoint>.
See L<Prometheus::Tiny> for more details of the kind of metrics supported.
The following metrics are included by default:
http_request_duration_seconds => {
help => 'Request durations in seconds',
type => 'histogram',
},
http_request_size_bytes => {
lib/Dancer2/Plugin/PrometheusTiny.pm view on Meta::CPAN
}
Returns the C<Prometheus::Tiny::Shared> instance.
=head1 CONFIGURATION
Example:
plugins:
PrometheusTiny:
endpoint: /prometheus-metrics # default: /metrics
filename: /run/d2prometheus # default: (undef)
include_default_metrics: 0 # default: 1
metrics: # default: {}
http_request_count:
help: HTTP Request count
type: counter
See below for full details of each configuration setting.
=head2 endpoint
The endpoint from which metrics are served. Defaults to C</metrics>.
=head2 filename
It is recommended that this is set to a directory on a memory-backed
filesystem. See L<Prometheus::Tiny::Shared/filename> for details and default
value.
=head2 include_default_metrics
Defaults to true. If set to false, then the default metrics shown in
t/endpoint.t view on Meta::CPAN
use strict;
use warnings;
use HTTP::Request::Common;
use Plack::Test;
use Test::More;
use lib 'lib', 't/lib';
BEGIN {
$ENV{DANCER_ENVIRONMENT} = 'endpoint';
}
use TestApp;
my $app = TestApp->to_app;
my $test = Plack::Test->create($app);
ok $test->request( GET '/' ), "GET / so we have HTTP_OK metrics";
my $res = $test->request( GET '/metrics' );
is $res->code, 404, "default endpoint /metrics NOT_FOUND";
$res = $test->request( GET '/test-metrics' );
is $res->code, 200, "endpoint /test-metrics OK";
like $res->content, qr/http_requests_total\{code="200",method="GET"\} 1/,
"... and we see OK request in metrics";
like $res->content, qr/http_requests_total\{code="404",method="GET"\} 1/,
"... and we see NOT_FOUND request in metrics";
done_testing;
t/environments/endpoint.yml view on Meta::CPAN
plugins:
PrometheusTiny:
endpoint: /test-metrics
( run in 0.481 second using v1.01-cache-2.11-cpan-b61123c0432 )