This file is indexed.

/usr/share/perl5/Net/Prometheus/Gauge.pm is in libnet-prometheus-perl 0.05-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#  You may distribute under the terms of either the GNU General Public License
#  or the Artistic License (the same terms as Perl itself)
#
#  (C) Paul Evans, 2016 -- leonerd@leonerd.org.uk

package Net::Prometheus::Gauge;

use strict;
use warnings;
use base qw( Net::Prometheus::Metric );

our $VERSION = '0.05';

use Carp;

use constant _type => "gauge";

__PACKAGE__->MAKE_child_class;

=head1 NAME

C<Net::Prometheus::Gauge> - a snapshot value-reporting metric

=head1 SYNOPSIS

   use Net::Prometheus;

   my $client = Net::Prometheus->new;

   my $gauge = $client->new_gauge(
      name => "users",
      help => "Number of current users",
   );

   my %users;
   ...

   $gauge->set( scalar keys %users );

=head1 DESCRIPTION

This class provides a gauge metric - an arbitrary value that observes some
snapshot of state at some instant in time. This is often used to report on the
current usage of resources by the instrumented program, in a way that can
decrease as well as increase. It is a subclass of L<Net::Prometheus::Metric>.

=head2 Value-Reporting Functions

As an alternative to using the C<set> method to update the value of the gauge,
a callback function can be used instead which should return the current value
to report for that gauge. This function is invoked at collection time, meaning
the reported value is up-to-date.

These functions are invoked inline as part of the collection process, so they
should be as small and lightweight as possible. Typical applications involve
reporting the size of an array or hash within the implementation's code.

   $gauge->set_function( sub { scalar @items } );

   $gauge->set_function( sub { scalar keys %things } );

=cut

=head1 CONSTRUCTOR

Instances of this class are not usually constructed directly, but instead via
the L<Net::Prometheus> object that will serve it:

   $gauge = $prometheus->new_gauge( %args )

This takes the same constructor arguments as documented in
L<Net::Prometheus::Metric>.

=cut

sub new
{
   my $class = shift;

   my $self = $class->SUPER::new( @_ );

   $self->{values}    = {};
   $self->{functions} = {};

   $self->inc( 0 ) if !$self->labelcount;

   return $self;
}

=head1 METHODS

=cut

=head2 set

   $gauge->set( [ @label_values ], $value )

   $child->set( $value )

Sets the current value for the gauge.

If the gauge has any labels defined, the values for them must be given first.

=cut

__PACKAGE__->MAKE_child_method( 'set' );
sub _set_child
{
   my $self = shift;
   my ( $labelkey, $value ) = @_;

   $self->{values}{$labelkey} = $value;
}

=head2 set_function

   $gauge->set_function( [ @label_values ], $func )

   $child->set_function( $func )

Sets a value-returning callback function for the gauge. If the gauge is
labeled, each label combination requires its own function.

When invoked, the function will be passed no arguments and is expected to
return a single value

   $value = $func->()

=cut

__PACKAGE__->MAKE_child_method( 'set_function' );
sub _set_function_child
{
   my $self = shift;
   my ( $labelkey, $func ) = @_;

   $self->{functions}{$labelkey} = $func;
}

=head2 inc

   $gauge->inc( [ @label_values ], $delta )

   $child->inc( $delta )

Increment the current value for the gauge. C<$delta> will default to 1 if not
supplied.

=cut

__PACKAGE__->MAKE_child_method( 'inc' );
sub _inc_child
{
   my $self = shift;
   my ( $labelkey, $delta ) = @_;
   defined $delta or $delta = 1;

   $self->{values}{$labelkey} += $delta;
}

=head2 dec

   $gauge->dec( [ @label_values ], $delta )

   $child->dec( $delta )

Decrement the current value for the gauge. C<$delta> will default to 1 if not
supplied.

=cut

__PACKAGE__->MAKE_child_method( 'dec' );
sub _dec_child
{
   my $self = shift;
   my ( $labelkey, $delta ) = @_;
   defined $delta or $delta = 1;

   $self->{values}{$labelkey} -= $delta;
}

sub samples
{
   my $self = shift;

   my $values    = $self->{values};
   my $functions = $self->{functions};

   return map {
      $self->make_sample( undef, $_,
         $functions->{$_} ? $functions->{$_}->() : $values->{$_}
      )
   } sort keys %$values;
}

=head1 AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

=cut

0x55AA;