处理nginx访问日志,筛选时间大于1秒的请求
程序员文章站
2022-12-23 19:51:06
处理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
上一篇: 近看一窝小蜜蜂搞笑动物
下一篇: 送给Python初学者资料,希望能帮到您