line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::Output::Graphite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1036
|
use Moose; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to write events to carbon line reciever |
6
|
|
|
|
|
|
|
our $VERSION = '1.5'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::Output'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
3938
|
use Time::Piece; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
11
|
1
|
|
|
1
|
|
81
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'prefix' => ( is => 'rw', isa => 'Str', |
14
|
|
|
|
|
|
|
default => 'saftpresse-metric', |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
my $handle = IO::Socket::INET->new( |
26
|
|
|
|
|
|
|
PeerAddr => $self->{'host'} || '127.0.0.1', |
27
|
|
|
|
|
|
|
PeerPort => $self->{'port'} || '2003', |
28
|
|
|
|
|
|
|
Proto => 'tcp', |
29
|
|
|
|
|
|
|
) or die('error opening connection to graphite line reciever: '.$@); |
30
|
|
|
|
|
|
|
return $handle; |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub output { |
35
|
0
|
|
|
0
|
0
|
|
my ( $self, @events ) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
foreach my $event (@events) { |
38
|
0
|
0
|
0
|
|
|
|
if( ! defined $event->{'type'} || $event->{'type'} ne $self->type ) { |
39
|
0
|
|
|
|
|
|
next; |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
$self->send_event( $event ); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub send_event { |
48
|
0
|
|
|
0
|
0
|
|
my ( $self, $event ) = @_; |
49
|
0
|
0
|
0
|
|
|
|
if( ! defined $event->{'path'} || ! defined $event->{'value'} ) { |
50
|
0
|
|
|
|
|
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
|
|
|
|
|
my $ts = $event->{'timestamp'}; |
53
|
0
|
0
|
|
|
|
|
if( ! defined $ts ) { |
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
|
0
|
|
|
|
|
$event->{'path'} |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$self->_handle->print( $path.' '.$event->{'value'}.' '.$ts."\n" ); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
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 |