| 1 | package Tail::Stat::Plugin; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | Tail::Stat::Plugin - Abstract plugin class | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 SYNOPSIS | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | package Tail::Stat::Plugin::apache; | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | use strict; | ||||||||||||||||||||
| 12 | use warnings qw(all); | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | use base qw(Tail::Stat::Plugin); | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | sub regex { qr/^(\d+)\s+(\d+)/ } | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | sub process_data { | ||||||||||||||||||||
| 19 | my ($self,$lref,$pub,$win) = @_; | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | $pub->{param1} += $lref->[0]; | ||||||||||||||||||||
| 22 | $win->{param2} += $lref->[1]; | ||||||||||||||||||||
| 23 | $win->{count}++; | ||||||||||||||||||||
| 24 | } | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | sub process_window { | ||||||||||||||||||||
| 27 | my ($self,$pub,$prv,$wins) = @_; | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | $pub->{last_param2} = sum ( map { $_->{param2} || 0 } @$wins ) || 0; | ||||||||||||||||||||
| 30 | } | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 12 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 12 | ▶ | use warnings qw(all); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 12 | ▶ | use Carp qw(confess); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head1 METHODS | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | =head2 new | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Plugin instance constructor. | ||||||||||||||||||||
| 45 | Usually you don't need to override it's default behavior. | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | sub new { | ||||||||||||||||||||
| 50 | 11 | ▶ | my ($class,%opts) = @_; | ||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 11 | my $self = \%opts; | |||||||||||||||||||
| 53 | 11 | bless $self, $class; | |||||||||||||||||||
| 54 | 11 | ▶ | $self->{regex} ||= $self->regex; | ||||||||||||||||||
|
Condition33%1/3
$self->{"regex"} ||= $self->regex
MC/DC0%0/2
$self->{"regex"} ||= $self->regex
$self->{"regex"}
$self->regex
Truth table33%1/3
A ||= B
A= $self->{"regex"}B= $self->regex
| |||||||||||||||||||||
| 55 | 11 | $self->{regex} = qr|$self->{regex}|ox; | |||||||||||||||||||
| 56 | 11 | return $self; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head2 regex | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Accessor to main regular expression. | ||||||||||||||||||||
| 63 | Called once during initialization (from constructor). | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | sub regex { | ||||||||||||||||||||
| 68 | 0 | ▶ | confess __PACKAGE__.'::regex is abstract method to override in subclass'; | ||||||||||||||||||
|
Subroutine
regex: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 69 | } | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | =head2 init_zone($zone,\%public,\%private,\%window) | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Called once on zone creating. Usually you can assigns some default values | ||||||||||||||||||||
| 75 | in public statistics. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | ▶ | sub init_zone { | |||||||||||||||||||
|
Subroutine
init_zone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =head2 process_line($line) | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | Parse single log line and returns array of successfully captured values. | ||||||||||||||||||||
| 86 | Method must returns true value in scalar context, otherwise message will | ||||||||||||||||||||
| 87 | be logged about unprocessed line. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =cut | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | sub process_line { | ||||||||||||||||||||
| 92 | 11684 | ▶ | my ($self,$line) = @_; | ||||||||||||||||||
|
Subroutine
process_line: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | 11684 | $line =~ $self->{regex}; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | =head2 process_data(\@ref,\%public,\%private,\%window) | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | Receives reference to array of captured values and modify public, private | ||||||||||||||||||||
| 101 | or current window statistics. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub process_data { | ||||||||||||||||||||
| 106 | 0 | ▶ | my ($self,$ref,$pub,$prv,$win) = @_; | ||||||||||||||||||
|
Subroutine
process_data: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | $pub->{'arg_'.$_} += $ref->[$_] for 0 .. $#$ref; | |||||||||||||||||||
| 109 | 0 | return 1; | |||||||||||||||||||
| 110 | } | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head2 process_window(\%public,\%private,\@windows) | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | Called during closing current window. Common usage is calculate averages | ||||||||||||||||||||
| 116 | from complete windows and save results in public or private statistics. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =cut | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | ▶ | sub process_window { | |||||||||||||||||||
|
Subroutine
process_window: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 121 | } | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | =head2 process_timer($name,\%public,\%private,\@windows) | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | Processing named timer. Receives timer name and zone statistics. | ||||||||||||||||||||
| 127 | Timer will be renewed unless handler returns false value. | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =cut | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | sub process_timer { | ||||||||||||||||||||
| 132 | 0 | ▶ | 1 | ||||||||||||||||||
|
Subroutine
process_timer: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 133 | } | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | =head2 dump_zone($zone,\%public,\%private,\@windows) | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | Stringify accumulated statistics. | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | =cut | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | sub dump_zone { | ||||||||||||||||||||
| 143 | 1 | ▶ | my ($self,$zone,$pub,$prv,$wins) = @_; | ||||||||||||||||||
|
Subroutine
dump_zone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | 1 | map { $_.': '.$pub->{$_} } sort keys %$pub; | |||||||||||||||||||
| 146 | } | ||||||||||||||||||||
| 147 | |||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =head2 stats_zone($zone,\%public,\%private,\@windows) | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | Optionally preprocess, and stringify accumulated statistics. | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||
| 154 | |||||||||||||||||||||
| 155 | sub stats_zone { | ||||||||||||||||||||
| 156 | 1 | ▶ | shift()->dump_zone(@_); | ||||||||||||||||||
|
Subroutine
stats_zone: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =head2 parse_error | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | Returns default logging level for unparsed lines. | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | =cut | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | sub parse_error { | ||||||||||||||||||||
| 167 | 6 | ▶ | 'debug' | ||||||||||||||||||
|
Subroutine
parse_error: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | |||||||||||||||||||||
| 171 | =head1 AUTHOR | ||||||||||||||||||||
| 172 | |||||||||||||||||||||
| 173 | Oleg A. Mamontov, C<< <oleg@mamontov.net> >> | ||||||||||||||||||||
| 174 | |||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | =head1 COPYRIGHT | ||||||||||||||||||||
| 177 | |||||||||||||||||||||
| 178 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||
| 179 | under the terms of either: the GNU General Public License as published | ||||||||||||||||||||
| 180 | by the Free Software Foundation; or the Artistic License. | ||||||||||||||||||||
| 181 | |||||||||||||||||||||
| 182 | See http://dev.perl.org/licenses/ for more information. | ||||||||||||||||||||
| 183 | |||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||
| 185 | |||||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 12 | 1; | |||||||||||||||||||
| 188 | |||||||||||||||||||||