一、前言

  公司有一项目出错,过了两个小时才发现它,为了第一时间发现错误,我们运维团队选择filebeat+logstash采集错误日志,zabbix实现报警。

二、配置流程

1.配置zabbix

#创建应用集

zabbix+filebeat+logstash日志收集

#在应用集里创建监控项

zabbix+filebeat+logstash日志收集

zabbix+filebeat+logstash日志收集

#创建触发器

zabbix+filebeat+logstash日志收集

zabbix+filebeat+logstash日志收集

2、配置filebeat

编辑filebeat配置文件
vi /etc/filebeat/filebeat.yml
filebeat.prospectors:
- input_type: log
  paths:
    - /opt/ops/logs/easyopen.log
#匹配时间格式开头的日志合并多行为一行(2019-06-14)
  multiline.pattern: '^[0-9]{4}-[0-9]{2}-[0-9]{2}' 
  multiline.negate: true
  multiline.match: after
#过滤包含‘ERROR’字符串的行
  include_lines: ['ERROR']
#添加logtype字段,在logstash 做条件判断
  fields:
    logtype: easyopen_log
#输出到logstah
output.logstash:
  # The Logstash hosts   Logstash 采用tcp采集模式
  hosts: ["172.17.0.15:5044"]
2019-06-14 17:19:13.317 ERROR 13864 --- [ntLoopGroup-3-2] c.g.a.netty.ApiConfigServerHandler       : 服务端出错

java.io.IOException: Connection reset by peer
        at sun.nio.ch.FileDispatcherImpl.read0(Native Method) ~[na:1.8.0_131]
        at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39) ~[na:1.8.0_131]
        at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223) ~[na:1.8.0_131]
        at sun.nio.ch.IOUtil.read(IOUtil.java:192) ~[na:1.8.0_131]
        at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:380) ~[na:1.8.0_131]
        at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:288) ~[netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:1108) ~[netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:345) ~[netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:148) ~[netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:647) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:582) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:499) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:461) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:884) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.25.Final.jar!/:4.1.25.Final]
        at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
错误日志示例
#重启filebeat服务
systemctl restart filebeat.service

相关文章: