| line | stmt | bran | cond | sub | pod | time | code | 
| 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 | 1 |  |  | 1 |  | 989 | use strict; | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 35 | 1 |  |  | 1 |  | 4 | use warnings qw(all); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 29 |  | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 1 |  |  | 1 |  | 3 | use Carp qw(confess); | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 384 |  | 
| 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 | 0 |  |  | 0 | 1 |  | my ($class,%opts) = @_; | 
| 51 |  |  |  |  |  |  |  | 
| 52 | 0 |  |  |  |  |  | my $self = \%opts; | 
| 53 | 0 |  |  |  |  |  | bless $self, $class; | 
| 54 | 0 |  | 0 |  |  |  | $self->{regex} ||= $self->regex; | 
| 55 | 0 |  |  |  |  |  | $self->{regex} = qr|$self->{regex}|ox; | 
| 56 | 0 |  |  |  |  |  | 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 |  |  | 0 | 1 |  | confess __PACKAGE__.'::regex is abstract method to override in subclass'; | 
| 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 |  |  |  | 0 | 1 |  | sub init_zone { | 
| 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 | 0 |  |  | 0 | 1 |  | my ($self,$line) = @_; | 
| 93 |  |  |  |  |  |  |  | 
| 94 | 0 |  |  |  |  |  | $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 |  |  | 0 | 1 |  | my ($self,$ref,$pub,$prv,$win) = @_; | 
| 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 |  |  |  | 0 | 1 |  | sub process_window { | 
| 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 |  |  | 0 | 1 |  | 1 | 
| 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 | 0 |  |  | 0 | 1 |  | my ($self,$zone,$pub,$prv,$wins) = @_; | 
| 144 |  |  |  |  |  |  |  | 
| 145 | 0 |  |  |  |  |  | map { $_.': '.$pub->{$_} } sort keys %$pub; | 
|  | 0 |  |  |  |  |  |  | 
| 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 | 0 |  |  | 0 | 1 |  | shift()->dump_zone(@_); | 
| 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 | 0 |  |  | 0 | 1 |  | 'debug' | 
| 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 |  |  |  |  |  |  | 1; | 
| 188 |  |  |  |  |  |  |  |