# Metricbeat/mongodb leaks connections when metricbeat.config.modules.reload.enabled set to true

**URL:** <https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723>\
**Category:** Beats\
**Tags:** metricbeat\
**Created:** [November 22, 2017, 1:44pm UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723 "2017-11-22T13:44:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![david.kostal](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@david.kostal](https://discuss.elastic.co/u/david.kostal)\
**Post date:** [November 22, 2017, 1:44pm UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/1 "2017-11-22T13:44:02Z")

</div>

Hi,  
I just enabled metricbeat's mongodb module (5.6) and suddenly our mongdb run out of file descriptors. I noticed that metricbeat keeps thousands of connections open to the mongodb.

Further investigation showed that if i enable reload of metricbeat modules:  
metricbeat.config.modules:  
path: /etc/metricbeat/conf.d/\*.yml  
reload:  
enabled: true  
period: 10s

then with every probe to mongodb additional 4 connections are created.  
If i disable the reload (set to false), there is no connection leak at all and it only keeps 10 connections open.

Anyone experienced this? Is there a way how to prevent the connection leak?  
Thanks,  
David

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [November 22, 2017, 5:10pm UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/2 "2017-11-22T17:10:22Z")

</div>

There was bug [fixed](https://github.com/elastic/beats/pull/5141) in 6.0 related to reloading. Can you enable debug for the `cfgfile` selector to see if the module is being constantly reloaded. I think we need to backport this fix to the 5.6 branch. This would make any leak that exist get exposed really quickly.

```auto
logging.level: debug
logging.selectors: [cfgfile]

```

Can you please share the config that you are using for the mongodb module?

Additionally I have opened [https://github.com/elastic/beats/issues/5688](https://github.com/elastic/beats/issues/5688) because I don't see where the session is closed in mongodb metricsets.

---

<div class="post-metadata">

**Author:** ![david.kostal](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@david.kostal](https://discuss.elastic.co/u/david.kostal)\
**Post date:** [November 23, 2017, 6:33am UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/3 "2017-11-23T06:33:39Z")

</div>

Here is the mongodb.yml config for the module:

- module: mongodb  
metricsets:  
- status  
- dbstats  
enabled: true  
period: 10s  
hosts:  
- mongodb://127.0.0.1:27017  
username: xxxxxxxx  
password: xxxxxxxx

I also tried the connection string with ?maxPoolSize=4 (or other numbers and did not help).

The main metricbeat.yml contains:  
metricbeat.config.modules:  
path: /etc/metricbeat/conf.d/\*.yml  
reload:  
enabled: true  
period: 10s

---

<div class="post-metadata">

**Author:** ![david.kostal](https://avatars.discourse-cdn.com/v4/letter/d/0ea827/32.png) [@david.kostal](https://discuss.elastic.co/u/david.kostal)\
**Post date:** [November 23, 2017, 6:38am UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/4 "2017-11-23T06:38:59Z")

</div>

And the log after enabling the debugging says (and yes, the connections stay open):  
2017-11-23T06:28:09Z INFO Home path: [/usr/share/metricbeat] Config path: [/etc/metricbeat] Data path: [/var/lib/metricbeat] Logs path: [/var/log/metricbeat]  
2017-11-23T06:28:09Z INFO Setup Beat: metricbeat; Version: 5.6.4  
2017-11-23T06:28:09Z INFO Metrics logging every 30s  
2017-11-23T06:28:09Z INFO Max Retries set to: 3  
2017-11-23T06:28:10Z INFO Activated logstash as output plugin.  
2017-11-23T06:28:10Z INFO Publisher name: prod-mongo1  
2017-11-23T06:28:10Z INFO Flush Interval set to: 1s  
2017-11-23T06:28:10Z INFO Max Bulk Size set to: 2048  
2017-11-23T06:28:10Z INFO Register [ModuleFactory:[docker, mongodb, mysql, postgresql, system], MetricSetFactory:[apache/status, ceph/cluster\_disk, ceph/cluster\_health, ceph/monitor\_health, ceph/pool\_disk, couchbase/bucket, couchbase/cluster, couchbase/node, docker/container, docker/cpu, docker/diskio, docker/healthcheck, docker/image, docker/info, docker/memory, docker/network, haproxy/info, haproxy/stat, jolokia/jmx, kafka/consumergroup, kafka/partition, mongodb/dbstats, mongodb/status, mysql/status, nginx/stubstatus, php\_fpm/pool, postgresql/activity, postgresql/bgwriter, postgresql/database, prometheus/collector, prometheus/stats, redis/info, redis/keyspace, system/core, system/cpu, system/diskio, system/filesystem, system/fsstat, system/load, system/memory, system/network, system/process, system/socket, zookeeper/mntr]]  
2017-11-23T06:28:10Z INFO metricbeat start running.  
2017-11-23T06:28:10Z WARN BETA: feature dynamic configuration reloading is enabled.  
2017-11-23T06:28:10Z INFO Config reloader started  
2017-11-23T06:28:20Z DBG Scan for new config files  
2017-11-23T06:28:20Z DBG Load config from file: /etc/metricbeat/conf.d/all.yml  
2017-11-23T06:28:20Z DBG Load config from file: /etc/metricbeat/conf.d/mongodb.yml  
2017-11-23T06:28:20Z DBG Number of module configs found: 2  
2017-11-23T06:28:20Z DBG Remove module from stoplist: 1187029132801020061  
2017-11-23T06:28:20Z DBG Add module to startlist: 1187029132801020061  
2017-11-23T06:28:20Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:20Z WARN EXPERIMENTAL: The mongodb dbstats metricset is experimental  
2017-11-23T06:28:20Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:20Z DBG Remove module from stoplist: 765976364690901654  
2017-11-23T06:28:20Z DBG Add module to startlist: 765976364690901654  
2017-11-23T06:28:20Z INFO Stopping 0 runners ...  
2017-11-23T06:28:20Z INFO Starting 2 runners ...  
2017-11-23T06:28:20Z DBG New runner started: 1187029132801020061  
2017-11-23T06:28:20Z DBG New runner started: 765976364690901654  
2017-11-23T06:28:30Z DBG Scan for new config files  
2017-11-23T06:28:30Z DBG Load config from file: /etc/metricbeat/conf.d/all.yml  
2017-11-23T06:28:30Z DBG Load config from file: /etc/metricbeat/conf.d/mongodb.yml  
2017-11-23T06:28:30Z DBG Number of module configs found: 2  
2017-11-23T06:28:30Z DBG Remove module from stoplist: 1187029132801020061  
2017-11-23T06:28:30Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:30Z WARN EXPERIMENTAL: The mongodb dbstats metricset is experimental  
2017-11-23T06:28:30Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:30Z DBG Remove module from stoplist: 765976364690901654  
2017-11-23T06:28:30Z INFO Stopping 0 runners ...  
2017-11-23T06:28:30Z INFO Starting 0 runners ...  
2017-11-23T06:28:39Z INFO Non-zero metrics in the last 30s: fetches.mongodb-dbstats.events=10 fetches.mongodb-dbstats.success=2 fetches.mongodb-status.events=2 fetches.mongodb-status.success=2 fetches.system-cpu.events=2 fetches.system-cpu.success=2 fetches.system-diskio.events=6 fetches.system-diskio.success=2 fetches.system-filesystem.events=60 fetches.system-filesystem.success=2 fetches.system-load.events=2 fetches.system-load.success=2 fetches.system-memory.events=2 fetches.system-memory.success=2 fetches.system-network.events=4 fetches.system-network.success=2 fetches.system-process.events=260 fetches.system-process.success=2 libbeat.config.module.running=2 libbeat.config.module.starts=2 libbeat.config.reloads=2 libbeat.logstash.call\_count.PublishEvents=2 libbeat.logstash.publish.read\_bytes=12 libbeat.logstash.publish.write\_bytes=44662 libbeat.logstash.published\_and\_acked\_events=348 libbeat.publisher.messages\_in\_worker\_queues=348 libbeat.publisher.published\_events=348  
2017-11-23T06:28:40Z DBG Scan for new config files  
2017-11-23T06:28:40Z DBG Load config from file: /etc/metricbeat/conf.d/all.yml  
2017-11-23T06:28:40Z DBG Load config from file: /etc/metricbeat/conf.d/mongodb.yml  
2017-11-23T06:28:40Z DBG Number of module configs found: 2  
2017-11-23T06:28:40Z DBG Remove module from stoplist: 1187029132801020061  
2017-11-23T06:28:40Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:40Z WARN EXPERIMENTAL: The mongodb dbstats metricset is experimental  
2017-11-23T06:28:40Z INFO Connecting to MongoDB node at [127.0.0.1:27017]  
2017-11-23T06:28:40Z DBG Remove module from stoplist: 765976364690901654  
2017-11-23T06:28:40Z INFO Stopping 0 runners ...  
2017-11-23T06:28:40Z INFO Starting 0 runners ...  
2017-11-23T06:28:50Z DBG Scan for new config files  
...

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [November 26, 2017, 9:47pm UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/5 "2017-11-26T21:47:33Z")

</div>

This PR should potentially fix the leak: [https://github.com/elastic/beats/pull/5711](https://github.com/elastic/beats/pull/5711)

---

<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:** [December 24, 2017, 9:48pm UTC](https://discuss.elastic.co/t/metricbeat-mongodb-leaks-connections-when-metricbeat-config-modules-reload-enabled-set-to-true/108723/6 "2017-12-24T21:48:33Z")

</div>

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