File Coverage

blib/lib/WWW/Opentracker/Stats/Mode/Fullscrape.pm
Criterion Covered Total %
statement 13 13 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 19 20 95.0


line stmt bran cond sub pod time code
1             package WWW::Opentracker::Stats::Mode::Fullscrape;
2              
3 1     1   34987 use strict;
  1         4  
  1         39  
4 1     1   5 use warnings;
  1         1  
  1         113  
5              
6 1         7 use parent qw/
7             WWW::Opentracker::Stats::Mode
8             Class::Accessor::Fast
9 1     1   1074 /;
  1         400  
10              
11              
12             __PACKAGE__->_format('txt');
13             __PACKAGE__->_mode('fscr');
14              
15             __PACKAGE__->mk_accessors(qw/_stats/);
16              
17              
18             =head1 NAME
19              
20             WWW::Opentracker::Stats::Mode::Fullscrape
21              
22             =head1 DESCRIPTION
23              
24             Parses the fullscrape statistics from opentracker.
25              
26             =head1 METHODS
27              
28             =head2 parse_stats
29              
30             Args: $self, $payload
31              
32             Decodes the plain text data retrieved from the fullscrape statistics of opentracker.
33              
34             The payload looks like this (no indentation):
35             21000
36             1701
37             36369 seconds (10 hours)
38             opentracker full scrape stats, 0 conns/s :: 0 bytes/s.
39              
40             =cut
41              
42             sub parse_stats {
43 1     1 1 2 my ($self, $payload) = @_;
44              
45 1 50       16 my ($count, $size, $seconds, $count_per_sec, $size_per_sec)
46             = $payload =~ m{\A
47             (\d+) \s
48             (\d+) \s
49             (\d+) \s seconds \s \( \d+ \s hours \) \s
50             opentracker \s full \s scrape \s stats , \s
51             (\d+) \s conns/s \s :: \s (\d+) \s bytes/s \.
52             }xms
53             or die "Unable to parse payload: $payload";
54              
55 1         10 my %stats = (
56             'count' => $count,
57             'size' => $size,
58             'uptime' => $seconds,
59             'count_per_sec' => $count_per_sec,
60             'size_per_sec' => $size_per_sec,
61             );
62              
63 1         20 return \%stats;
64             }
65              
66              
67             =head1 SEE ALSO
68              
69             L
70              
71             =head1 AUTHOR
72              
73             Knut-Olav Hoven, Eknutolav@gmail.comE
74              
75             =head1 COPYRIGHT AND LICENSE
76              
77             Copyright (C) 2009 by Knut-Olav Hoven
78              
79             This library is free software; you can redistribute it and/or modify
80             it under the same terms as Perl itself, either Perl version 5.8.8 or,
81             at your option, any later version of Perl 5 you may have available.
82              
83              
84             =cut
85              
86             1;
87