Last active
June 7, 2021 15:12
-
-
Save SysPete/133807602562e49d0af436c9260965c4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In your app class: | |
__PACKAGE__->config( | |
'Plugin::PrometheusTiny' => { | |
metrics => [ | |
{ | |
name => 'http_request_count_by_route', | |
help => 'HTTP request count by route', | |
type => 'counter', | |
}, | |
{ | |
name => 'http_request_duration_by_route', | |
help => 'HTTP request duration by route', | |
type => 'gauge', | |
} | |
] | |
} | |
); | |
after finalize => sub { | |
my $c = shift; | |
my $req = $c->request; | |
if ( $c->response->code == 200 ) { | |
$c->prometheus->inc( 'http_request_count_by_route', | |
{ method => $req->method, path => $req->path } ); | |
$c->prometheus->set( 'http_request_duration_by_route', $c->stats->elapsed, | |
{ method => $req->method, path => $req->path } ); | |
} | |
} | |
# or abuse the plugin in your model (or elsewhere): | |
use Catalyst::Plugin::PrometheusTiny; | |
Catalyst::Plugin::PrometheusTiny->prometheus->inc( 'some_metric', { %labels }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment