# Mongo DB and Mongo DB atlas

# Introduction

**Ver**. 25-08-2021  
  
With this plug-in you can view the stats of a database and its collections, it supports Mongo DB atlas compatibility.

<div id="bkmrk-tipo%3A-server-plugin"><div>**Tipo**: Server or agent plug-in</div></div>

# Compatibility matrix

<table border="1" id="bkmrk-sistemas-donde-se-ha" style="border-collapse: collapse; width: 100%; height: 84px;"><tbody><tr style="height: 28px;"><td style="width: 29.8093%; height: 28px;">**Systems where it has been tested**</td><td style="width: 70.3031%; height: 28px;">CentOS 7, Fedora

</td></tr><tr style="height: 28px;"><td style="width: 29.8093%; height: 28px;">**Systems where it should work**</td><td style="width: 70.3031%; height: 28px;">Any linux system

</td></tr></tbody></table>

# Prerequisites

Requires:

- A Mongo DB or Mongo DB atlas database
- Have Pandora FMS **Data Server** enabled.
- Have Pandora FMS **Plugin Server** enabled.

# Configuration

To use the plugin you will need to have a number of dependencies installed.

The first thing is to have python 3 installed

```
yum install python3
```

The plugin comes with a file called requirements.txt that will install the other necessary dependencies. To run it we will use:

```
pip3 install -r requirements.txt
```

However, if you want to install its dependencies without the requirements file, you can use the following commands (recommended if you don't use a Mongo DB atlas database)

**PyMongo**

```
python -m pip install pymongo
```

or with the following command if Python 3 is not your default Python version:

```bash
python3 -m pip install pymongo
```

**dnspython**

```
python -m pip install dnspython
```

or with the following command if Python 3 is not your default Python version:

```bash
python3 -m pip install pymongo
```

*note: dnspython is only required if you use a MongoDB atlas database.*

To connect, you need to know your connection ip or uri. If you have set up the database in docker you can see it with :

```
docker inspect <id-contenedor>
```

[![image-1629969157626.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629969157626.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629969157626.png)

The default port is usually 27017. For example with this ip the connection url would be :

mongodb://172.17.0.2:27017

  
For MongoDB atlas, we will need the connection string, this is obtained by doing the following.

Let's go to connect:

[![1.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/1.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/1.png)

We will be presented with several options to connect:  
  
[![2.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/2.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/2.png)

For example, I have chosen MongoDB compass, and when I click on it, it will show us the connection string, if we have already installed it, or it will give us the option to install it.

[![3.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/3.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/3.png)

That would be the connection string, obviously you would have to change &lt;password&gt; to your password.

# General parameters

Execution command:

```
python pandora_mongodb -u <uri> -s <server> -d <databases> -a <alldatabases> -p <prefix> -c <collectionstats> [ -g <group> ] [ --data_dir <data dir> ] [ --as_agent_plugin 1]
```

If the execution is successful we will see an integer, which will be the database number we have.

[![4.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/4.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/4.png)

If we want to run it as an agent plugin, we will do it using the optional parameter "as\_agent\_plugin" with a "1" which will return an xml with the data of our server:

[![5.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/5.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/5.png)

This will only work if you put a single database with the -d parameter, it will not work with -a which is the parameter for all databases.

# Specific parameters

The plug-in has the following parameters:

<table border="1" id="bkmrk-par%C3%A1metro-descripci%C3%B3" style="border-collapse: collapse; width: 100%; height: 260px;"><tbody><tr style="height: 29px;"><td style="width: 50%; height: 29px;">**Parameter**</td><td style="width: 50%; height: 29px;">**Description**</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-u &lt;uri&gt; --u &lt;uri&gt;</td><td style="width: 50%; height: 29px;">The connection uri (mandatory)</td></tr><tr><td style="width: 50%;">-s &lt;server&gt; --server &lt;server&gt;</td><td style="width: 50%;">To get server stats (cluster)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-d &lt;name\_database&gt; --databases &lt;name\_database&gt;</td><td style="width: 50%; height: 29px;">To get statistics from a database, the one with the name you enter.

</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-a &lt;1&gt; --alldatabases &lt;1&gt;</td><td style="width: 50%; height: 29px;">To get the stats from all databases, it is activated with 1</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-p &lt;prefix&gt; --prefix &lt;prefix&gt;</td><td style="width: 50%; height: 29px;">To name the agents (optional)</td></tr><tr style="height: 28px;"><td style="width: 50%; height: 28px;">-c &lt;1&gt; --collectionstats &lt;1&gt;</td><td style="width: 50%; height: 28px;">To activate the stats of the collections in the database, activate with 1 (optional).</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-g GROUP, --group GROUP</td><td style="width: 50%; height: 29px;">Pandora FMS target group (optional)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">--data\_dir DATA\_DIR</td><td style="width: 50%; height: 29px;">Pandora FMS data directory. By default it is /var/spool/pandora/data\_in/ (optional)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">--as\_agent\_plugin</td><td style="width: 50%; height: 29px;">It's optional, if you want the plugin to be an agent plugin and put the modules in the pandora agent, execute this with a 1 (optional)</td></tr></tbody></table>

Help example:

```bash
./pandora_mongodb
```

[![6.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/6.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/6.png)

# Manual execution

We can test the plugin from the terminal to see if it works, to check it, we run the plugin:

[![image-1629973021245.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629973021245.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629973021245.png)

With as\_agent\_plugin:

[![image-1629973734411.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629973734411.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629973734411.png)

Example of implementation with assistance:

[![image-1629973766276.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629973766276.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629973766276.png)

# Configuration in Pandora

**Installation from the console**

To register the plugin, from the console, go to the "register plugin" section.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/9UOimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/9UOimage.png)

Click on select file.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/84wimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/84wimage.png)

Select the pspz2 file containing the plugin.

[![register1_mongodb.png](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/scaled-1680-/register1-mongodb.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register1-mongodb.png)

Once uploaded you will see a message indicating that it has been successfully registered.

[![register2_mongodb.png](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/scaled-1680-/register2-mongodb.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2022-04/register2-mongodb.png)

Once the plugin is registered, we will see it in the plugins section.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/Eh6image.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/Eh6image.png)

In the parameters section we will see all the parameters used by the plugin, not all of them are essential for its operation, only those that are mandatory in parameters.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/TvKimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/TvKimage.png)

In the section below you will see all the parameters used and you will be able to assign them the required value.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/9Wlimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/9Wlimage.png)

**Manual installation**

The best way to manage server plugins in Pandora is from "/usr/share/pandora\_server/util/plugin" so we will send it to that path.

Then we will move to the folder where we have put it ("/usr/share/pandora\_server/util/plugin" is the recommended one").

**Remember: You have to install the dependencies that the PyMongo module needs in your system, this is explained in the configuration section.**

We move from home with :

<div id="bkmrk--7" style="text-align: justify;"></div>```
cd /usr/share/pandora_server/util/plugin/
```

We run the plugin to see that it works:

```
python pandora_mongodb -u <uri> -s <server> -d <databases> -a <alldatabases> -p <prefix> -c <collectionstats> [ -g <group> ] [ --data_dir <data dir> ] [ --as_agent_plugin 1]
```

[![image-1629974206435.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629974206435.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629974206435.png)

With as\_agent\_plugin 1 we will be able to see an XML with the data that will be displayed in the console:

[![image-1629974241455.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/image-1629974241455.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/image-1629974241455.png)

If we execute it in the first way, without "as\_agent\_plugin 1", we will have created an agent for each database of our cluster. The --as\_agent\_plugin parameter can only be executed if we insert the databases one by one, introducing their name with the -d parameter.

Anyway, if you prefer to install it manually from the console, the process would be the following:

**As a server plugin**

Go to servers &gt; plugins:

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/pI0image.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/pI0image.png)

Click on add:

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/Snrimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/Snrimage.png)

We put in the name and description of your choice:

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/aPWimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/aPWimage.png)

We enter as command the path to the plugin, and as parameters the ones we have entered by executing the plugin, the "\_field\_" fields are macros defined below.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/AEqimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/AEqimage.png)

We put for each macro the description of your choice and as value the data of your ldap server.

[![image.png](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/scaled-1680-/Yimimage.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2025-08/Yimimage.png)

Once this is done, if we execute the plugin from the terminal, the agent with the modules will have been created.

# Modules generated

An agent will be created for each database of our cluster with data of the stats of the databases and the collections. And other agent with modules with the data of the server (cluster)

**Database modules**

<table border="1" id="bkmrk-nombre-m%C3%B3dulo%C2%A0-colle" style="border-collapse: collapse; width: 50.1235%; height: 203px;"><tbody><tr style="height: 29px;"><td style="width: 100%; height: 29px;">**Module name**</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">collections</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">views</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">objects</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;"><div><div>avgObjSize</div></div></td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">datasize</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">storagesize</td></tr></tbody></table>

<table border="1" id="bkmrk-totalfreestoragesize" style="border-collapse: collapse; width: 50.1235%; height: 203px;"><tbody><tr style="height: 29px;"><td style="width: 100%; height: 29px;">totalfreestoragesize</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">numextents</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">indexes</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">indexsize</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">filesize</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">nssizemb</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">status</td></tr></tbody></table>

**Collection modules**

<table border="1" id="bkmrk-nombre-m%C3%B3dulo-size-c" style="border-collapse: collapse; width: 50.1235%;"><tbody><tr><td style="width: 100%;">**Module name**</td></tr><tr><td style="width: 100%;">size</td></tr><tr><td style="width: 100%;">count</td></tr><tr><td style="width: 100%;">avgobjsize</td></tr><tr><td style="width: 100%;">storagesize</td></tr><tr><td style="width: 100%;">freestoragesize</td></tr></tbody></table>

<table border="1" id="bkmrk-capped-nindexes-tota" style="border-collapse: collapse; width: 50.245%; height: 174px;"><tbody><tr style="height: 29px;"><td style="width: 100%; height: 29px;">capped</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">nindexes</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">totalindexsizes</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">totalsizes</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">scalefactor</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">status</td></tr></tbody></table>

**Server modules :**

<table border="1" id="bkmrk-connections-current-" style="border-collapse: collapse; width: 50.7407%; height: 290px;"><tbody><tr style="height: 29px;"><td style="width: 100%; height: 29px;">connections current</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">connections avalaible</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">connections total created</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">network bytes in</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">network bytes out</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">network num requests</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations insert</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations query</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations update</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations delete</td></tr></tbody></table>

<table border="1" id="bkmrk-operations-get-more-" style="border-collapse: collapse; width: 50.4938%; height: 232px;"><tbody><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations get more</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">operations command</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">writes latency</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">writes ops</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">reads latency</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">reads ops</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">commands latency</td></tr><tr style="height: 29px;"><td style="width: 100%; height: 29px;">commands ops</td></tr></tbody></table>

[![modulos database collections.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/VHKmodulos-database-collections.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/VHKmodulos-database-collections.png)

[![modulos server status.png](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/scaled-1680-/modulos-server-status.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/modulos-server-status.png)