elk查询nginx日志响应时间

一、目标

通过kibana方便查询nginx中的响应时间

 

二、搭建过程

本文的架构是:Filebeat+kafka+Logstash+ES+kibana,具体搭建请参照其他文章。版本是elasticsearch 7.4。

新增配置如下:

1、nginx日志格式修改

为了能让es识别nginx响应时间数据,成为独立的字段,需要把nginx日志改为json输出。

log_format main '{"@timestamp":"$time_iso8601",'
                  '"trace":"$upstream_http_ctx_transaction_id",'
                  '"log":"log",'
                  '"remote_addr":"$remote_addr",'
                  '"request":"$request",'
                  '"http_user_agent":"$http_user_agent",'
                  '"bytes_sent":$bytes_sent,'
                  '"request_time":$request_time,'
                  '"upstream_response_time":"$upstream_response_time",'
                '"upstream_addr":"$upstream_addr",'
                  '"scheme":"$scheme",'
                '"server_addr":"$server_addr",'
                '"http_host":"$http_host",'
                '"host":"$host",'
                  '"uri":"$uri",'
                  '"http_x_forwarded_for":"$http_x_forwarded_for",'
                  '"http_referer":"$http_referer",'
                  '"status":"$status"}';

重启nginx, 是日志配置生效。

2、filebeat

修改filebeat.yml配置文件,在需要显示为json的输入类型中添加一下配置:

json.message_key: event
  json.keys_under_root: true
  json.add_error_key: true

重启filebeat:

service filebeat restart

3、kibana配置

因为有新的字段加入,所以要刷新nginx的索引模式

 

三、效果

查看

 

搜索条件,大于1秒的请求:

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值