SignalFx.pm

filter: Statementstmt 96.5% 28 / 29 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 91.8% 34 / 37 CC 5 SCAR 8.5
CC
5
Cov
94%
send
3.0
_labels
3.0
BEGIN
1.0
CRAP 2.3
« Statsd.pm ↑ Summary
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, 2020-2026 -- leonerd@leonerd.org.uk
5  
6 package Metrics::Any::Adapter::SignalFx 0.04;
7  
8 2 ▶use v5.14;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use base qw( Metrics::Any::Adapter::Statsd );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # See also
13 # https://docs.signalfx.com/en/latest/integrations/agent/monitors/collectd-statsd.html
14  
15 =head1 NAME
16  
17 C<Metrics::Any::Adapter::SignalFx> - a metrics reporting adapter for SignalFx
18  
19 =head1 SYNOPSIS
20  
21 =for highlighter language=perl
22  
23 use Metrics::Any::Adapter 'SignalFx';
24  
25 =head1 DESCRIPTION
26  
27 This extension of L<Metrics::Any::Adapter::Statsd> supports the additional tag
28 reporting syntax defined by F<SignalFx> to report labelled metrics. Due to
29 limitations of the line-based protocol, certain characters are not allowed in
30 label names or values. Any C<[>, C<]>, C<,>, C<|>, C<=> or linefeeds are
31 replaced by C<_>.
32  
33 =cut
34  
35 sub _labels
36 6 ▶{
Subroutine _labels: called CC=3 SCAR=11.0
37 6 my ( $labelnames, $labelvalues ) = @_;
38  
39 6 my @labels;
40 6 foreach ( 0 .. $#$labelnames ) {
41 6 my $name = $labelnames->[$_];
42 6 my $value = $labelvalues->[$_];
43 # Replace disallowed characters with '_'
44 6 $_ =~ s/[][,|=\n]/_/g for $name, $value;
45  
46 6 push @labels, "$name=$value";
47 }
48  
49 6 return "[" . join( ",", @labels ) . "]";
50 }
51  
52 sub send
53 5 ▶{
Subroutine send: called CC=3 SCAR=11.1
Pod undocumented
54 5 my $self = shift;
55 5 my ( $stats, $labelnames, $labelvalues ) = @_;
56  
57 5 my %labelledstats;
58 5 ▶ if( $labelnames ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($labelnames) { } 5 0 5
59 5 foreach my $name ( keys %$stats ) {
60 6 my $value = $stats->{$name};
61 6 my @parts = split m/\./, $name;
62 6 $parts[-1] = _labels( $labelnames, $labelvalues ) . $parts[-1];
63 6 $name = join ".", @parts;
64  
65 6 $labelledstats{$name} = $value;
66 }
67 }
68 else {
69 0 %labelledstats = %$stats;
70 }
71  
72 5 $self->SUPER::send( \%labelledstats );
73 }
74  
75 =head1 AUTHOR
76  
77 Paul Evans <leonerd@leonerd.org.uk>
78  
79 =cut
80  
81 2 0x55AA;
« Statsd.pm ↑ Summary