Saftpresse.pm

filter: Statementstmt 40.5% 30 / 74 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 41.1% 7 / 17 Podpod 100% 2 / 2 totaltotal 36.1% 39 / 108 SCAR 32.6
CC
8
Cov
34%
run
30.0
_need_flush_counters
20.0
__ANON__
2.0
CRAP 26.0
« Saftpresse/Input/Server.pm ↑ Summary Saftpresse/Input/RELP.pm »
1 package Log::Saftpresse;
2  
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: a modular logfile analyzer
6 1 our $VERSION = '1.5'; # VERSION
7  
8 1 ▶use Log::Saftpresse::Log4perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Log::Saftpresse::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶use Log::Saftpresse::Analyzer;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Log::Saftpresse::Slurp;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Log::Saftpresse::CounterOutputs;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Log::Saftpresse::Outputs;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 has 'config' => (
18 is => 'ro', isa => 'Log::Saftpresse::Config', lazy => 1,
19 0 ▶ default => sub { Log::Saftpresse::Config->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
20 1 handles => [ 'load_config' ],
21 );
22  
23 has 'slurp' => (
24 is => 'ro', isa => 'Log::Saftpresse::Slurp', lazy => 1,
25 0 ▶ default => sub { Log::Saftpresse::Slurp->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 1 );
27  
28 has 'analyzer' => (
29 is => 'ro', isa => 'Log::Saftpresse::Analyzer', lazy => 1,
30 0 ▶ default => sub { Log::Saftpresse::Analyzer->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
31 1 );
32  
33 has 'counter_outputs' => (
34 is => 'ro', isa => 'Log::Saftpresse::CounterOutputs', lazy => 1,
35 0 ▶ default => sub { Log::Saftpresse::CounterOutputs->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 1 );
37  
38 has 'outputs' => (
39 is => 'ro', isa => 'Log::Saftpresse::Outputs', lazy => 1,
40 0 ▶ default => sub { Log::Saftpresse::Outputs->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
41 1 );
42  
43 1 has 'flush_interval' => ( is => 'rw', isa => 'Maybe[Int]' );
44  
45 has '_last_flush_counters' => (
46 is => 'rw', isa => 'Int',
47 0 ▶ default => sub { time },
Subroutine __ANON__: not called CC=1 SCAR=6.9
48 1 );
49  
50  
51 sub init {
52 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod documented
53 0 my $config = $self->config;
54
55 0 Log::Saftpresse::Log4perl->init(
56 $config->get('logging', 'level'),
57 $config->get('logging', 'file'),
58 );
59 0 $self->flush_interval( $config->get('counters', 'flush_interval') );
60 0 $self->slurp->load_config( $config->get_node('Input') );
61 0 $self->analyzer->load_config( $config->get_node('Plugin') );
62 0 $self->counter_outputs->load_config( $config->get_node('CounterOutput') );
63 0 $self->outputs->load_config( $config->get_node('Output') );
64  
65 0 return;
66 }
67  
68 sub _need_flush_counters {
69 0 ▶ my $self = shift;
Subroutine _need_flush_counters: not called CC=4 SCAR=30.0
70  
71 0 ▶ if( ! defined $self->flush_interval
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->flush_interval or $self->flush_interval < 1) 0 0 0
Condition0%0/3
not defined $self->flush_interval or $self->flush_interval < 1
l!l&&r!l&&!r
000
MC/DC0%0/2
not defined $self->flush_interval or $self->flush_interval < 1
not defined $self->flush_interval $self->flush_interval < 1
Truth table0%0/3
not(A) or B
A= not defined $self->flush_intervalB= $self->flush_interval < 1
ABresult
1X1
011
000
72 || $self->flush_interval < 1 ) {
73 0 return 0;
74 }
75  
76 0 my $next_flush = $self->_last_flush_counters + $self->flush_interval;
77 0 ▶ if( time < $next_flush ) {
Branch: 1 branch
BranchTrueFalseTotal
if (time < $next_flush) 0 0 0
78 0 return 0;
79 }
80  
81 0 return 1;
82 }
83  
84 sub _flushed_counters {
85 0 ▶ my $self = shift;
Subroutine _flushed_counters: not called CC=1 SCAR=6.9
86 0 $self->_last_flush_counters( time );
87 0 return;
88 }
89  
90  
91 sub run {
92 0 ▶ my $self = shift;
Subroutine run: not called CC=5 SCAR=34.0
Pod documented
93 0 my $slurp = $self->slurp;
94 0 my $last_flush = time;
95  
96 0 $log->info('entering main loop');
97 0 for(;;) { # main loop
98 0 my $events;
99 0 ▶ if( $slurp->can_read(1) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($slurp->can_read(1)) 0 0 0
100 0 $log->debug('checking for new input...');
101 0 $events = $slurp->read_events;
102 0 foreach my $event ( @$events ) {
103 0 $self->analyzer->process_event( $event );
104 }
105 }
106 0 ▶ if( scalar @$events ) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @$events) 0 0 0
107 0 $log->debug('sending '.scalar(@$events).' events to outputs...');
108 0 $self->outputs->output( @$events );
109 }
110  
111 0 ▶ if( $self->_need_flush_counters ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_need_flush_counters) 0 0 0
112 0 $log->debug('flushing counters...');
113 0 $self->counter_outputs->output(
114 $self->analyzer->get_all_counters );
115 0 $self->_flushed_counters;
116 }
117 }
118  
119 0 return;
120 }
121  
122  
123 1 1;
124  
125 __END__
126  
127 =pod
128  
129 =encoding UTF-8
130  
131 =head1 NAME
132  
133 Log::Saftpresse - a modular logfile analyzer
134  
135 =head1 VERSION
136  
137 version 1.5
138  
139 =head1 Description
140  
141 This is the central class of the saftpresse log analyzer.
142  
143 =head1 Synopsis
144  
145 use Log::Saftpresse;
146  
147 my $saft = Log:::Saftpresse->new;
148  
149 $saft->load_config( $path );
150 $saft->init;
151  
152 # start main loop
153 $saft->run;
154  
155 =head1 Attributes
156  
157 =head2 config( L<Log::Saftpresse::Config>)
158  
159 Holds the configuration.
160  
161 =head2 slurp( L<Log::Saftpresse::Slurp> )
162  
163 Holds the slurp class implementing the input.
164  
165 =head2 analyzer( L<Log::Saftpresse::Analyzer> )
166  
167 Holds the analyzer object which controls the processing plugins.
168  
169 =head2 counter_outputs( L<Log::Saftpresse::CounterOutputs> )
170  
171 Holds the counter output object which controls output of metrics.
172  
173 =head2 outputs( L<Log::Saftpresse::Outputs> )
174  
175 Holds the Outputs plugin which controls the event output.
176  
177 =head2 flush_interval( $seconds )
178  
179 How often to flush metrics to CounterOutputs.
180  
181 =head1 Methods
182  
183 =head2 init
184  
185 Initialize saftpresse as configured in config file.
186  
187 Will load slurp, analyzer, counter_outputs, outputs and flush_interval
188 from configuration.
189  
190 =head2 run
191  
192 Run the main loop of saftpresse.
193  
194 =head1 See also
195  
196 =over
197  
198 =item L<Log::Saftpresse::App>
199  
200 Commandline glue for this class.
201  
202 =item bin/saftpresse
203  
204 Commandline interface of saftpresse with end-user docs.
205  
206 =back
207  
208 =head1 AUTHOR
209  
210 Markus Benning <ich@markusbenning.de>
211  
212 =head1 COPYRIGHT AND LICENSE
213  
214 This software is Copyright (c) 1998 by James S. Seymour, 2015 by Markus Benning.
215  
216 This is free software, licensed under:
217  
218 The GNU General Public License, Version 2, June 1991
219  
220 =cut
« Saftpresse/Input/Server.pm ↑ Summary Saftpresse/Input/RELP.pm »