# 更多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. 比较常见的const与指针的组合情况

    1.对于普通的const与基本类型组合,都是表示的是这是一个常量, const int a; int const a; 表示的意思是一样的,a是一个常量,不可改变 2.对于const与指针组合在一起, ...

  2. python 解释器内建函数001

    python解释器内建函数列表如下: 001.abs() 求绝对值 #!/usr/bin/python if __name__=="__main__": print(abs(-10 ...

  3. 解决CentOS(RedHat)中sendmail和sm-client启动慢故障(转)

    Starting sendmail: Starting sm-client: 刚才发了修改主机名那篇文章后,我意外发现重新启动CentOS的时候系统会卡在sendmail和sm-client那里将近3 ...

  4. lostash 正则

     (?:\s+?)  0个或者多个空格

  5. 通过Jetty搭建一个简单的Servlet运行环境

    最近在做一些简单的Servlet开发的时候,感觉每次调试的时候都要发布到tomcat上很麻烦,把程序共享给同事也很麻烦,需要帮他设置本地的tomcat环境. 在网上找了找其他的Servlet运行环境, ...

  6. Codeforces 482B Interesting Array(线段树)

    题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...

  7. 【最大流】【HDU3338】【Kakuro Extension】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3338 题目大意:填数字,使白色区域的值得和等于有值得黑色区域的相对应的值,用网络流来做 题目思路:增加 ...

  8. Js特效总结

    1.//#hidediv2为一个需要隐藏的div  这个功能实现当点击hidediv2以外的其他任何位置时,隐藏该div $(document).click(function() {          ...

  9. Debug编辑通过转Release找不到命名空间

    首先查看缺少命名空间在哪个项目中 然后看缺少命名空间项目中bin/Release有没有相关文件 如果没有对该项目进行Release编译然后在编译所有项目

  10. SQL 数据库知识点回顾

    SQL2008 一.安装注意事项: 1.修改用户权限(在一个安装页面中有七八个)(改成net.) 2.添加当前系统用户为账户 二.主键,约束,索引 三.增删改查: insert.delete.upda ...