Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1730352
  • 博文数量: 150
  • 博客积分: 660
  • 博客等级: 上士
  • 技术积分: 2480
  • 用 户 组: 普通用户
  • 注册时间: 2005-08-08 11:39
文章分类

全部博文(150)

文章存档

2019年(4)

2018年(36)

2017年(53)

2016年(7)

2015年(3)

2014年(3)

2013年(27)

2012年(2)

2011年(1)

2006年(1)

2005年(13)

分类: 系统运维

2013-09-03 10:22:06

1、目标


统计给定日志中按照地区分类的访问耗时,该统计可以发现访问速度有问题的区域
 
2、脚本说明


a、该awk脚本有shell脚本调用,其中shell脚本的$1为参数传递到awk内部的city变量,格式为 tj_by_city.awk city=$1 
b、脚本排除耗时小于0,或者总耗时小于操作耗时的情况


3、脚本内容


#!/bin/awk -f
BEGIN{
        cnt=1;
     }



        # $1 为日期
        # $2 为时间
        # $7 地区代码
        # $10 操作耗时
        # $12 http返回代码
        # cnt 为次数数组
        # alltime 为各地区总耗时数组
  #debug
  #print city;
  #debug 
  split($7,area,"=");
  #debug
  #print substr(area[2],1,2);
  #debug
  if(substr(area[2],1,2)==city)
        {


           split($12,time,"=");
           if (time[2]>0) 


                {
                        consumtime=time[2];
              
  
                        if(substr($14,11,3)==200) 
                                {
                                        alltime=consumtime+alltime;
                                        cnt=cnt+1;
                                }
                }
  
        }
}
END {


                #  print city,alltime/cnt+0,cnt-1;
                print alltime/cnt+0 ; 
    }
阅读(2103) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~