ELK B 之 logstash filebeat

下载logstash,下面是参考conf demo,主要是filter的ruby语法
测试数据

00:00:47 - Timeout : total:21, init:4, getUser:0, userReal:0, negs:2, negByZrevrange:1, negGetAllCSet:1, parseLastDoc:1, getNewlastdoc:0, updateUserSession:0, lastdoc:1, isColdUser:0, preRequest:2, printLast:2, updateSpecial:0, send:0, bizRecom:14, hotTagPosi:0, userSubNews:0, userSubCache:0, localPosi:1, positive:1, getLastDoc:0, getSessionLastDoc:0, getPositiveIndex:0, doPosi:0, FeedRecallInfo:0, videoPositive:1, getLastVideo:0, videFeedRecallInfo:0, bid:6, userPosiSearch:0, userSearchIndex:0, recallInfo:0, personal:3, getindex:1, rank:1, trans:0, responseSupport:1, updateEv:0,uid:191f851a87e7420ba748630bc0e3752b

input {
  beats {
    port => 5044 #监听的端口
    codec => multiline {
         pattern => "^*"
         negate => true
         what => previous
    }
  }
}
filter {
  ruby{
  #ruby 字符串解析处理逻辑
        code => "
        #event.get('message').split(',').each{|str| event.set(str.split(':')[0],str.split(':')[1])}
        a=event.get('message').split('-')
        time = Time.now.strftime('%Y-%m-%d')
        time = time+' '+a[0].strip
        event.set('time',time)
        b=a[1].split(',')
        length=b.length-1
        for i in 0..length do
          if b[i].include?('Timeout')
            m=b[i].match('\d+')
            event.set('total',m[0].to_i)
            #event.set('message.total',m[0].to_i)
          elsif b[i].include?(':')
            c=b[i].split(':')
            if c[0].lstrip.rstrip=='uid'
              event.set(c[0].strip,c[1].strip)
            else
              unless c[0].nil?||c[1].nil?
                event.set(c[0].strip,c[1].strip.to_i)
                #event.set('message.'+c[0].strip,c[1].strip.to_i)
              end
            end
          else

          end
        end
        event.remove('tags')
        event.remove('beat')
        event.remove('@version')
                "

   }


}
---------测试用,控制台输出-------------
#output {
#  stdout {
#    codec => rubydebug }
#}
--------------es输出-----------------------
output {
#program logs
    if [type] == :1-account_errorlog'{        #'192.168.1.21-account_errorlog'为filebeat配置中由document_type定义的
        elasticsearch {          #输出到elasticsearch中
                hosts => ["127.0.0.1::9201"]       #指定elasticsearch主机
                index => "%{type}-%{+YYYY.MM.dd}"
                document_type => "log"       #设定Elasticsearch输出时的document的type字段,也可以用来给日志进行分类
                template_overwrite => true       #如果设置为true,模板名字一样的时候,新的模板会覆盖旧的模板
        }
    }
    if [type] == 'timeout-account_log'{
        elasticsearch {
                hosts => ["127.0.0.1:9201"]
                index => "%{type}-%{+YYYY.MM.dd}"
                document_type => "log"
                template_overwrite => true
        }
    }
}

filebeat 占用内存小,logforword
filebeat.yml 样例

filebeat.prospectors:
- input_type: log  #指定文件的输入类型log(默认)或者stdin
  paths:   #指定要监控的日志,目前按照Go语言的glob函数处理,没有对配置目录做递归处理,如果指定的文件为/var/log/*.log的话,会读取该目
录下所有以log结尾的文件,但是这样不好,在logstash上不好处理,会写到一个文件内,kibana显示会很乱,建议分开写
    - /home/wangxl6/test.log      #指定filebeat读取的文件(绝对路径)
  document_type: timeout-account_log   #设定Elasticsearch输出时的document的type字段,也可以用来给日志进行分类
output.logstash:
  hosts: ["127.0.0.1:5044"]

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值