首页 > 其他 > 详细

logstash抽取日志文件数据到ES中

时间:2021-01-18 16:33:14      阅读:124      评论:0      收藏:0      [点我收藏+]
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
     }
 }
}

 

logstash抽取日志文件数据到ES中

原文:https://www.cnblogs.com/wueryuan/p/14179154.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!