linux系统联盟,vgos – Linux开源联盟

#!/usr/bin/perl

#--------------------------------------#

# Script Name: AccessLog.pl #

# Writer by : Tat #

# Create time: 2012-03-27 #

# Last update: 2012-03-30 #

# Ver: 0.1 beta #

#--------------------------------------#

use strict;

use warnings;

#----------数据统计变量----------------

my $sum = 0; #总日志数量

my $code5 = 0; #Http 500错误页

my $code2 = 0; #Http 200页

my $tophome=0; #进入主页数据

#----------条件匹配变量---------------

my $home = "/home.htm"; #进入主页匹配

#-------------时间涵数------------------

sub getTime(){

(my $sec,my $min,my $hour,my $day,my $mon,my $year,

my $weekday,my $yeardate,my $savinglightday) = (localtime(time-86400));#time-86400前一天

$sec = ($sec < 10)? "0$sec":$sec;

$min = ($min < 10)? "0$min":$min;

$hour = ($hour < 10)? "0$hour":$hour;

$day = ($day < 10)? "0$day":$day;

$mon = ($mon < 9)? "0".($mon+1):($mon+1);

$year += 1900;

my $now = "$year-$mon-$day";

return $now;

}

#------------其他变量-----------------

my $namemin=getTime();

my $filename="access.$namemin.log";

my $tmpfile="/tmp/access.log";

my $logfile=$tmpfile;

if(-e $tmpfile)

{

system("rm $tmpfile");

}

system("find /logs/*/ -name $filename|xargs cat |

awk \'{print \$1 \" \" \$2 \" \" \$3 \

" \" \$6 \" \" \$10 \" \" \$12}\' >> $tmpfile");

open(INFILE,$logfile)||die "can't open ddns_log file $logfile: $!\n";

line: while(my $line=){

$line =~ /^\[

([\d\w:\/]+)\s\+\d{4}\] #Date matching

\s+

(\d+) #Http Status code matching

\s+

(\d+|-) #phone

\s+

(\w+) #Request type

\s+

(\/([^\s]*)|.*) #url

$/ix or do

{

next line;

};

if ($2 >=500){

$code5 ++;

}

if($2 == 200){

$code2 ++;

}

if($4 eq "GET" && $5 eq $home){

$top ++;

}

$sum ++;

}

print "####################【日志统计】#####################\n";

print "总处理日志条数:: $sum\n";

print "页面50X代码条数:: $code5\n";

print "页面200代码条数 :: $code2\n";

print "##########################################################\n";

system("rm $tmpfile");

脚本是用来统计一个access日志用户行为的初本,由于考虑机密问题只放出初本供大家参考。

tomcat日志格式

pattern=”%t %s %T %b %{x-up-calling-line-id}i %{x-up-bear-type}i %a %{x-forwarded-for}i %m [%{HOST}i] %U%q [%{User-Agent}i] [%{Accept-Encoding}i]“

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值