The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojolicious::Plugin::Prometheus - Mojolicious Plugin

SYNOPSIS

  # Mojolicious
  $self->plugin('Prometheus');

  # Mojolicious::Lite
  plugin 'Prometheus';

  # Mojolicious::Lite, with custom response buckets (seconds)
  plugin 'Prometheus' => { response_buckets => [qw/4 5 6/] };

DESCRIPTION

Mojolicious::Plugin::Prometheus is a Mojolicious plugin that exports Prometheus metrics from Mojolicious.

Hooks are also installed to measure requests response time and count requests based on method and HTTP return code.

HELPERS

prometheus

Create further instrumentation into your application by using this helper which gives access to the Net::Prometheus object. See Net::Prometheus for usage.

METHODS

Mojolicious::Plugin::Prometheus inherits all methods from Mojolicious::Plugin and implements the following new ones.

register

  $plugin->register($app, \%config);

Register plugin in Mojolicious application.

%config can have:

  • path

    The path to mount the exporter.

    Default: /metrics

  • prometheus

    Override the Net::Prometheus object. The default is a new singleton instance of Net::Prometheus.

  • namespace, subsystem

    These will be prefixed to the metrics exported.

  • request_buckets

    Override buckets for request sizes histogram.

    Default: (1, 50, 100, 1_000, 10_000, 50_000, 100_000, 500_000, 1_000_000)

  • response_buckets

    Override buckets for response sizes histogram.

    Default: (5, 50, 100, 1_000, 10_000, 50_000, 100_000, 500_000, 1_000_000)

  • duration_buckets

    Override buckets for request duration histogram.

    Default: (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) (actually see Net::Prometheus)

METRICS

In addition to exposing the default process metrics that Net::Prometheus already expose this plugin will also expose

  • http_requests_total, request counter partitioned over HTTP method and HTTP response code

  • http_request_duration_seconds, request duration histogram partitioned over HTTP method

  • http_request_size_bytes, request size histogram partitioned over HTTP method

  • http_response_size_bytes, response size histogram partitioned over HTTP method

RUNNING UNDER HYPNOTOAD

When running under a preforking daemon like Hypnotoad, you will not get global metrics but only the metrics of each worker, randomly.

The worker label will include the pid of the current worker so metrics can be aggregated per worker in Prometheus.

If you prefer to get the global metrics from any worker, then see Mojolicious::Plugin::Prometheus::Shared::FastMmap for a possible solution.

AUTHOR

Vidar Tyldum

COPYRIGHT AND LICENSE

Copyright (C) 2017, Vidar Tyldum

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

Mojolicious::Plugin::Prometheus::Shared::FastMmap
Net::Prometheus
Mojolicious
Mojolicious::Guides
http://mojolicious.org