Monitor::MetricsAPI::Metric::Callback - Callback metric class for Monitor::MetricsAPI
use Monitor::MetricsAPI; use DateTime; # Put into scope first so we can capture it as part of the callback sub. my $collector; $collector = Monitor::MetricsAPI->new( metrics => { process => { started => 'timestamp' }, messages => { incoming => { total => 'counter', per_min => sub { $collector->metric('messages/incoming/total')->value / DateTime->now()->delta_ms( $collector->metric('process/started')->dt )->in_units('minutes') }, } } } ); $collector->metric('process/started')->now;
Boolean metrics allow you to track the true/false/unknown state of something in your application. All boolean metrics are initialized as unknown and must be explicitly set to either true or false.
Callback metrics do not provide any additional methods not already offered by Monitor::MetricsAPI::Metric. You may call the set() method at any time to updated the callback function that will be used when the metric is displayed.
Allows you to provide a new subroutine to be invoked for the callback metric.
Overrides the value() method provided by the base Metric class. Invoking this method will run the callback subroutine. For expensive callbacks, you are very strongly advised to consider incorporating some reasonable caching mechanism so that unnecessary computations can be avoided during metrics reporting.
Jon Sime <jonsime@gmail.com>
This software is copyright (c) 2015 by OmniTI Computer Consulting, Inc.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
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.
To install Monitor::MetricsAPI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Monitor::MetricsAPI
CPAN shell
perl -MCPAN -e shell install Monitor::MetricsAPI
For more information on module installation, please visit the detailed CPAN module installation guide.