博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx 日志问题(\x22)
阅读量:4694 次
发布时间:2019-06-09

本文共 1520 字,大约阅读时间需要 5 分钟。

问题:

request_body中含有中文时,nginx日志会转换为十六进制。

优化:

logstash为了能高效的处理各类日志,希望日志是一种特定结构存储的方式。

nginx默认日志格式:

log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                      '$status $body_bytes_sent "$http_referer" '                      '"$http_user_agent" "$http_x_forwarded_for" $request_body';

问题日志

[25/Feb/2019:00:00:10 +0800]|192.168.10.19|POST /paas/callback HTTP/1.1|200|163|0.002|0.002|{\x22rc\x22:0,\x22msg\x22:\x22success\x22,\x22transferrate\x22:\x2245301\x22}]}}

request_body中都是转换后十六进制,不易阅读.


直接提供可视化日志格式和解决十六进制的解决办法:

格式化数据:

###json格式:    log_format log_json escape=json '{"timestamp": "$time_local",'        '"remote_addr": "$remote_addr",'        '"referer": "$http_referer",'        '"request": "$request",'        '"statu": "$status",'        '"byte": "$body_bytes_sent",'        '"agen": "$http_user_agent",'        '"x_forwarde": "$http_x_forwarded_for",'        '"request_time": "$request_time"}';###自定义边界:log_format main escape=json '[$time_iso8601]|$remote_addr|$request_method|$request|$status|$body_bytes_sent|$request_time|$request_body|'                '"$http_referer"|"$http_user_agent"|$http_x_forwarded_for|'                '"$upstream_addr"|$upstream_response_time|'                '$upstream_cache_status|$scheme|$http_user_agent';
  • log_format :日志格式开头
  • main :日志名称
  • escape=json :nginx 1.11.8版本后才提供此参数。

如果版本低,要么升级,要么在logstash中使用ruby给做一次转化,可参考链接:

总结:
正常格式的日志,在logstash中需要使用grok语句进行匹配,会消耗较多的性能。如果日志在生成时就将格式固定好,后续的处理就会很简易。

转载于:https://www.cnblogs.com/dance-walter/p/10635260.html

你可能感兴趣的文章
[wp7游戏]wp7~~X-Box Live游戏~~集合贴~~
查看>>
Access 标准表达式中数据类型不匹配问题
查看>>
Python实现屏幕截图
查看>>
【Python求助】在eclipse和pycharm中,通过adb install安装中文名字APK时老是报错,如何解决...
查看>>
用weka来做Logistic Regression
查看>>
Linux现学现用之Top命令
查看>>
[C3W1] Structuring Machine Learning Projects - ML Strategy 1
查看>>
【原创】谈谈服务雪崩、降级与熔断
查看>>
Java加密代码 转换成Net版
查看>>
jquery.validation.js 使用
查看>>
day38 mycql 初识概念,库(增删改查),表(增删改)以及表字段(增删改查),插入更新操作...
查看>>
数据库高级查询
查看>>
C语言实现封装、继承和多态
查看>>
Linux字符设备驱动框架(二):Linux内核的LED设备驱动框架
查看>>
创建文件
查看>>
Nginx 相关介绍
查看>>
leetcode[33]Search in Rotated Sorted Array
查看>>
安卓上按钮绑定监听事件的两种写法
查看>>
OpenCV Shi-Tomasi角点检测子
查看>>
jQurey基础简介
查看>>