| 1 | 14 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 14 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Monitor::MetricsAPI::MetricFactory; | ||||||||||
| 5 | 14 | $Monitor::MetricsAPI::MetricFactory::VERSION = '0.900'; | |||||||||
| 6 | 14 | ▶ | use Module::Loaded; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 14 | ▶ | use Monitor::MetricsAPI::Metric; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | |||||||||||
| 10 | 14 | ▶ | use Monitor::MetricsAPI::Metric::Boolean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 14 | ▶ | use Monitor::MetricsAPI::Metric::Callback; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 14 | ▶ | use Monitor::MetricsAPI::Metric::Counter; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 14 | ▶ | use Monitor::MetricsAPI::Metric::Gauge; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 14 | ▶ | use Monitor::MetricsAPI::Metric::List; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 14 | ▶ | use Monitor::MetricsAPI::Metric::String; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 14 | ▶ | use Monitor::MetricsAPI::Metric::Timestamp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | |||||||||||
| 18 | =head1 NAME | ||||||||||
| 19 | |||||||||||
| 20 | Monitor::MetricsAPI::MetricFactory - Factory for creating Metric::* objects. | ||||||||||
| 21 | |||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||
| 23 | |||||||||||
| 24 | You should not interact with this module directly in your code. Please refer to | ||||||||||
| 25 | L<Monitor::MetricsAPI> for how to integrate this service with your application. | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | This module provides a factory pattern for creating individual metric objects. | ||||||||||
| 30 | The intent is for L<Monitor::MetricsAPI::Collector> to use this when building | ||||||||||
| 31 | the collector, as well as any time new metrics are added to an existing | ||||||||||
| 32 | collector. | ||||||||||
| 33 | |||||||||||
| 34 | =head1 METHODS | ||||||||||
| 35 | |||||||||||
| 36 | =head2 create (%options) | ||||||||||
| 37 | |||||||||||
| 38 | Accepts a hash of options describing a metric, and returns the appropriate type | ||||||||||
| 39 | of metric object. Valid entries in the options hash are: | ||||||||||
| 40 | |||||||||||
| 41 | =over | ||||||||||
| 42 | |||||||||||
| 43 | =item * name | ||||||||||
| 44 | |||||||||||
| 45 | A string containing the full name (including all parent groups) for the metric. | ||||||||||
| 46 | As detailed in L<Monitor::MetricsAPI::Tutorial>, full metric names are | ||||||||||
| 47 | slash-delimited strings of the form "<group>/<subgroup>/<metric>" and there may | ||||||||||
| 48 | be as many or as few subgroups as you choose. | ||||||||||
| 49 | |||||||||||
| 50 | Example: | ||||||||||
| 51 | |||||||||||
| 52 | process/workers/current_threads | ||||||||||
| 53 | |||||||||||
| 54 | =item * type | ||||||||||
| 55 | |||||||||||
| 56 | A string naming the type of metric to be created. This will match the last | ||||||||||
| 57 | component of the metric class's name, in lowercase. Thus, a metric of the class | ||||||||||
| 58 | L<Monitor::MetricsAPI::Metric::Boolean> would have a type of "boolean". | ||||||||||
| 59 | |||||||||||
| 60 | =item * callback | ||||||||||
| 61 | |||||||||||
| 62 | A subroutine to be invoked every time the metric is included in API output, or | ||||||||||
| 63 | when the metric's value() method is called. Relevant only for metrics of type | ||||||||||
| 64 | 'callback'. | ||||||||||
| 65 | |||||||||||
| 66 | =back | ||||||||||
| 67 | |||||||||||
| 68 | =cut | ||||||||||
| 69 | |||||||||||
| 70 | 17 | ▶ | sub create { | ||||||||
|
Subroutine
create: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||
| 71 | 17 | my ($class, %options) = @_; | |||||||||
| 72 | |||||||||||
| 73 | 17 | ▶ | die "must pass metric options as a hash" unless %options; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 74 | 17 | ▶ | die "must indicate the type of metric to create" unless exists $options{'type'}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 75 | |||||||||||
| 76 | 17 | my $type = ucfirst($options{'type'}); | |||||||||
| 77 | 17 | my $pkg = "Monitor::MetricsAPI::Metric::$type"; | |||||||||
| 78 | |||||||||||
| 79 | 17 | ▶ | die $options{'type'} . " is not a valid metric type" unless is_loaded($pkg); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | |||||||||||
| 81 | 17 | return $pkg->new(%options); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | =head1 AUTHORS | ||||||||||
| 85 | |||||||||||
| 86 | Jon Sime <jonsime@gmail.com> | ||||||||||
| 87 | |||||||||||
| 88 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 89 | |||||||||||
| 90 | This software is copyright (c) 2015 by OmniTI Computer Consulting, Inc. | ||||||||||
| 91 | |||||||||||
| 92 | This module is free software; you can redistribute it and/or | ||||||||||
| 93 | modify it under the same terms as Perl itself. See L<perlartistic>. | ||||||||||
| 94 | |||||||||||
| 95 | This program is distributed in the hope that it will be useful, | ||||||||||
| 96 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 97 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||
| 98 | |||||||||||
| 99 | =cut | ||||||||||
| 100 | |||||||||||
| 101 | 14 | 1; | |||||||||