File Coverage

blib/lib/Regexp/Log/RealServer.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Regexp::Log::RealServer;
2              
3 1     1   26066 use strict;
  1         2  
  1         43  
4 1     1   5 use base qw( Regexp::Log );
  1         1  
  1         812  
5 1     1   1632 use vars qw( $VERSION %DEFAULT %FORMAT %REGEXP );
  1         6  
  1         407  
6              
7             $VERSION = 0.02;
8              
9             =head1 NAME
10              
11             Regexp::Log::RealServer - A regular expression parser for RealServer
12             log format.
13              
14             =head1 SYNOPSIS
15              
16             my $foo = Regexp::Log::Common->new(
17             format => 'custom %date %cs_uri_stem',
18             capture => [qw( date request )],
19             );
20              
21             # the format() and capture() methods can be used to set or get
22             $foo->format('custom %date %cs_uri_stem %c_rate %c_status');
23             $foo->capture(qw( date cs_uri_stem ));
24              
25             # this is necessary to know in which order
26             # we will receive the captured fields from the regexp
27             my @fields = $foo->capture;
28              
29             # the all-powerful capturing regexp :-)
30             my $re = $foo->regexp;
31              
32             while (<>) {
33             my %data;
34             @data{@fields} = /$re/; # no need for /o, it's a compiled regexp
35              
36             # now munge the fields
37             ...
38             }
39              
40             =head1 DESCRIPTION
41              
42             Regexp::Log::RealServer uses Regexp::Log as a base class, to generate regular
43             expressions for performing the usual data munging tasks on log files that
44             cannot be simply split().
45              
46             This specific module enables the computation of regular expressions for
47             parsing the log files created by RealServer.
48              
49             For more information on how to use this module, please see Regexp::Log.
50              
51             =head1 ABSTRACT
52              
53             Regexp::Log::RealServer enables simple parsing of log files created by RealServer.
54              
55             =cut
56              
57             # default values
58             %DEFAULT = ( format => (q(%c_ip %date %c_dns %cs_uri_stem %c_starttime %x_duration %c_rate ).
59             q(%c_status %c_playerid %c_playerversion %c_playerlanguage ).
60             q(%cs_user_agent %cs_referer %c_hostexe %c_hostexever %c_os %c_osversion ).
61             q(%c_cpu %filelength %filesize %avgbandwidth %protocol %transport ).
62             q(%audiocodec %videocodec %channelURL %sc_bytes %c_bytes %s_pkts_sent ).
63             q(%c_pkts_received %c_pkts_lost_client %c_pkts_lost_net ).
64             q(%c_pkts_lost_cont_net %c_resendreqs %c_pkts_recovered_ECC ).
65             q(%c_pkts_recovered_resent %c_buffercount %c_totalbuffertime %c_quality ).
66             q(%s_ip %s_dns %s_totalclients %s_cpu_util)),
67              
68             capture => [qw(c_ip date c_dns cs_uri_stem c_starttime x_duration c_rate
69             c_status c_playerid c_playerversion c_playerlanguage cs_user_agent
70             cs_referer c_hostexe c_hostexever c_os c_osversion c_cpu filelength
71             filesize avgbandwidth protocol transport audiocodec videocodec
72             channelURL sc_bytes c_bytes s_pkts_sent c_pkts_received
73             c_pkts_lost_client c_pkts_lost_net c_pkts_lost_cont_net c_resendreqs
74             c_pkts_recovered_ECC c_pkts_recovered_resent c_buffercount
75             c_totalbuffertime c_quality s_ip s_dns s_totalclients s_cpu_util)]);
76              
77             # predefined format strings
78             %FORMAT = (
79             ':default' => $DEFAULT{format},
80             ':common' => $DEFAULT{format},
81             );
82              
83             # the regexps that match the various fields
84             %REGEXP = ( '%c_ip' => '(?#=c_ip)\S+(?#!c_ip)',
85             '%date' => '(?#=date)\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}(?#!date)',
86             '%c_dns' => '(?#=c_dns).*?(?#!c_dns)',
87             '%cs_uri_stem' => '(?#=cs_uri_stem).*?(?#!cs_uri_stem)',
88             '%c_starttime' => '(?#=c_starttime).*?(?#!c_starttime)',
89             '%x_duration' => '(?#=x_duration).*?(?#!x_duration)',
90             '%c_rate' => '(?#=c_rate).*?(?#!c_rate)',
91             '%c_status' => '(?#=c_status).*?(?#!c_status)',
92             '%c_playerid' => '(?#=c_playerid).*?(?#!c_playerid)',
93             '%c_playerversion' => '(?#=c_playerversion).*?(?#!c_playerversion)',
94             '%c_playerlanguage' => '(?#=c_playerlanguage).*?(?#!c_playerlanguage)',
95             '%cs_user_agent' => '(?#=cs_user_agent).*?(?#!cs_user_agent)',
96             '%cs_referer' => '(?#=cs_referer).*?(?#!cs_referer)',
97             '%c_hostexe' => '(?#=c_hostexe).*?(?#!c_hostexe)',
98             '%c_hostexever' => '(?#=c_hostexever).*?(?#!c_hostexever)',
99             '%c_os' => '(?#=c_os).*?(?#!c_os)',
100             '%c_osversion' => '(?#=c_osversion).*?(?#!c_osversion)',
101             '%c_cpu' => '(?#=c_cpu).*?(?#!c_cpu)',
102             '%filelength' => '(?#=filelength).*?(?#!filelength)',
103             '%filesize' => '(?#=filesize).*?(?#!filesize)',
104             '%avgbandwidth' => '(?#=avgbandwidth).*?(?#!avgbandwidth)',
105             '%protocol' => '(?#=protocol).*?(?#!protocol)',
106             '%transport' => '(?#=transport).*?(?#!transport)',
107             '%audiocodec' => '(?#=audiocodec).*?(?#!audiocodec)',
108             '%videocodec' => '(?#=videocodec).*?(?#!videocodec)',
109             '%channelURL' => '(?#=channelURL).*?(?#!channelURL)',
110             '%sc_bytes' => '(?#=sc_bytes).*?(?#!sc_bytes)',
111             '%c_bytes' => '(?#=c_bytes).*?(?#!c_bytes)',
112             '%s_pkts_sent' => '(?#=s_pkts_sent).*?(?#!s_pkts_sent)',
113             '%c_pkts_received' => '(?#=c_pkts_received).*?(?#!c_pkts_received)',
114             '%c_pkts_lost_client' => '(?#=c_pkts_lost_client).*?(?#!c_pkts_lost_client)',
115             '%c_pkts_lost_net' => '(?#=c_pkts_lost_net).*?(?#!c_pkts_lost_net)',
116             '%c_pkts_lost_cont_net' => '(?#=c_pkts_lost_cont_net).*?(?#!c_pkts_lost_cont_net)',
117             '%c_resendreqs' => '(?#=c_resendreqs).*?(?#!c_resendreqs)',
118             '%c_pkts_recovered_ECC' => '(?#=c_pkts_recovered_ECC).*?(?#!c_pkts_recovered_ECC)',
119             '%c_pkts_recovered_resent' => '(?#=c_pkts_recovered_resent).*?(?#!c_pkts_recovered_resent)',
120             '%c_buffercount' => '(?#=c_buffercount).*?(?#!c_buffercount)',
121             '%c_totalbuffertime' => '(?#=c_totalbuffertime).*?(?#!c_totalbuffertime)',
122             '%c_quality' => '(?#=c_quality).*?(?#!c_quality)',
123             '%s_ip' => '(?#=s_ip).*?(?#!s_ip)',
124             '%s_dns' => '(?#=s_dns).*?(?#!s_dns)',
125             '%s_totalclients' => '(?#=s_totalclients).*?(?#!s_totalclients)',
126             '%s_cpu_util' => '(?#=s_cpu_util).*?(?#!s_cpu_util)');
127              
128              
129             1;
130              
131             __END__