filebeat收集json格式的日志
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json
免费下载资源
·
正常情况下,我们收集到的日志的格式可能和我们要求的不太一样,所以需要将日志按照我们要求的格式进行展现,在kibana中也可以直接过滤搜索。
查找对应的版本,我的是7.3版本的,官网的配置如下:
filebeat.inputs:
- type: log
enabled: true
paths:
- /var/log/nginx/access.log
json.key_under_root: true
json.overwrite_keys: true
json.message_key: log
tags: ["access"]
- type: log
enabled: true
paths:
- /var/log/nginx/error.log
json.key_under_root: true
json.overwrite_keys: true
json.message_key: log
tags: ["error"]
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.ilm.enabled: false
setup.template:
name: "test-nginx"
pattern: "test-nginx-*"
setup.template.overwrite: true
setup.template.enabled: false
setup.kibana:
host: "172.123.154.13:5601"
output.elasticsearch:
hosts: ["172.123.154.13:9203"]
indices:
- index: "test-nginx-access-%{+yyyy.MM.dd}"
when.contains:
tags: "access"
- index: "test-nginx-error-%{+yyyy.MM.dd}"
when.contains:
tags: "error"
nginx中的配置如下
log_format json '{"@timestamp":"$time_iso8601",'
'"host": "$server_addr",'
'"clientip": "$remote_addr",'
'"request_body": "$request_body",'
'"responsetime": $request_time,'
'"upstreamtime": "$upstream_response_time",'
'"upstreamhost": "$upstream_addr",'
'"http_host": "$host",'
'"url": "$uri",'
'"referer": "$http_referer",'
'"agent": "$http_user_agent",'
'"status": "$status"}';
#日志使用json的模板
access_log /var/log/nginx/access.log json;
发送几条请求,然后看到es中有索引生产。
在kibana中查看到message数据已经按照json的格式进行展示。
错误的日志message就是一行
GitHub 加速计划 / js / json
41.72 K
6.61 K
下载
适用于现代 C++ 的 JSON。
最近提交(Master分支:1 个月前 )
960b763e
2 个月前
8c391e04
5 个月前
更多推荐
已为社区贡献4条内容
所有评论(0)