Saftpresse/Output/Graphite.pm

filter: Statementstmt 44.1% 15 / 34 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 2 totaltotal 26.4% 18 / 68 SCAR 40.4
CC
11
Cov
28%
send_event
30.0
__ANON__
20.0
output
20.0
CRAP 56.6
« Saftpresse/Output/JSON.pm ↑ Summary Saftpresse/Plugin/Role/Tracking.pm »
1 package Log::Saftpresse::Output::Graphite;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: plugin to write events to carbon line reciever
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 extends 'Log::Saftpresse::Output';
9  
10 1 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use IO::Socket::INET;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 1 has 'prefix' => ( is => 'rw', isa => 'Str',
14 default => 'saftpresse-metric',
15 );
16  
17 1 has 'type' => ( is => 'rw', isa => 'Str',
18 default => 'metric',
19 );
20  
21 has '_handle' => (
22 is => 'rw', isa => 'IO::Socket::INET', lazy => 1,
23 default => sub {
24 0 ▶ my $self = shift;
Subroutine __ANON__: not called CC=4 SCAR=30.0
25 my $handle = IO::Socket::INET->new(
26 PeerAddr => $self->{'host'} || '127.0.0.1',
27 0 ▶ PeerPort => $self->{'port'} || '2003',
Branch: 1 branch
BranchTrueFalseTotal
my $handle = "IO::Socket::INET"->new("PeerAddr", $self->{"host"} || "127.0.0.1", "PeerPort", $self->{"port"} || 2003, "Proto", "tcp") or die 'error opening connection to graphite line reciever: ' . $@ 0 0 0
Condition0%0/4
$self->{'host'} || '127.0.0.1'
l!l
00
$self->{'port'} || '2003'
l!l
00
MC/DC0%0/1
$self->{'host'} || '127.0.0.1'
$self->{'host'}
MC/DC0%0/1
$self->{'port'} || '2003'
$self->{'port'}
Truth table0%0/2
A
A= $self->{'host'}
Aresult
11
00
Truth table0%0/2
A
A= $self->{'port'}
Aresult
11
00
28 Proto => 'tcp',
29 ) or die('error opening connection to graphite line reciever: '.$@);
30 0 return $handle;
31 },
32 1 );
33  
34 sub output {
35 0 ▶ my ( $self, @events ) = @_;
Subroutine output: not called CC=4 SCAR=30.0
Pod undocumented
36  
37 0 foreach my $event (@events) {
38 0 ▶ if( ! defined $event->{'type'} || $event->{'type'} ne $self->type ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $event->{"type"} or $event->{"type"} ne $self->type) 0 0 0
Condition0%0/3
not defined $event->{"type"} or $event->{"type"} ne $self->type
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $event->{"type"} or $event->{"type"} ne $self->type
not defined $event->{"type"} $event->{"type"} ne $self->type
Truth table0%0/3
not(A) or B
A= not defined $event->{"type"}B= $event->{"type"} ne $self->type
ABresult
1X1
011
000
39 0 next;
40 }
41 0 $self->send_event( $event );
42 }
43  
44 0 return;
45 }
46  
47 sub send_event {
48 0 ▶ my ( $self, $event ) = @_;
Subroutine send_event: not called CC=5 SCAR=34.0
Pod undocumented
49 0 ▶ if( ! defined $event->{'path'} || ! defined $event->{'value'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $event->{"path"} and defined $event->{"value"}) 0 0 0
Condition0%0/3
defined $event->{"path"} and defined $event->{"value"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $event->{"path"} and defined $event->{"value"}
defined $event->{"path"} defined $event->{"value"}
Truth table0%0/3
A and B
A= defined $event->{"path"}B= defined $event->{"value"}
ABresult
0X0
100
111
50 0 return;
51 }
52 0 my $ts = $event->{'timestamp'};
53 0 ▶ if( ! defined $ts ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ts) 0 0 0
54 0 $ts = Time::Piece->new->epoch;
55 }
56 0 my $host = $event->{'host'};
57  
58 my $path = join('.',
59 $self->prefix,
60 defined $host ? ( 'host', $host ) : ( 'global' ),
61 0 ▶ $event->{'path'}
Branch: 1 branch
BranchTrueFalseTotal
defined $host ? : 0 0 0
62 );
63  
64 0 $self->_handle->print( $path.' '.$event->{'value'}.' '.$ts."\n" );
65  
66 0 return;
67 }
68  
69 1 1;
70  
71 __END__
72  
73 =pod
74  
75 =encoding UTF-8
76  
77 =head1 NAME
78  
79 Log::Saftpresse::Output::Graphite - plugin to write events to carbon line reciever
80  
81 =head1 VERSION
82  
83 version 1.5
84  
85 =head1 AUTHOR
86  
87 Markus Benning <ich@markusbenning.de>
88  
89 =head1 COPYRIGHT AND LICENSE
90  
91 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
92  
93 This is free software, licensed under:
94  
95 The GNU General Public License, Version 2, June 1991
96  
97 =cut
« Saftpresse/Output/JSON.pm ↑ Summary Saftpresse/Plugin/Role/Tracking.pm »