Skip to main content

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.conf for the path: line of the systemLog section, which becomes the log path fact;
  • runs mongosh --quiet --eval with a short script that prints a projection of db.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.

SignalMetric
Current and available connectionssvc.mongo.connections, svc.mongo.connections_available
Operations since startsvc.mongo.opcounters_insert, svc.mongo.opcounters_query, svc.mongo.opcounters_update, svc.mongo.opcounters_delete
Operations per secondsvc.mongo.insert_rate, svc.mongo.query_rate, svc.mongo.update_rate, svc.mongo.delete_rate
Resident memorysvc.mongo.mem_resident_mb
Uptimesvc.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​

RuleFires whenSeverityShips
MongoDB is running out of connections500 or fewer connections available, held for 5 minuteswarningon

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 serverStatus probe fails; the connection check and the log collection still work.
  • mongosh must 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.conf only; 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.