# 更多ELK资料请访问 http://devops.taobao.com

一、配置前需要注意:

1.Use chmod to modify nginx log file privilege. E.g. chmod 664 access.log
2.Modify /etc/default/logstash => LS_USER field to change logstash user, e.g. root -------------------------------------------------------------------------- 二、logstash配置文件: input {
file {
type => "nginx-access"
path => "/var/nginx/access.log" # MODIFY REQUIRED! point to nginx access.log file
start_position => beginning # read file from beginning, instead of from end as default
ignore_older => 0 # do not ignore old file
}
file {
type => "nginx-error"
path => "/var/nginx/error.log" # MODIFY REQUIRED! point to nginx error.log file
start_position => beginning
ignore_older => 0
}
} filter {
# separate parsing for nginx access and error log
if [type] == "nginx-access" {
# default nginx access log pattern (nginx 1.4.6). You may change it if it doesn't fit
grok {
match => { "message" => "%{COMBINEDAPACHELOG}+%{GREEDYDATA:extra_fields}" }
}
} else if [type] == "nginx-error" {
# default nginx error log pattern (nginx 1.4.6). You may change it if it doesn't fit (but ensure "clientip" field)
grok {
match => [ "message" , "(?<timestamp>%{YEAR}[./-]%{MONTHNUM}[./-]%{MONTHDAY}[- ]%{TIME}) \[%{LOGLEVEL:severity}\] %{POSINT:pid}#%{NUMBER}: %{GREEDYDATA:errormessage}(?:, client: (?<clientip>%{IP}|%{HOSTNAME}))(?:, server: %{IPORHOST:server}?)(?:, request: %{QS:request})?(?:, upstream: (?<upstream>\"%{URI}\"|%{QS}))?(?:, host: %{QS:request_host})?(?:, referrer: \"%{URI:referrer}\")?"]
}
} # add geo-location info
geoip {
source => "clientip"
}
} output {
# output to local Elasticsearch server as index, separated by log type and date
elasticsearch {
hosts => ["127.0.0.1"]
index => "%{type}-%{+YYYY.MM.dd}"
}
} -------------------------------------------------------------------------- github地址:https://github.com/adventure-yunfei/ELK-for-nginx-log

logstash 根据type 判断输出的更多相关文章

  1. logstash 通过type判断

    [elk@zjtest7-frontend type]$ cat input.conf input { file { type => "type_a" path => ...

  2. Logstash type来标记事件类型,通过type判断

    /*************** 根据type判断 input { file { type => "zj_frontend_access" path => [" ...

  3. logstash收集的日志输出到elasticsearch中

    logstash收集的日志输出到elasticsearch中 一.需求 二.实现步骤 1.编写pipeline文件 1.`elasticsearch`配置参数解析: 2.可能会报的一个异常 2.准备测 ...

  4. 浏览器解析js和type判断数据类型

    ### 浏览器解析: - 1.当浏览器(内核.引擎)解析和渲染js的时候,会给js提供一个运行的环境,这个环境叫做“全局作用域(后端global / 客服端window scope)” - 2.代码自 ...

  5. ThinkPHP 模板判断输出--Switch 标签

    ThinkPHP 模板引擎支持 switch 判断,根据不同情况输出不同的值,格式如下:<switch name="变量名" >    <case value=& ...

  6. 类型(type)判断

    windows下源文件编码问题 在windows下不要直接右击桌面创建.txt再改成.c,这种方式容易引起编码问题 windows下gvim的设置: 先打开gvim再用:w newfile.c这种方式 ...

  7. Python中为什么推荐使用isinstance来进行类型判断?而不是type

    转自:http://www.xinxingzhao.com/blog/2016/05/23/python-type-vs-isinstance.html Python在定义变量的时候不用指明具体的的类 ...

  8. type,isinstance判断一个变量的数据类型

    type,isinstance判断一个变量的数据类型 import types type(x) is types.IntType # 判断是否int 类型 type(x) is types.Strin ...

  9. logstash输出到elasticsearch多索引

    目标:将json格式的两类日志输出到elasticsearch两类索引 1. 安装logstash. 2. 编写logstash处理配置文件,创建一个test.conf文件,内容如下: input { ...

随机推荐

  1. DOMDocument类文件

    http://php.net/manual/en/class.domdocument.php <?php $xml = <<< XML <?xml version=&qu ...

  2. git基础命令

     git pull 更新git status 查看文件状态git add .添加所有git commit -a -m "xxxx" 提交git push 推送至服务器git dif ...

  3. 使用SelectClipRgn注意事项

    SelectClipRgn 函数功能:该函数选择一个区域作为指定设备环境的当前剪切区域. 函数原型:int SelectClipRgn(HDc hdc, HRGN hrgn): 参数: hdc:设备环 ...

  4. UVA 10943 How do you add?

    设函数 f(k)(n); 则: f(1)(n)=1; f(2)(n)=f(1)(0)+f(1)(1)+f(1)(2)+...+f(1)(n); f(3)(n)=f(2)(0)+f(2)(1)+f(2) ...

  5. 基于TCP套接字实现的简单Demo

    由于代码的注释已经很详尽了,所以这里不再作过多说明.仅仅贴出代码和结果图. 值得注意的是必须先启动server程序再启动client. Server: #include <WINSOCK2.H& ...

  6. 【LeetCode练习题】Scramble String

    Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...

  7. 网易云课堂_C++程序设计入门(上)_第1单元:C++概览_第1单元作业 - 写代码 - 互评 (难度:易)

    第1单元作业 - 写代码 - 互评 (难度:易) 查看帮助 返回   提交作业(截止时间已过) 完成并提交作业     作业批改 互评训练   互评作业   自评作业     成绩公布 查看成绩 温 ...

  8. 学习本课程需要具备哪些基础及微信小程序目录结构介绍

    1.html css js 基础 2.ajax 基础 3.简单的面向对象基础  

  9. java的静态代理

    解决这个问题:在多个模块要插入一段功能,比方,在不同业务处理模块中,都须要检查用户是否登录,假设不使用代理的话,每添加一个模块,就须要添加非常多代码. 比方,除了推断是否登录,假设还须要添加一个记录日 ...

  10. Java Math的 floor,round和ceil的总结

    floor 返回不大于的最大整数 round 则是4舍5入的计算,入的时候是到大于它的整数round方法,它表示“四舍五入”,算法为Math.floor(x+0.5),即将原来的数字加上0.5后再向下 ...