Monitoring MongoDB
MongoDB is recognised by its mongod process and needs nothing from you on a server that
accepts local connections without authentication: the agent asks serverStatus through
the mongosh shell, checks the listening port and follows the server log. An instance with
authentication enabled is not covered by the stock definition (see Limitations).
How MongoDB is recognised
The signed definition matches a host that runs a process named mongod. Every minute the
agent:
- opens a TCP connection to the port that process listens on, so a non-default port passes the connection check without configuration;
- reads
/etc/mongod.conffor thepath:line of thesystemLogsection, which becomes the log path fact; - runs
mongosh --quiet --evalwith a short script that prints a projection ofdb.serverStatus(): current and available connections, the insert and query operation counters, resident memory, uptime and version, within a 20-second budget. The call carries no connection string, so it reaches the default local port with no credentials.
A companion definition for logs runs every 30 seconds.
What is collected
Connections. How many clients are connected now and how many more the server can still accept. The second number is the server's own countdown and drives the built-in alert.
Operations. The insert, query, update and delete counters since the server started, cumulative, and the per-second rate of each derived on the host between two readings. The rates are what you chart; the totals are what they come from.
Memory and uptime. Resident memory in megabytes and seconds since start.
Facts shown on the host page: version and the log path.
| Signal | Metric |
|---|---|
| Current and available connections | svc.mongo.connections, svc.mongo.connections_available |
| Operations since start | svc.mongo.opcounters_insert, svc.mongo.opcounters_query, svc.mongo.opcounters_update, svc.mongo.opcounters_delete |
| Operations per second | svc.mongo.insert_rate, svc.mongo.query_rate, svc.mongo.update_rate, svc.mongo.delete_rate |
| Resident memory | svc.mongo.mem_resident_mb |
| Uptime | svc.mongo.uptime |
Names and units are in the metrics reference.
Logs. The server log ships by default at notice level and above, from the journal
entries of mongod and from the file named in mongod.conf, where the level is read from
the severity field (s) of MongoDB's JSON log lines. See Logs.
Alerts out of the box
| Rule | Fires when | Severity | Ships |
|---|---|---|---|
| MongoDB is running out of connections | 500 or fewer connections available, held for 5 minutes | warning | on |
Available connections is the number MongoDB itself reports as still free, so the rule needs no knowledge of your configured maximum. Five hundred left, held for five minutes, clears the brief dips a deploy or a batch job causes and still leaves room to act before clients are refused. The incident closes only once 1000 connections are free again, so a server hovering near the edge does not flap. Thresholds and hysteresis are in the rules catalog.
When a path is not where MongoDB says it is
The log path comes from /etc/mongod.conf. To point the agent elsewhere:
sudo wakora --set mongo.log-path=/var/log/mongodb/mongod.log
Keys are listed in Agent configuration.
Limitations
- The stock definition sends no credentials. On an instance with authentication enabled the
serverStatusprobe fails; the connection check and the log collection still work. mongoshmust be installed on the host; the probe runs the shell, not a driver.- The status probe talks to the default local port. The connection check follows the discovered port, the status probe does not.
- Only the insert and query counters are collected; updates, deletes, replica set state and per-collection statistics are not.
- The log path is read from
/etc/mongod.confonly; a configuration elsewhere leaves the file side of log collection idle, the journal side still works.
FAQ
My mongod requires authentication. What do I get? The port check, the log collection
and the log path fact. The serverStatus probe reports a failed check because the stock
definition connects without credentials.