nginx访问日志分析,筛选时间大于1秒的请求

处理nginx访问日志,筛选时间大于1秒的请求

 
复制代码
#!/usr/bin/env python
'''
处理访问日志,筛选时间大于1秒的请求
'''
with open('test.log','a+',encoding='utf-8') as f_a:
    with open('wkxz-api.access.log') as f:
        for line in f.readlines():
            if line[-2:] == "-\n" :
                num =float(line[-7:-2])
            else:
                num=float(line[-6:])
            if num >= 1.000 :
                f_a.write(line)
复制代码
复制代码
#!/bin/bash
cat wkxz-api.access.log | while read LINE
do
#echo $LINE
time=`echo $LINE| awk '{print $NF}' | awk '{print int($0)}'`
#echo $time
  if [ "$time" -ge "1" ];then
      echo $LINE >> wkxz-api.log
  fi
done
复制代码
posted @ 2020-03-14 10:13  30岁再次出发  阅读(1061)  评论(0编辑  收藏  举报