line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Log::Saftpresse::CountersOutput::Dump; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1005
|
use Moose; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# ABSTRACT: plugin to dump counters to stdout |
6
|
|
|
|
|
|
|
our $VERSION = '1.5'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
extends 'Log::Saftpresse::CountersOutput'; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
4128
|
use JSON; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
7
|
|
11
|
1
|
|
|
1
|
|
682
|
use Data::Dumper; |
|
1
|
|
|
|
|
4116
|
|
|
1
|
|
|
|
|
47
|
|
12
|
1
|
|
|
1
|
|
5
|
use Sys::Hostname; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
382
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has 'format' => ( is => 'rw', isa => 'Str', default => 'graphit' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub output { |
17
|
0
|
|
|
0
|
0
|
|
my ( $self, $counters ) = @_; |
18
|
|
|
|
|
|
|
my %data = map { |
19
|
0
|
|
|
|
|
|
$_ => $counters->{$_}->counters, |
|
0
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
} keys %$counters; |
21
|
|
|
|
|
|
|
|
22
|
0
|
0
|
|
|
|
|
if( lc $self->format eq 'graphit' ) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
$self->_output_graphit( \%data ); |
24
|
|
|
|
|
|
|
} elsif ( lc $self->format eq 'json' ) { |
25
|
0
|
|
|
|
|
|
$self->_output_json( \%data ); |
26
|
|
|
|
|
|
|
} elsif ( lc $self->format eq 'perl' ) { |
27
|
0
|
|
|
|
|
|
$self->_output_perl( \%data ); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'graphit_prefix' => ( |
34
|
|
|
|
|
|
|
is => 'rw', isa => 'Str', lazy => 1, |
35
|
|
|
|
|
|
|
default => sub { |
36
|
|
|
|
|
|
|
return 'server.'.hostname; |
37
|
|
|
|
|
|
|
}, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _proc_hash { |
41
|
0
|
|
|
0
|
|
|
my ( $path, $hash, $now ) = @_; |
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
|
|
|
|
|
|
_proc_hash($this_path, $value, $now); |
52
|
|
|
|
|
|
|
} elsif( $type eq '' ) { |
53
|
0
|
|
|
|
|
|
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
|
|
|
|
|
|
_proc_hash($self->graphit_prefix, $data, $now); |
66
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub _output_perl { |
71
|
0
|
|
|
0
|
|
|
my ( $self, $data ) = @_; |
72
|
0
|
|
|
|
|
|
print Dumper( $data ); |
73
|
0
|
|
|
|
|
|
return; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
sub _output_json { |
76
|
0
|
|
|
0
|
|
|
my ( $self, $data ) = @_; |
77
|
0
|
|
|
|
|
|
my $json = JSON->new; |
78
|
0
|
|
|
|
|
|
$json->pretty(1); |
79
|
0
|
|
|
|
|
|
print $json->encode( $data ); |
80
|
0
|
|
|
|
|
|
return; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
__END__ |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=encoding UTF-8 |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 NAME |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Log::Saftpresse::CountersOutput::Dump - plugin to dump counters to stdout |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 VERSION |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
version 1.5 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Markus Benning <ich@markusbenning.de> |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This is free software, licensed under: |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
The GNU General Public License, Version 2, June 1991 |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=cut |