# Mongo DB y Mongo DB atlas

# Introducción

**Ver**. 25-08-2021  
  
Con este plug-in podremos ver los stats de una base de datos y de sus colecciones, soporta compatibilidad con Mongo DB atlas

<div id="bkmrk-tipo%3A-plug-in-de-ser"><div>**Tipo**: Plug-in de servidor o agente</div></div>

# Matriz de compatibilidad

<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: 30.1796%; height: 28px;">**Sistemas donde se ha probado**</td><td style="width: 69.9327%; height: 28px;">CentOS 7, Fedora

</td></tr><tr style="height: 28px;"><td style="width: 30.1796%; height: 28px;">**Sistemas donde debería funcionar**</td><td style="width: 69.9327%; height: 28px;">Cualquier sistema linux

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

# Pre requisitos

Se requiere:

- Una base de datos Mongo DB o Mongo DB atlas
- Tener el **Data Server** de Pandora FMS habilitado
- Tener el **Plugin Server** de Pandora FMS habilitado

# Configuración

Para el uso del plugin será necesario tener instalado una serie de dependencias.

Lo primero es tener instalado python 3

```
yum install python3
```

El plugin viene con un archivo llamado requirements.txt que instalará las otras dependencias necesarias. Para ejecutarlo usaremos:

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

No obstante, si quieres instalar sus dependencias sin el archivo requirements, puedes usar los siguientes comandos (recomendado si no usas una base de datos Mongo DB atlas)

**PyMongo**

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

o con el siguiente comando si python 3 no es tu versión de python por defecto:

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

**dnspython**

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

o con el siguiente comando si python 3 no es tu versión de python por defecto:

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

*nota: dnspython solo es imprescindible si usas una base de datos MongoDB atlas.*

Para conectarte, necesitas conocer tu ip o uri de conexión. Si te has montado la base de datos en docker puedes verlo con :

```
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)

El puerto por defecto suele ser 27017. Por ejemplo con esta ip la url de conexión sería :

mongodb://172.17.0.2:27017

Para MongoDB atlas, necesitaremos la cadena de conexión, esta se obtiene haciendo lo siguiente.

Vamos a 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)

Nos saldrán varias opciones para conectarnos:  
  
[![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)

Yo por ejemplo, he optado por MongoDB compass, al darle, nos mostrará la cadena de conexión, si es que ya lo hemos instalado, o nos dará la opción de instalarlo.

[![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)

Esa sería la cadena de conexión, obviamente habría que cambiar &lt;password&gt; por tu contraseña.

# Parámetros generales del plugin

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

Si la ejecución es correcta veremos un número entero, que sera el numero de base de datos que tengamos.

[![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)

Si queremos ejecutarlo como plugin de agente lo haremos usando el parámetro opcional "as\_agent\_plugin" con un "1" que nos devolverá un xml con los datos de nuestro servidor :

[![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)

Esto solo funcionará si metes una única base de datos con el parámetro -d , no funcionara con -a que es el parámetro para todas las bases de datos.

# Parámetros específicos del plugin

El plug-in contiene los siguientes parámetros:

<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;">**Parámetros**</td><td style="width: 50%; height: 29px;">**Descripción**</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;">La uri de conexión (obligatorio)</td></tr><tr><td style="width: 50%;">-s &lt;server&gt; --server &lt;server&gt;</td><td style="width: 50%;">Para obtener estadísticas del servidor (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;">Para obtener los stats de una base de datos, la que tiene el nombre que ingresas.</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;">Para coger los stats de todas las bases de datos, se activa con 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;">Para poner un nombre en los agentes (opcional)</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;">Para activar los stats de las colecciones de la base de datos, se activa con 1 (opcional)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">-g GROUP, --group GROUP</td><td style="width: 50%; height: 29px;">Grupo de destino de Pandora FMS (opcional)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">--data\_dir DATA\_DIR</td><td style="width: 50%; height: 29px;">Directorio de datos de Pandora FMS. **Por defecto** es /var/spool/pandora/data\_in/ (opcional)</td></tr><tr style="height: 29px;"><td style="width: 50%; height: 29px;">--as\_agent\_plugin</td><td style="width: 50%; height: 29px;">Es opcional, si quieres que el plugin sea de agente y te meta los módulos en el agente de pandora, ejecuta esto con un 1 (opcional)</td></tr></tbody></table>

Ejemplo de ayuda:

```
./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)

# Ejecución manual

Podemos comprobar el plugin desde el terminal para ver si funciona, para comprobarlo, ejecutamos el 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)

Con 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)

Ejemplo de ejecución con ayuda:

[![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)

# Configuración en pandora

**Instalación desde consola**

Para el registro del plugin, desde la consola, se debe ir al apartado "registrar plugin".

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

Daremos a seleccionar archivo.

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

Seleccionaremos el fichero pspz2 que contiene el 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)

Una vez subido se podrá ver un mensaje indicando que esta registrado correctamente.

[![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)

Una vez registrado el plugin, lo veremos en el apartado 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)

En el apartado parámetros veremos todos los que usa el plugin, no todos son imprescindibles para su funcionamiento, solo los que salen como obligatorios en parámetros.

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

En el apartado de abajo veremos todos los parámetros utilizados y se les podrá asignar el valor requerido.

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

**Instalación manual**

La mejor forma de manejar plugins de servidor en Pandora es desde "/usr/share/pandora\_server/util/plugin" asi que lo enviaremos esa ruta.

Después nos moveremos a la carpeta en la que lo hemos metido ( "/usr/share/pandora\_server/util/plugin" es la recomendada").

**Recuerda: Tienes que instalar las dependencias que necesita el módulo PyMongo en tu sistema, esta explicado en el apartado configuración.**

<div id="bkmrk-nos-movemos-desde-ho"><div>Nos movemos desde home con :</div></div><div id="bkmrk--7"></div>```
cd /usr/share/pandora_server/util/plugin/
```

Ejecutamos el plugin para ver que funciona :

```
./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)

Con as\_agent\_plugin 1 podremos ver un XML con los datos que nos saldrán en consola:

[![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)

Si lo ejecutamos de la primera manera, sin "as\_agent\_plugin 1" se nos habrá creado un agente por cada database de nuestro cluster. El parámetro --as\_agent\_plugin solo podremos ejecutarlo si metemos las bases de datos una a una introduciendo su nombre con el parámetro -d.

De todas formas, por si se prefiere instalarlo manualmente desde la consola, el proceso sería el siguiente:

**Como plugin de servidor**

Iremos a servidores &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)

Pinchamos en añadir:

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

Le ponemos en nombre y la descripción que se prefiera:

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

Metemos como comando la ruta al plugin, y como parámetros los que hemos metido ejecutando el plugin, los campos "\_field\_" son macros definidas más abajo.

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

Ponemos por cada macro la descripción que se prefiera y como valor los datos de mongodb.

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

Hecho esto si ejecutamos el plugin desde el terminal se nos habrá creado el agente con los módulos.

# Modulos generados

Se nos creara un agente por cada database de nuestro cluster con datos de los stats de las databases y de las colecciones y otro agente con módulos con los datos del server.

**Módulos database**

<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;">**Nombre módulo** </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>

**Módulos colecciones**

<table border="1" id="bkmrk-nombre-m%C3%B3dulo-size-c" style="border-collapse: collapse; width: 50.1235%;"><tbody><tr><td style="width: 100%;">**Nombre módulo**</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>

**Módulos server :**

<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-/modulos-database-collections.png)](https://pandorafms.com/guides/public/uploads/images/gallery/2021-08/modulos-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)