Perl draws a traffic line chart based on W3C logs

Source: Internet
Author: User

The company's billing is not based on access logs. However, the original access logs are the most trusted resources,

It is often used to test various parameters, such as traffic.

Log format:

222.85.90.158--[01/SEP/2012: 00: 00: 00 + 0800]
"Get/download/apks/ggg-market-1/gggmarket2.0.3zhidian201.apk? HTTP/1.1 "206
126410 "-" "Apache-httpclient/unavailable (Java 1.4 )"

Main time and byte size

#!/usr/bin/perl#use warnings;  #use strict;  use Data::Dumper;use Time::Local;my $hash;my $text = $ARGV[0];  my $num = 0;my $interval = $ARGV[1];my $flag = 0;open FILE ,"<$text" or die "Can't open myfile: $!";        while ($line = <FILE>) {        #       print $line;        my @a = split (/\s+/,$line);        $time = $a[3];        $time =~/\[(.*)/;        $time = $1;        $num =  $a[9];        my $string = $time;        %month = (                        'Jan', '01',                         'Feb', '02',                         'Mar', '03',                         'Apr', '04',                         'May', '05',                         'Jun', '06',                         'Jul', '07',                         'Aug', '08',                         'Sep', '09',                         'Oct', '10',                         'Nov', '11',                         'Dec', '12',                  );        my ($year,$month,$date,$hour,$minute,$second);        if($string=~ m/(\d+)\/(\w+)\/(\d+):(\d+):(\d+):(\d+)/){                $year = int $3;                $month = int $month{$2} - 1 ;                $date = int $1;                $hour = int $4;                $minute = int $5;                $second = int $6;        }        else        {                next;        }        $string = timelocal( $second,$minute,$hour,$date,$month,$year);        if( $flag == 0 )        {                $begin_time = $string;                $flag = 1;        }        if($string - $begin_time < $interval)        {                $hash_time = $begin_time;        }        else        {                $begin_time = $string;                $hash_time = $begin_time;        }        if(exists $hash->{$hash_time}){                $hash->{$hash_time} += $num;        }        else        {                $hash->{$hash_time} = $num;        }}#print Dumper($hash);foreach $time (sort keys %{$hash} ) {         print  $time."\t";        print $hash->{$time}."\n" ;}

Perl check_for_billing.pl/tmp/in1 300

Calculate a set of data based on/tmp/in S.

Check_for_billing.pl in1 60

1346428800 1624072102
1346428860 1819704465
1346428920 1652706944
1346428980 1796033459
1346429040 1771569864
1346429100 1744929423
1346429160 1922832195
1346429220 1660383579
1346429280 1714866844
1346429340 1721153695
1346429400 1642454102
1346429460 1544478258
1346429520 1310100814
1346429580 1581676557
1346429640 1518062958
1346429700 1833178378
1346429760 1580890704
1346429820 1733835211
1346429880 1549757477
1346429940 1460066927
1346430000 1642321720
1346430060 1520984661
1346430120 1598766051
1346430180 1436598072
1346430240 1501967340

Then, you can draw a line chart in Excel:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.