Perl 根據w3C日誌畫出流量折線圖

來源:互聯網
上載者:User

公司計費採集不是基於訪問日誌的。但是原始的訪問日誌是最被信賴的資源,

常常被用來檢驗各種參數,比如流量。

日誌格式:

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)"

主要 時間 和  位元組大小

#!/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

根據 /tmp/in 300s計算出一組資料。

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

然後excel可以簡單的畫出折線圖:

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.