blib/lib/Tail/Stat/Plugin/cvsupd.pm

filter: Statementstmt 100% 40 / 40 Branchbran 87.5% 7 / 8 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 4 / 4 totaltotal 95.2% 60 / 63 CC 7 SCAR 10.0
CC
7
Cov
96%
process_window
4.0
process_data
4.0
BEGIN
1.0
CRAP 2.7
« blib/lib/Tail/Stat/Plugin/clamd.pm ↑ Summary blib/lib/Tail/Stat/Plugin/icecast.pm »
1 package Tail::Stat::Plugin::cvsupd;
2  
3 =head1 NAME
4  
5 Tail::Stat::Plugin::cvsupd - Statistics collector for CVSupd server
6  
7 =cut
8  
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings qw(all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 =head1 SYNOPSIS
14  
15 tstatd cvsupd cvsupd.log
16  
17  
18 =head1 LOG FORMATS
19  
20 Plugin search cvsupd logs for records of three types:
21  
22 =over
23  
24 =item C<connect>
25  
26 +1088 root@host.domain.com [CSUP_1_0/17.0]
27  
28 =item C<update>
29  
30 =1088 [2597Kin+1797Kout] ports-all/cvs
31  
32 =item C<disconnect>
33  
34 -1088 [2597Kin+1797Kout] Finished successfully
35  
36 =back
37  
38  
39 =head1 STATISTICS
40  
41 =head2 Overall statistics
42  
43 =over
44  
45 =item C<clients>
46  
47 Total number of received clients connections.
48  
49 =item C<client:I<version>>
50  
51 Total number of connections received with client I<version>.
52  
53 =item C<collections>
54  
55 Total number of requsted collections.
56  
57 =item C<collection:I<collection>>
58  
59 Total number of updates of I<collection>.
60  
61 =item C<bytes_in>
62  
63 Total traffic received.
64  
65 =item C<bytes_out>
66  
67 Total traffic sent.
68  
69 =item C<status:I<status>>
70  
71 Total number of disconnects with I<status>.
72  
73 =back
74  
75 =cut
76  
77  
78 2 ▶use base qw(Tail::Stat::Plugin);
Subroutine BEGIN: called CC=1 SCAR=0.0
79 2 ▶use List::Util qw(sum);
Subroutine BEGIN: called CC=1 SCAR=0.0
80  
81 1 ▶sub regex { qr{
Subroutine regex: called CC=1 SCAR=0.0
Pod documented
82  
83 (?:
84 (\+) # operation [0]
85 (\d+) # connection [1]
86 \s+
87 (\S+) # user [2]
88 \@
89 (\S+) # host [3]
90 \s+
91 \[([^\]]+)\] # version [4]
92 |
93 (=) # operation [5]
94 (\d+) # connection [6]
95 \s+
96 \[(\d+)Kin\+(\d+)Kout\] # traffic [7],[8]
97 \s+
98 (\S+) # collection [9]
99 |
100 (-) # operation [10]
101 (\d+) # connection [11]
102 \s+
103 \[(\d+)Kin\+(\d+)Kout\] # traffic [12],[13]
104 \s+
105 (.+) # status [14]
106 )
107 $
108  
109 }x }
110  
111  
112 sub process_data {
113 664 ▶ my $self = shift;
Subroutine process_data: called CC=4 SCAR=13.9
Pod documented
114 664 my ($ref,$pub,$prv,$win) = @_;
115  
116 664 ▶ if ( $ref->[0] ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($ref->[0]) { } 218 446 664
elsif ($ref->[5]) { } 223 223 446
elsif ($ref->[10]) { } 223 0 223
117 # connect
118 218 $pub->{ clients }++;
119 218 $win->{ clients }++;
120 218 $pub->{ 'client:' . $ref->[4] }++;
121 } elsif ( $ref->[5] ) {
122 # collection
123 223 $pub->{ collections }++;
124 223 $win->{ collections }++;
125 223 $ref->[9] =~ s{:}{_}g;
126 223 $pub->{ 'collection:' . $ref->[9] }++;
127 } elsif ( $ref->[10] ) {
128 # disconnect
129 223 $pub->{ bytes_in } += 1024 * $ref->[12];
130 223 $pub->{ bytes_out } += 1024 * $ref->[13];
131 223 $win->{ bytes_in } += 1024 * $ref->[12];
132 223 $win->{ bytes_out } += 1024 * $ref->[13];
133 223 $ref->[14] =~ s{:}{_}g;
134 223 $pub->{ 'status:' . $ref->[14] }++;
135 }
136 }
137  
138  
139 sub process_window {
140 3 ▶ my $self = shift;
Subroutine process_window: called CC=4 SCAR=13.9
Pod documented
141 3 my ($pub,$prv,$wins) = @_;
142  
143 3 for my $m ( qw( clients collections bytes_in bytes_out ) ) {
144 12 ▶ $pub->{'last_' . $m } = sum ( map { $_->{ $m } || 0 } @$wins ) || 0;
Branch: 1 branch
BranchTrueFalseTotal
$_->{$m} or 0 12 12 24
Condition50%1/2
&sum(map({$_->{$m} or 0;} @$wins)) || 0
l!l
120
MC/DC0%0/1
&sum(map({$_->{$m} or 0;} @$wins)) || 0
&sum(map({$_->{$m} or 0;} @$wins))
Truth table50%1/2
A
A= &sum(map({$_->{$m} or 0;} @$wins))
Aresult
11
00
145 }
146 }
147  
148  
149 sub stats_zone {
150 1 ▶ my ($self,$zone,$pub,$prv,$wins) = @_;
Subroutine stats_zone: called CC=1 SCAR=0.0
Pod documented
151  
152 # required keys defaults
153 1 my %out = ( ( map { $_ => 0 } qw(
154 clients
155 collections
156 bytes_in
157 bytes_out
158  
159 last_clients
160 last_collections
161 last_bytes_in
162 last_bytes_out
163 ) ), %$pub );
164  
165 1 map { $_ . ': ' . $out{ $_ } } sort keys %out;
166 }
167  
168  
169 =head1 AUTHOR
170  
171 Oleg A. Mamontov, C<< <oleg@mamontov.net> >>
172  
173  
174 =head1 COPYRIGHT
175  
176 This program is free software; you can redistribute it and/or modify it
177 under the terms of either: the GNU General Public License as published
178 by the Free Software Foundation; or the Artistic License.
179  
180 See http://dev.perl.org/licenses/ for more information.
181  
182 =cut
183  
184 2 1;
185  
« blib/lib/Tail/Stat/Plugin/clamd.pm ↑ Summary blib/lib/Tail/Stat/Plugin/icecast.pm »