filebeat:Failed to publish events caused by: write tcp 5044: write: connection reset by peer

简介: filebeat:Failed to publish events caused by: write tcp 5044: write: connection reset by peer

一、问题描述



filebeat的日志文件上一直在报这个错误:Failed to publish events caused by: write tcp 5044: write: connection reset by peer,从明面上看这个问题就是联通logstash时失败了,具体是什么原因却看不出来。刚开始网络上搜了下,发现网上的解决方法都是给logstash配置个连接超时的配置,就是在logstash的input里面配置如下即可:


input {
        beats {
                port => 5044
                codec => json
                client_inactivity_timeout => 36000
        }
}


笔者试了,不好使,根本原因还是我这里的报错不是这个导致的。


二、问题原因



上面的方法不好使,然后笔者就去检查了logstash的日志,有下面这块日志信息:

io.netty.util.internal.OutOfDirectMemoryError: failed to allocate 16777216 byte(s) of direct memory (used: 1029357059, max: 1037959168)
        at io.netty.util.internal.PlatformDependent.incrementMemoryCounter(PlatformDependent.java:640) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.util.internal.PlatformDependent.allocateDirectNoCleaner(PlatformDependent.java:594) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PoolArena$DirectArena.allocateDirect(PoolArena.java:764) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PoolArena$DirectArena.newChunk(PoolArena.java:740) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PoolArena.allocateNormal(PoolArena.java:244) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PoolArena.allocate(PoolArena.java:214) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PoolArena.allocate(PoolArena.java:146) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:324) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:185) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:176) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.buffer.AbstractByteBufAllocator.ioBuffer(AbstractByteBufAllocator.java:137) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.DefaultMaxMessagesRecvByteBufAllocator$MaxMessageHandle.allocate(DefaultMaxMessagesRecvByteBufAllocator.java:114) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:125) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497) ~[netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459) [netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858) [netty-all-4.1.18.Final.jar:4.1.18.Final]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) [netty-all-4.1.18.Final.jar:4.1.18.Final]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_281]


看到这里就很简单明了了,logstash是用java写的,这里报的是直接内存这块使用已经满了,那就给直接内存增加点容量吧(注意:直接内存不属于堆栈范围,他是jvm虚拟机之外的内存,jvm是通过DirectByteBuffer来操作这块堆外内存的,这块内存常常会因为我们的忽视,导致内存溢出,直接内存详情请看这里:JVM内存结构详细总结)

然后笔者就去修改了logstash的jvm参数,就ok了。


三、问题解决



从报错上看 1037959168 该值将近1G,笔者直接提到了2G,参数如下

-XX:MaxDirectMemorySize=2048M


logstash配置截图如下:

7699cf05a0e4446caa5fc9c832ad5c23.png

logstash的运行截图如下:

image.png

(备注:这里当时配置的是2024不是2048,属于失误)


相关文章
|
人工智能
Timeout on reading data from socket
Timeout on reading data from socket
126 3
ConnectionResetError: [Errno 104] Connection reset by peer|4-16
ConnectionResetError: [Errno 104] Connection reset by peer|4-16
|
2月前
|
网络安全
client_loop: send disconnect: Connection reset by peerB/s4-5
client_loop: send disconnect: Connection reset by peerB/s4-5
|
4月前
|
监控 网络安全
Connection reset by peer的原因
Connection reset by peer的原因
【已解决】kex_exchange_identification: Connection closed by remote host fatal: Could not read from
【已解决】kex_exchange_identification: Connection closed by remote host fatal: Could not read from
|
Java 网络安全 Docker
curl: (56) Recv failure: Connection reset by peer
curl: (56) Recv failure: Connection reset by peer
697 0
sls报错:m_idle_streams_timeout=10s, call invalid_srt
sls报错:m_idle_streams_timeout=10s, call invalid_srt
76 0
sls报错:m_idle_streams_timeout=10s, call invalid_srt
|
网络协议 安全 Linux
如何修复 SSH Client_loop: send disconnect: Broken pipe Error
如何修复 SSH Client_loop: send disconnect: Broken pipe Error
3113 1
|
Python
ConnectionResetError: [Errno 104] Connection reset by peer
ConnectionResetError: [Errno 104] Connection reset by peer
575 0
|
网络协议
OGG-01232 Receive TCP params error: TCP/IP error 104 (Connection reset by peer), endpoint:
源端: 2015-02-05 17:45:49 INFO OGG-01815 Virtual Memory Facilities for: COM anon alloc: mmap(MAP_ANON) anon free: munmap file alloc: mmap(MAP_SH...
3107 0