分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 技术分享

收集Nginx的json格式日志(五)

发布时间:2023-09-06 02:00责任编辑:傅花花关键词:jsjson

一.配置nginx

[root@linux-node1 ~]# vim /etc/nginx/nginx.conf#修改日志格式为json格式,并创建一个nginxweb的网站目录log_format access_json ‘{"@timestamp":"$time_iso8601",‘ ??????????????????????????‘"host":"$server_addr",‘ ??????????????????????????‘"clientip":"$remote_addr",‘ ??????????????????????????‘"size":$body_bytes_sent,‘ ??????????????????????????‘"responsetime":$request_time,‘ ??????????????????????????‘"upstreamtime":"$upstream_response_time",‘ ??????????????????????????‘"upstreamhost":"$upstream_addr",‘ ??????????????????????????‘"http_host":"$host",‘ ??????????????????????????‘"url":"$uri",‘ ??????????????????????????‘"domain":"$host",‘ ??????????????????????????‘"xff":"$http_x_forwarded_for",‘ ??????????????????????????‘"referer":"$http_referer",‘ ??????????????????????????‘"status":"$status"}‘; ???access_log ?/var/log/nginx/access.log ?access_json; ???????location /nginxweb { ???????????????root html; ???????????????index index.html index.htm; ???????}[root@linux-node1 ~]# mkdir /usr/share/nginx/html/nginxweb[root@linux-node1 ~]# echo "<h1> welcome to use Nginx" > /usr/share/nginx/html/nginxweb/index.html[root@linux-node1 ~]# nginx -tnginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successful[root@linux-node1 ~]# systemctl start nginx

 

二、配置logstash

# vim /etc/logstash/conf.d/nginxlog.confinput{ ???file { ???????path => "/var/log/nginx/access.log" ???????type => "nginx-access-log" ???????start_position => "beginning" ???????stat_interval => "2" ???}}output{ ??elasticsearch { ???????hosts => ["10.0.0.22:9200"] ???????index => "logstash-nginx-access-log-%{+YYYY.MM.dd}" ??}}

三、Kibana展示

[[root@saltstack02 ~]# ab -n1000 -c 100 http://10.0.0.22/nginxweb/index.html ???#对页面压测 ?[root@saltstack02 conf.d]# tailf /var/log/nginx/access.log ???#nginx的访问日志变成了json格式{"@timestamp":"2018-06-20T19:14:30+08:00","host":"10.0.0.22","clientip":"10.0.0.22","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}{"@timestamp":"2018-06-20T19:14:30+08:00","host":"10.0.0.22","clientip":"10.0.0.22","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}{"@timestamp":"2018-06-22T09:10:42+08:00","host":"10.0.0.22","clientip":"10.0.0.1","size":26,"responsetime":0.000,"upstreamtime":"-","upstreamhost":"-","http_host":"10.0.0.22","url":"/nginxweb/index.html","domain":"10.0.0.22","xff":"-","referer":"-","status":"200"}

Head插件查看:

  

  

 

收集Nginx的json格式日志(五)

原文地址:https://www.cnblogs.com/jimmy-xuli/p/9212386.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved