nginx自定义json格式日志
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18#注意:此指令只支持http块,不支持server块 log_format access_json '{"@timestamp":"$time_iso8601",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"size":$body_bytes_sent,' '"responsetime":$request_time,' #总的处理时间 '"upstreamtime":"$upstream_response_time",' '"upstreamhost":"$upstream_addr",' #后端应用服务器处理时间 '"http_host":"$host",' '"uri":"$uri",' '"xff":"$http_x_forwarded_for",' '"referer":"$http_referer",' '"tcp_xff":"$proxy_protocol_addr",' '"http_user_agent":"$http_user_agent",' '"status":"$status"}'; access_log /apps/nginx/logs/access_json.log access_json;
编写py3脚本实现json 格式的日志访问统计
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19#python3 #!/usr/bin/env python3 #coding:utf-8 status_200= [] status_404= [] with open("access_json.log") as f: for line in f.readlines(): line = eval(line) if line.get("status") == "200": status_200.append(line.get) elif line.get("status") == "404": status_404.append(line.get) else: print("状态码 ERROR") print((line.get("clientip"))) f.close() print("状态码200的有--:",len(status_200)) print("状态码404的有--:",len(status_404))
最后
以上就是腼腆缘分最近收集整理的关于编写python3脚本监控Nginx服务状态nginx自定义json格式日志的全部内容,更多相关编写python3脚本监控Nginx服务状态nginx自定义json格式日志内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复