
# MongoDB cluster by Zabbix agent 2

## Overview

The template to monitor MongoDB sharded cluster by Zabbix that work without any external scripts.
Most of the metrics are collected in one go, thanks to Zabbix bulk data collection.

`MongoDB cluster by Zabbix agent 2` — collects metrics from mongos proxy(router) by polling zabbix-agent2.

## Requirements

Zabbix version: 7.0 and higher.

## Tested versions

This template has been tested on:
- MongoDB 4.0.21, 4.4.3

## Configuration

> Zabbix should be configured according to the instructions in the [Templates out of the box](https://www.zabbix.com/documentation/7.0/manual/config/templates_out_of_the_box) section.

## Setup

1. Setup and configure zabbix-agent2 compiled with the MongoDB monitoring plugin.
2. Set the {$MONGODB.CONNSTRING} such as <protocol(host:port)> or named session of mongos proxy(router).
3. Set the user name and password in host macros ({$MONGODB.USER}, {$MONGODB.PASSWORD}) if you want to override parameters from the Zabbix agent configuration file.

**Note**, depending on the number of DBs and collections discovery operation may be expensive. Use filters with macros {$MONGODB.LLD.FILTER.DB.MATCHES}, {$MONGODB.LLD.FILTER.DB.NOT_MATCHES}, {$MONGODB.LLD.FILTER.COLLECTION.MATCHES}, {$MONGODB.LLD.FILTER.COLLECTION.NOT_MATCHES}.

All sharded Mongodb nodes (mongod) will be discovered with attached template "MongoDB node by Zabbix agent 2".


Test availability: `zabbix_get -s mongos.node -k 'mongodb.ping["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]"`

### Macros used

|Name|Description|Default|
|----|-----------|-------|
|{$MONGODB.CONNSTRING}|
Connection string in the URI format (password is not used). This param overwrites a value configured in the "Server" option of the configuration file (if it's set), otherwise, the plugin's default value is used: "tcp://localhost:27017"
|`tcp://localhost:27017`|
|{$MONGODB.USER}|
MongoDB username
||
|{$MONGODB.PASSWORD}|
MongoDB user password
||
|{$MONGODB.CONNS.AVAILABLE.MIN.WARN}|
Minimum number of available connections
|`1000`|
|{$MONGODB.LLD.FILTER.COLLECTION.MATCHES}|
Filter of discoverable collections
|`.*`|
|{$MONGODB.LLD.FILTER.COLLECTION.NOT_MATCHES}|
Filter to exclude discovered collections
|`CHANGE_IF_NEEDED`|
|{$MONGODB.LLD.FILTER.DB.MATCHES}|
Filter of discoverable databases
|`.*`|
|{$MONGODB.LLD.FILTER.DB.NOT_MATCHES}|
Filter to exclude discovered databases
|`(admin\|config\|local)`|
|{$MONGODB.CURSOR.TIMEOUT.MAX.WARN}|
Maximum number of cursors timing out per second
|`1`|
|{$MONGODB.CURSOR.OPEN.MAX.WARN}|
Maximum number of open cursors
|`10000`|

### Items

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Get server status|
The mongos statistic
|Zabbix agent|mongodb.server.status["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|
|Get mongodb.connpool.stats|
Returns current info about connpool.stats.
|Zabbix agent|mongodb.connpool.stats["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|
|Ping|
Test if a connection is alive or not.
|Zabbix agent|mongodb.ping["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]
**Preprocessing**

- 
Discard unchanged with heartbeat: `30m`

|
|Jumbo chunks|
Total number of 'jumbo' chunks in the mongo cluster.
|Zabbix agent|mongodb.jumbo_chunks.count["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|
|Mongos version|
Version of the Mongos server
|Dependent item|mongodb.version
**Preprocessing**

- 
JSON Path: `$.version`

- 
Discard unchanged with heartbeat: `3h`

|
|Uptime|
Number of seconds since the Mongos server start.
|Dependent item|mongodb.uptime
**Preprocessing**

- 
JSON Path: `$.uptime`

|
|Operations: command|
The number of commands issued to the database per second.

Counts all commands except the write commands: insert, update, and delete.
|Dependent item|mongodb.opcounters.command.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.command`

- Change per second
|
|Operations: delete|
The number of delete operations the mongos instance per second.
|Dependent item|mongodb.opcounters.delete.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.delete`

- Change per second
|
|Operations: update, rate|
The number of update operations the mongos instance per second.
|Dependent item|mongodb.opcounters.update.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.update`

- Change per second
|
|Operations: query, rate|
The number of queries received the mongos instance per second.
|Dependent item|mongodb.opcounters.query.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.query`

- Change per second
|
|Operations: insert, rate|
The number of insert operations received the mongos instance per second.
|Dependent item|mongodb.opcounters.insert.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.insert`

- Change per second
|
|Operations: getmore, rate|
The number of "getmore" operations the mongos per second. This counter can be high even if the query count is low.

Secondary nodes send getMore operations as part of the replication process.
|Dependent item|mongodb.opcounters.getmore.rate
**Preprocessing**

- 
JSON Path: `$.opcounters.getmore`

- Change per second
|
|Last seen configserver|
The latest optime of the CSRS primary that the mongos has seen.
|Dependent item|mongodb.last_seen_config_server
**Preprocessing**

- 
JSON Path: `$.sharding.lastSeenConfigServerOpTime.ts.T`

|
|Configserver heartbeat|
Difference between the latest optime of the CSRS primary that the mongos has seen and cluster time.
|Dependent item|mongodb.config_server_heartbeat
**Preprocessing**

- 
JavaScript: `The text is too long. Please see the template.`

|
|Bytes in, rate|
The total number of bytes that the server has received over network connections initiated by clients or other mongod/mongos instances per second.
|Dependent item|mongodb.network.bytes_in.rate
**Preprocessing**

- 
JSON Path: `$.network.bytesIn`

- Change per second
|
|Bytes out, rate|
The total number of bytes that the server has sent over network connections initiated by clients or other mongod/mongos instances per second.
|Dependent item|mongodb.network.bytes_out.rate
**Preprocessing**

- 
JSON Path: `$.network.bytesOut`

- Change per second
|
|Requests, rate|
Number of distinct requests that the server has received per second.
|Dependent item|mongodb.network.numRequests.rate
**Preprocessing**

- 
JSON Path: `$.network.numRequests`

- Change per second
|
|Connections, current|
The number of incoming connections from clients to the database server.

This number includes the current shell session.
|Dependent item|mongodb.connections.current
**Preprocessing**

- 
JSON Path: `$.connections.current`

|
|New connections, rate|
"Rate of all incoming connections created to the server."
|Dependent item|mongodb.connections.rate
**Preprocessing**

- 
JSON Path: `$.connections.totalCreated`

- Change per second
|
|Connections, active|
The number of active client connections to the server.

Active client connections refers to client connections that currently have operations in progress.

Available starting in  4.0.7, 0 for older versions.
|Dependent item|mongodb.connections.active
**Preprocessing**

- 
JSON Path: `$.connections.active`

⛔️Custom on fail: Set value to: `0`

|
|Connections, available|
"The number of unused incoming connections available."
|Dependent item|mongodb.connections.available
**Preprocessing**

- 
JSON Path: `$.connections.available`

|
|Connection pool: client connections|
The number of active and stored outgoing synchronous connections from the current mongos instance to other members of the sharded cluster.
|Dependent item|mongodb.connection_pool.client
**Preprocessing**

- 
JSON Path: `$.numClientConnections`

|
|Connection pool: scoped|
Number of active and stored outgoing scoped synchronous connections from the current mongos instance to other members of the sharded cluster.
|Dependent item|mongodb.connection_pool.scoped
**Preprocessing**

- 
JSON Path: `$.numAScopedConnections`

|
|Connection pool: created, rate|
The total number of outgoing connections created per second by the current mongos instance to other members of the sharded cluster.
|Dependent item|mongodb.connection_pool.created.rate
**Preprocessing**

- 
JSON Path: `$.totalCreated`

- Change per second
|
|Connection pool: available|
The total number of available outgoing connections from the current mongos instance to other members of the sharded cluster.
|Dependent item|mongodb.connection_pool.available
**Preprocessing**

- 
JSON Path: `$.totalAvailable`

|
|Connection pool: in use|
Reports the total number of outgoing connections from the current mongos instance to other members of the sharded cluster set that are currently in use.
|Dependent item|mongodb.connection_pool.in_use
**Preprocessing**

- 
JSON Path: `$.totalInUse`

|
|Connection pool: refreshing|
Reports the total number of outgoing connections from the current mongos instance to other members of the sharded cluster that are currently being refreshed.
|Dependent item|mongodb.connection_pool.refreshing
**Preprocessing**

- 
JSON Path: `$.totalRefreshing`

|
|Cursor: open no timeout|
Number of open cursors with the option DBQuery.Option.noTimeout set to prevent timeout after a period of inactivity.
|Dependent item|mongodb.metrics.cursor.open.no_timeout
**Preprocessing**

- 
JSON Path: `$.metrics.cursor.open.noTimeout`

⛔️Custom on fail: Discard value

|
|Cursor: open pinned|
Number of pinned open cursors.
|Dependent item|mongodb.cursor.open.pinned
**Preprocessing**

- 
JSON Path: `$.metrics.cursor.open.pinned`

|
|Cursor: open total|
Number of cursors that MongoDB is maintaining for clients.
|Dependent item|mongodb.cursor.open.total
**Preprocessing**

- 
JSON Path: `$.metrics.cursor.open.total`

|
|Cursor: timed out, rate|
Number of cursors that time out, per second.
|Dependent item|mongodb.cursor.timed_out.rate
**Preprocessing**

- 
JSON Path: `$.metrics.cursor.timedOut`

- Change per second
|
|Architecture|
A number, either 64 or 32, that indicates whether the MongoDB instance is compiled for 64-bit or 32-bit architecture.
|Dependent item|mongodb.mem.bits
**Preprocessing**

- 
JSON Path: `$.mem.bits`

- 
Discard unchanged with heartbeat: `3h`

|
|Memory: resident|
Amount of memory currently used by the database process.
|Dependent item|mongodb.mem.resident
**Preprocessing**

- 
JSON Path: `$.mem.resident`

- 
Custom multiplier: `1048576`

|
|Memory: virtual|
Amount of virtual memory used by the mongos process.
|Dependent item|mongodb.mem.virtual
**Preprocessing**

- 
JSON Path: `$.mem.virtual`

- 
Custom multiplier: `1048576`

|

### Triggers

|Name|Description|Expression|Severity|Dependencies and additional info|
|----|-----------|----------|--------|--------------------------------|
|MongoDB cluster: Connection to mongos proxy is unavailable|
Connection to mongos proxy instance is currently unavailable.
|`last(/MongoDB cluster by Zabbix agent 2/mongodb.ping["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"])=0`|High||
|MongoDB cluster: Version has changed|
MongoDB cluster version has changed. Acknowledge to close the problem manually.
|`last(/MongoDB cluster by Zabbix agent 2/mongodb.version,#1)<>last(/MongoDB cluster by Zabbix agent 2/mongodb.version,#2) and length(last(/MongoDB cluster by Zabbix agent 2/mongodb.version))>0`|Info|**Manual close**: Yes|
|MongoDB cluster: Mongos server has been restarted|
Uptime is less than 10 minutes.
|`last(/MongoDB cluster by Zabbix agent 2/mongodb.uptime)<10m`|Info|**Manual close**: Yes|
|MongoDB cluster: Failed to fetch info data|
Zabbix has not received data for items for the last 10 minutes
|`nodata(/MongoDB cluster by Zabbix agent 2/mongodb.uptime,10m)=1`|Warning|**Manual close**: Yes
**Depends on**:

- MongoDB cluster: Connection to mongos proxy is unavailable
|
|MongoDB cluster: Available connections is low|
Too few available connections.
Consider this value in combination with the value of connections current to understand the connection load on the database.
|`max(/MongoDB cluster by Zabbix agent 2/mongodb.connections.available,5m)<{$MONGODB.CONNS.AVAILABLE.MIN.WARN}`|Warning||
|MongoDB cluster: Too many cursors opened by MongoDB for clients||`min(/MongoDB cluster by Zabbix agent 2/mongodb.cursor.open.total,5m)>{$MONGODB.CURSOR.OPEN.MAX.WARN}`|Warning||
|MongoDB cluster: Too many cursors are timing out||`min(/MongoDB cluster by Zabbix agent 2/mongodb.cursor.timed_out.rate,5m)>{$MONGODB.CURSOR.TIMEOUT.MAX.WARN}`|Warning||

### LLD rule Database discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Database discovery|
Collect database metrics.

Note, depending on the number of DBs this discovery operation may be expensive. Use filters with macros {$MONGODB.LLD.FILTER.DB.MATCHES}, {$MONGODB.LLD.FILTER.DB.NOT_MATCHES}.
|Zabbix agent|mongodb.db.discovery["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|

### Item prototypes for Database discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|MongoDB {#DBNAME}: Get db stats {#DBNAME}|
Returns statistics reflecting the database system's state.
|Zabbix agent|mongodb.db.stats["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}","{#DBNAME}"]|
|MongoDB {#DBNAME}: Objects, avg size|
The average size of each document in bytes.
|Dependent item|mongodb.db.size["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.avgObjSize`

|
|MongoDB {#DBNAME}: Size, data|
Total size of the data held in this database including the padding factor.
|Dependent item|mongodb.db.data_size["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.dataSize`

|
|MongoDB {#DBNAME}: Size, file|
Total size of the data held in this database including the padding factor (only available with the mmapv1 storage engine).
|Dependent item|mongodb.db.file_size["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.fileSize`

⛔️Custom on fail: Discard value

|
|MongoDB {#DBNAME}: Size, index|
Total size of all indexes created on this database.
|Dependent item|mongodb.db.index_size["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.indexSize`

|
|MongoDB {#DBNAME}: Size, storage|
Total amount of space allocated to collections in this database for document storage.
|Dependent item|mongodb.db.storage_size["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.storageSize`

|
|MongoDB {#DBNAME}: Objects, count|
Number of objects (documents) in the database across all collections.
|Dependent item|mongodb.db.objects["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.objects`

|
|MongoDB {#DBNAME}: Extents|
Contains a count of the number of extents in the database across all collections.
|Dependent item|mongodb.db.extents["{#DBNAME}"]
**Preprocessing**

- 
JSON Path: `$.numExtents`

⛔️Custom on fail: Discard value

|

### LLD rule Collection discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Collection discovery|
Collect collections metrics.

Note, depending on the number of DBs and collections this discovery operation may be expensive. Use filters with macros {$MONGODB.LLD.FILTER.DB.MATCHES}, {$MONGODB.LLD.FILTER.DB.NOT_MATCHES}, {$MONGODB.LLD.FILTER.COLLECTION.MATCHES}, {$MONGODB.LLD.FILTER.COLLECTION.NOT_MATCHES}.
|Zabbix agent|mongodb.collections.discovery["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|

### Item prototypes for Collection discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|MongoDB {#DBNAME}.{#COLLECTION}: Get collection stats {#DBNAME}.{#COLLECTION}|
Returns a variety of storage statistics for a given collection.
|Zabbix agent|mongodb.collection.stats["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}","{#DBNAME}","{#COLLECTION}"]|
|MongoDB {#DBNAME}.{#COLLECTION}: Size|
The total size in bytes of the data in the collection plus the size of every indexes on the mongodb.collection.
|Dependent item|mongodb.collection.size["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.size`

|
|MongoDB {#DBNAME}.{#COLLECTION}: Objects, avg size|
The size of the average object in the collection in bytes.
|Dependent item|mongodb.collection.avg_obj_size["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.avgObjSize`

⛔️Custom on fail: Discard value

|
|MongoDB {#DBNAME}.{#COLLECTION}: Objects, count|
Total number of objects in the collection.
|Dependent item|mongodb.collection.count["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.count`

|
|MongoDB {#DBNAME}.{#COLLECTION}: Capped, max number|
Maximum number of documents in a capped collection.
|Dependent item|mongodb.collection.max["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.max`

⛔️Custom on fail: Discard value

|
|MongoDB {#DBNAME}.{#COLLECTION}: Capped, max size|
Maximum size of a capped collection in bytes.
|Dependent item|mongodb.collection.max_size["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.maxSize`

⛔️Custom on fail: Discard value

|
|MongoDB {#DBNAME}.{#COLLECTION}: Storage size|
Total storage space allocated to this collection for document storage.
|Dependent item|mongodb.collection.storage_size["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.storageSize`

|
|MongoDB {#DBNAME}.{#COLLECTION}: Indexes|
Total number of indices on the collection.
|Dependent item|mongodb.collection.nindexes["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.nindexes`

|
|MongoDB {#DBNAME}.{#COLLECTION}: Capped|
Whether or not the collection is capped.
|Dependent item|mongodb.collection.capped["{#DBNAME}","{#COLLECTION}"]
**Preprocessing**

- 
JSON Path: `$.capped`

- Boolean to decimal
- 
Discard unchanged with heartbeat: `3h`

|

### LLD rule Shards discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Shards discovery|
Discovery shared cluster hosts.
|Zabbix agent|mongodb.sh.discovery["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|

### LLD rule Config servers discovery

|Name|Description|Type|Key and additional info|
|----|-----------|----|-----------------------|
|Config servers discovery|
Discovery shared cluster config servers.
|Zabbix agent|mongodb.cfg.discovery["{$MONGODB.CONNSTRING}","{$MONGODB.USER}","{$MONGODB.PASSWORD}"]|

## Feedback

Please report any issues with the template at [`https://support.zabbix.com`](https://support.zabbix.com)

You can also provide feedback, discuss the template, or ask for help at [`ZABBIX forums`](https://www.zabbix.com/forum/zabbix-suggestions-and-feedback)

