Skip to content

Instantly share code, notes, and snippets.

@SysPete
Last active June 7, 2021 15:12
Show Gist options
  • Save SysPete/133807602562e49d0af436c9260965c4 to your computer and use it in GitHub Desktop.
Save SysPete/133807602562e49d0af436c9260965c4 to your computer and use it in GitHub Desktop.
# 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