Jimliu


一只刚上路的前端程序猿


logstash解析nginx日志

配置好ELK后,使用logstash读取nginx日志,但是logstash没有默认的nginx日志格式解析插件,需要自己使用正则匹配。
这里有一个简便的配置方案:

1.配置nginx日志log format

1
2
3
4
5
6
7
8
9
10
11
12
13
log_format 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",'
'"xff":"$http_x_forwarded_for",'
'"referer":"$http_referer",'
'"agent":"$http_user_agent",'
'"status":"$status"}';

2.logstash配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
input {
file {
path => "/var/log/nginx/access.log"
codec => json
}
}
filter {
mutate {
split => [ "upstreamtime", "," ]
}
mutate {
convert => [ "upstreamtime", "float" ]
}
}
最近的文章

js中引入模块那些事

系统的总结一下 js 引入模块的方式。 主流模块及规范在es6以前,还没有提出一套官方的规范,从社区和框架推广程度而言,目前通行的javascript模块规范有两种:CommonJS 和 AMD CommonJS在CommonJS中,暴露模块使用module.exports和exports;在一个n …

于  js 继续阅读
更早的文章

服务器安装ELK

一.安装java环境由于Elasticsearch和Logstash的要求,在服务器首先安装jdk 1.8 …

于  ELK, linux 继续阅读