一、前言
本文档为监控系统服务日志技术规范修订版,明确了日志信息输出的规范要求,方便系统设计人员和开发人员使用。
ps现状: 公司各部门都有自己的日志规范,存在规范不统一,接入不统一,监控大盘,报警模版不统一的痛点。在日志接入,大盘创建,报警添加方面存在耗时耗力且效果不好的问题
二、Nginx日志规范
1、日志格式要求
#access 格式 配置
log_format json escape=json '{'
'"trace_id": "$trace_id", '
'"request_length": "$request_length", '
'"remote_addr": "$remote_addr", '
'"remote_user": "$remote_user", '
'"time_local": "$time_local", '
'"time_iso8601": "$time_iso8601", '
'"request": "$request", '
'"args": "$args", '
'"status": "$status", '
'"body_bytes_sent": "$body_bytes_sent", '
'"bytes_sent": "$bytes_sent", '
'"http_referer": "$http_referer", '
'"http_user_agent": "$http_user_agent", '
'"http_x_forwarded_for": "$http_x_forwarded_for", '
'"http_host": "$http_host", '
'"server_name": "$server_name", '
'"request_time": "$request_time", '
'"request_method": "$request_method", '
'"server_protocol": "$server_protocol", '
'}';
access_log /var/log/nginx/access-json.log json buffer=64k flush=5s;
2、日志重要参数说明
参数 |
说明 |
举例 |
$remote_addr |
来访客户端的ip地址(代理服务器,显示代理服务ip) |
10.92.22.11 |
$remote_user |
来访客户端的用户名称(一般为“-”) |
- |
$time_iso8601 |
ISO 8601 标准时间格式 |
2022-09-08T18:16:03+8:00 |
$tim |