zoukankan      html  css  js  c++  java
  • logstash抽取日志文件数据到ES中

    input {
      stdin {
     }
     file{
        #扫描路径下特定名称的日志文件
        #path => "/home/elastic/logs/a.log"
        #扫描路径下的.log结尾的所有日志文件
        path => "/home/elastic/logs/*.log"
        #类型名称
        type=>"log"
        #若日志为多行信息显示,需要codec配置
        codec => multiline{
            # 正则表达式,匹配开头为 "[" 的为一条日志的开始
            pattern => "^["
            negate => true
            # 设置未匹配的内容是向前合并还是向后合并,previous, next 两个值选择,必选
            what => "previous"
        }
        start_position=>"beginning"
     }
    }
    
    # filter为logstash的解析日志模块
    filter{
        if [type] == "log" {
            # 解析日志生成相关的IP,访问地址,日志级别
            grok {
                match => { 
                  "message" => "%{SYSLOG5424SD:time} %{IP:hostip} %{URIPATHPARAM:url}s*%{LOGLEVEL:loglevel}" 
                     }
            }
            # 解析log生成的时间为时间戳
            grok{
                match => {
                  "message" => "%{TIMESTAMP_ISO8601:log_create_date}"
                     }
            }
            # 替换插入信息的时间戳为日志生成的时间戳
            date {
                match => ["log_create_date", "yyyy-MM-dd HH:mm:ss" ]
                target => "@timestamp"             
            }
        }
    }
    
    #定义日志输出的配置,此处为写入解析结果到es集群
    output {
     stdout {
      codec => json_lines
     }
     if [type] == "log" {
         elasticsearch {
          hosts => "localhost:9200"
          index => "log"
          user => elastic
          password => elastic
         }
     }
    }
  • 相关阅读:
    angular2怎么使用第三方的库(jquery等)
    线性代数:方程组的几何解释
    2016新的计划
    ES+Hbase对接方案概述
    sparkR操作HDFS上面的CSV文件
    spark1.6配置sparksql 的元数据存储到postgresql中
    spark读写Sequoiadb
    Spring Boot与Docker部署
    Docker中使用Tomcat并部署war工程
    CentOS7安装使用Docker
  • 原文地址:https://www.cnblogs.com/wueryuan/p/14179154.html
Copyright © 2011-2022 走看看