# MongoDB Module - Memory / Connection issues over time

**URL:** <https://discuss.elastic.co/t/mongodb-module-memory-connection-issues-over-time/273512>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [May 20, 2021, 11:03am UTC](https://discuss.elastic.co/t/mongodb-module-memory-connection-issues-over-time/273512 "2021-05-20T11:03:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nessworthy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nessworthy/32/89011_2.png) [@Nessworthy](https://discuss.elastic.co/u/Nessworthy)\
**Post date:** [May 20, 2021, 11:03am UTC](https://discuss.elastic.co/t/mongodb-module-memory-connection-issues-over-time/273512/1 "2021-05-20T11:03:17Z")

</div>

Agent OS: Amazon Linux 2 AMI 2.0.20210326.0 x86\_64 HVM gp2  
Type: t3.medium  
(v)CPUs: 2  
Memory: 4GB  
MongoDB Version: 4.0.19  
Metricbeat Version: 6.6.0

I have the following configuration for the module:

```auto
    - hosts: ['<internal hostname>:27017']
      metricsets: [dbstats, status, metrics]
      module: mongodb
      period: 60s
    - hosts: ['<internal hostname>:27017']
      metricsets: [replstatus]
      module: mongodb
      period: 10s

```

This is part of a 3-node replica set, and is a secondary node. It has about 2TB of data stored.

Running into an issue where metricbeat is killing nodes because they're running out of memory.  
What I can see is its `listDatabases` calls taking about 25 minutes to complete, but the metricbeat agent will continue to create and query at every period tick. The nodes end up with a ton of open connections from metricbeat until eventually it runs out of memory and falls over.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/b/c/bcda09cfaf35c86244dc3a8daea67ee5a49eaf84.jpeg)

![image](https://us1.discourse-cdn.com/elastic/original/3X/4/7/4713df3ba0a85ca0376cfa2c4408e7f5f433e5b9.png)

I couldn't see any related fixes in any release notes, is there any way to set a query timeout within metricbeat to protect against this?

A big bottleneck in this case is the limited amount of memory on the instance, but protection against long-running queries would be a great thing to have!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 17, 2021, 1:03pm UTC](https://discuss.elastic.co/t/mongodb-module-memory-connection-issues-over-time/273512/2 "2021-06-17T13:03:47Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
