| 1 | package Log::Saftpresse::CountersOutput::Dump; | ||||||||||||||||||
| 2 | |||||||||||||||||||
| 3 | 1 | ▶ | use Moose; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 4 | |||||||||||||||||||
| 5 | # ABSTRACT: plugin to dump counters to stdout | ||||||||||||||||||
| 6 | 1 | our $VERSION = '1.5'; # VERSION | |||||||||||||||||
| 7 | |||||||||||||||||||
| 8 | 1 | extends 'Log::Saftpresse::CountersOutput'; | |||||||||||||||||
| 9 | |||||||||||||||||||
| 10 | 1 | ▶ | use JSON; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 12 | 1 | ▶ | use Sys::Hostname; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 13 | |||||||||||||||||||
| 14 | 1 | has 'format' => ( is => 'rw', isa => 'Str', default => 'graphit' ); | |||||||||||||||||
| 15 | |||||||||||||||||||
| 16 | sub output { | ||||||||||||||||||
| 17 | 0 | ▶ | my ( $self, $counters ) = @_; | ||||||||||||||||
|
Subroutine
output: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||
| 18 | my %data = map { | ||||||||||||||||||
| 19 | 0 | $_ => $counters->{$_}->counters, | |||||||||||||||||
| 20 | } keys %$counters; | ||||||||||||||||||
| 21 | |||||||||||||||||||
| 22 | 0 | ▶ | if( lc $self->format eq 'graphit' ) { | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 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 | 0 | ▶ | return 'server.'.hostname; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 37 | }, | ||||||||||||||||||
| 38 | 1 | ); | |||||||||||||||||
| 39 | |||||||||||||||||||
| 40 | sub _proc_hash { | ||||||||||||||||||
| 41 | 0 | ▶ | my ( $path, $hash, $now ) = @_; | ||||||||||||||||
|
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 | _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 | ▶ | my ( $self, $data ) = @_; | ||||||||||||||||
|
Subroutine
_output_graphit: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 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 | ▶ | my ( $self, $data ) = @_; | ||||||||||||||||
|
Subroutine
_output_perl: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 72 | 0 | print Dumper( $data ); | |||||||||||||||||
| 73 | 0 | return; | |||||||||||||||||
| 74 | } | ||||||||||||||||||
| 75 | sub _output_json { | ||||||||||||||||||
| 76 | 0 | ▶ | my ( $self, $data ) = @_; | ||||||||||||||||
|
Subroutine
_output_json: not called CC=1 SCAR=6.9
| |||||||||||||||||||
| 77 | 0 | my $json = JSON->new; | |||||||||||||||||
| 78 | 0 | $json->pretty(1); | |||||||||||||||||
| 79 | 0 | print $json->encode( $data ); | |||||||||||||||||
| 80 | 0 | return; | |||||||||||||||||
| 81 | } | ||||||||||||||||||
| 82 | |||||||||||||||||||
| 83 | 1 | 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 | ||||||||||||||||||