line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::CountersOutput::Graphite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
4028
|
use Moose; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
10
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to write counters to carbon line reciever |
6
|
|
|
|
|
|
|
our $VERSION = '1.6'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::CountersOutput'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
5764
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub output { |
13
|
0
|
|
|
0
|
0
|
|
my ( $self, $counters ) = @_; |
14
|
|
|
|
|
|
|
my %data = map { |
15
|
0
|
|
|
|
|
|
$_ => $counters->{$_}->counters, |
|
0
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
} keys %$counters; |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$self->_output_graphit( \%data ); |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
return; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
31
|
|
|
|
|
|
|
my $handle = IO::Socket::INET->new( |
32
|
|
|
|
|
|
|
PeerAddr => $self->{'host'} || '127.0.0.1', |
33
|
|
|
|
|
|
|
PeerPort => $self->{'port'} || '2003', |
34
|
|
|
|
|
|
|
Proto => 'tcp', |
35
|
|
|
|
|
|
|
) or die('error opening connection to graphite line reciever: '.$@); |
36
|
|
|
|
|
|
|
return $handle; |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _proc_hash { |
41
|
0
|
|
|
0
|
|
|
my ( $self, $path, $now, $hash ) = @_; |
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
|
0
|
|
|
|
|
if( ! defined $value ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
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
|
|
|
0
|
|
|
my ( $self, $data ) = @_; |
63
|
0
|
|
|
|
|
|
my $now = time; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
$self->_proc_hash($self->prefix, $now , $data); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
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.6 |
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 |