| 1 | package Log::Saftpresse::CountersOutput::Graphite; | ||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | # ABSTRACT: plugin to write counters to carbon line reciever | ||||||||||||||||||||||||||||||
| 6 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | 1 | extends 'Log::Saftpresse::CountersOutput'; | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use IO::Socket::INET; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | sub output { | ||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | my ( $self, $counters ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
output: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 14 | my %data = map { | ||||||||||||||||||||||||||||||
| 15 | 0 | $_ => $counters->{$_}->counters, | |||||||||||||||||||||||||||||
| 16 | } keys %$counters; | ||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 0 | $self->_output_graphit( \%data ); | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||
| 20 | 0 | return; | |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||
| 23 | 1 | has 'prefix' => ( is => 'rw', isa => 'Str', lazy => 1, | |||||||||||||||||||||||||||||
| 24 | default => 'saftpresse', | ||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||
| 27 | has '_handle' => ( | ||||||||||||||||||||||||||||||
| 28 | is => 'rw', isa => 'IO::Socket::INET', lazy => 1, | ||||||||||||||||||||||||||||||
| 29 | default => sub { | ||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 31 | my $handle = IO::Socket::INET->new( | ||||||||||||||||||||||||||||||
| 32 | PeerAddr => $self->{'host'} || '127.0.0.1', | ||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | PeerPort => $self->{'port'} || '2003', | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/4
$self->{'host'} || '127.0.0.1'
$self->{'port'} || '2003'
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'}
Truth table0%0/2
A
A= $self->{'port'}
| |||||||||||||||||||||||||||||||
| 34 | Proto => 'tcp', | ||||||||||||||||||||||||||||||
| 35 | ) or die('error opening connection to graphite line reciever: '.$@); | ||||||||||||||||||||||||||||||
| 36 | 0 | return $handle; | |||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | sub _proc_hash { | ||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | my ( $self, $path, $now, $hash ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_proc_hash: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 42 | 0 | foreach my $key ( keys %$hash ) { | |||||||||||||||||||||||||||||
| 43 | 0 | my $value = $hash->{$key}; | |||||||||||||||||||||||||||||
| 44 | 0 | my $type = ref $value; | |||||||||||||||||||||||||||||
| 45 | 0 | my $graphit_key = $key; | |||||||||||||||||||||||||||||
| 46 | 0 | $graphit_key =~ s/\./_/g; | |||||||||||||||||||||||||||||
| 47 | 0 | my $this_path = $path.'.'.$graphit_key; | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if( ! defined $value ) { | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 49 | # noop | ||||||||||||||||||||||||||||||
| 50 | } elsif( $type eq 'HASH' ) { | ||||||||||||||||||||||||||||||
| 51 | 0 | $self->_proc_hash($this_path, $now, $value); | |||||||||||||||||||||||||||||
| 52 | } elsif( $type eq '' ) { | ||||||||||||||||||||||||||||||
| 53 | 0 | $self->_handle->print($this_path.' '.$value.' '.$now."\n"); | |||||||||||||||||||||||||||||
| 54 | } else { | ||||||||||||||||||||||||||||||
| 55 | 0 | die('unhandled data structure!'); | |||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | 0 | return; | |||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | sub _output_graphit { | ||||||||||||||||||||||||||||||
| 62 | 0 | ▶ | my ( $self, $data ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_output_graphit: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 63 | 0 | my $now = time; | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | 0 | $self->_proc_hash($self->prefix, $now , $data); | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 0 | return; | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | =pod | ||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||
| 76 | =encoding UTF-8 | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | =head1 NAME | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | Log::Saftpresse::CountersOutput::Graphite - plugin to write counters to carbon line reciever | ||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | =head1 VERSION | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | version 1.5 | ||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||
| 86 | =head1 AUTHOR | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | Markus Benning <ich@markusbenning.de> | ||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | This is free software, licensed under: | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | The GNU General Public License, Version 2, June 1991 | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | =cut | ||||||||||||||||||||||||||||||