跳到主要内容

日志查询

nginx日志查询

nginx 单条日志如下

120.55.28.65 - 172.18.1.33:8000 - 115.61.104.224 - 100.116.167.56 - - [04/Jun/2019:16:31:27 +0800] "GET /realmachine/recordNew.htm?uniqueId= HTTP/1.1" 200 [0.041]  [0.041] 36 "https://www.testin.cn/realmachine/recorddetail.htm?taskid=5ba0a70b899d1b1eece6a6ae&from=remote&uniqueId=" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36"

查询过程

提示

sed查询的时候,指定的开始时间和结束时间必须存在,精确到秒,否则查询结果为空

截取固定时间点日志

sed -n '/04\/Jun\/2019:16:15:00/,/04\/Jun\/2019:16:16:00/p' /data/nginx/logs/www.testin.cn_access.log >/root/test.txt

截取固定时间点有504的报错日志

awk '{if($15==504) print $0}' test.txt 

统计状态码 上述日志中第15列是状态码

awk '{a[$15]++}END{for(i in a) print a[i],i}' test.txt |sort -nr