File Coverage

blib/lib/Net/Prometheus/PerlCollector.pm
Criterion Covered Total %
statement 9 13 69.2
branch n/a
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 20 60.0


line stmt bran cond sub pod time code
1             # You may distribute under the terms of either the GNU General Public License
2             # or the Artistic License (the same terms as Perl itself)
3             #
4             # (C) Paul Evans, 2018 -- leonerd@leonerd.org.uk
5              
6             package Net::Prometheus::PerlCollector;
7              
8 1     1   636 use strict;
  1         2  
  1         25  
9 1     1   5 use warnings;
  1         2  
  1         53  
10              
11             our $VERSION = '0.01';
12              
13             require XSLoader;
14             XSLoader::load( __PACKAGE__, $VERSION );
15              
16 1     1   404 use Net::Prometheus::Types qw( MetricSamples Sample );
  1         2347  
  1         135  
17              
18             =head1 NAME
19              
20             C - obtain statistics about the perl interpreter
21              
22             =head1 SYNOPSIS
23              
24             use Net::Prometheus;
25             use Net::Prometheus::PerlCollector;
26              
27             my $client = Net::Prometheus->new;
28             $client->register( Net::Prometheus::PerlCollector->new );
29              
30             =head1 DESCRIPTION
31              
32             This module provides a class that collects metrics about the perl interpreter
33             itself.
34              
35             =head2 Metrics
36              
37             The following metrics are collected:
38              
39             =over 2
40              
41             =item * C
42              
43             A gauge giving the number of arenas the heap is split into.
44              
45             =item * C
46              
47             A gauge giving the total number of SVs allocated on the heap.
48              
49             =back
50              
51             Note that the way these metrics are collected requires counting them all every
52             time. While this code is relatively efficient, it is still a linear scan, and
53             may itself cause some slowdown of the process at the time it is collected, if
54             the heap has grown very large, containing a great number of SVs.
55              
56             =cut
57              
58             sub new
59             {
60 0     0 0   my $class = shift;
61              
62 0           return bless {}, $class;
63             }
64              
65             sub collect
66             {
67 0     0 0   my ( $arenas, $svs ) = count_heap();
68              
69             return
70 0           MetricSamples( "perl_heap_arenas", gauge => "Number of arenas in the Perl heap",
71             [ Sample( "perl_heap_arenas", [], $arenas ) ] ),
72             MetricSamples( "perl_heap_svs", gauge => "Number of SVs in the Perl heap",
73             [ Sample( "perl_heap_svs", [], $svs ) ] );
74             }
75              
76             =head1 AUTHOR
77              
78             Paul Evans
79              
80             =cut
81              
82             0x55AA;