天天看点

Nginx 日志转为Json格式

在早期的版本中,有一种降低 logstash 过滤器的 CPU 负载消耗的做法盛行于社区直接输入预定义好的 JSON 数据,这样就可以省略掉 filter/grok 配置!

这个建议依然有效,不过在当前版本中需要稍微做一点配置变动 —— 因为现在有专门的 codec 设置。

[root@linux-node1 ~]# vim /usr/local/nginx/conf/nginx.conf

log_format json '{"@timestamp":"$time_iso8601",'

'"@version":"1",'
           '"client":"$remote_addr",'
           '"url":"$uri",'
           '"status":"$status",'
           '"domain":"$host",'
           '"host":"$server_addr",'
           '"size":$body_bytes_sent,'
           '"responsetime":$request_time,'
           '"referer": "$http_referer",'
           '"ua": "$http_user_agent"'
           '}';           

access_log logs/access_json.log json;

继续阅读