Watchlog DocsWatchlog Docs
Home
Get Started
Gen AI Monitoring
Integrations
Log Watchlist
Home
Get Started
Gen AI Monitoring
Integrations
Log Watchlist
  • All Integrations
  • NGINX

    • Nginx Integration
    • Connect NGINX to Watchlog
    • Docker
    • Windows
    • Kubernetes
    • Source Code
  • IIS

    • IIS Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • REDIS

    • Redis Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • POSTGRESQL

    • PostgreSQL Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • MONGODB

    • MongoDB Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • MYSQL

    • MySQL Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • PM2

    • PM2 Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • DOCKER

    • Docker Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code
  • GITLAB

    • Gitlab Integration
    • Ubuntu
    • Docker
    • Windows
    • Kubernetes
    • Source
  • ELASTICSEARCH

    • Elasticsearch Integration
    • Ubuntu
    • Docker Container
    • Windows
    • Kubernetes
    • Source Code

Source Code

  1. Go to your cloned repo:
    cd /path/to/watchlog-agent
    vim integration.json
    
  2. Locate the MongoDB config:

{ "service": "mongodb", "monitor": false, "host": "localhost", "port": "27017", "username": "", "password": "", "authDatabase": "admin", "tls": false }

3. Update `"monitor"` to `true` and set the credentials:
```diff
-  "monitor": false
+  "monitor": true

authDatabase is where the monitoring user is defined — usually admin. 4. Restart the agent:

pm2 restart watchlog-agent

Prerequisite

mongosh must be on PATH. The collection script uses the Promise-based shell API, which the legacy mongo shell does not provide — with only mongo available the agent falls back to the basic collector and the per-collection, index and slow-query tabs stay empty.

mongosh --version

Run the collector directly

Useful when you want the payload without waiting for the 60s tick:

node -e "
const list = require('./integration.json');
const cfg = list.find(i => i.service === 'mongodb');
require('./app/integrations/mongodb/index').collect(cfg, (err, res) => {
  if (err) return console.error('failed:', err.message);
  console.log('capabilities :', JSON.stringify(res.advanced.capabilities || {}));
  console.log('databases    :', (res.advanced.databases || []).length);
  console.log('collections  :', (res.advanced.collections || []).length);
  console.log('slow queries :', (res.advanced.slowQueries || []).length);
});
"

Running the tests

The MongoDB collector's parsers and shell-script builder are covered by the agent's test suite, which needs no live server:

npm test

Development notes

  • The advanced collector sits at app/integrations/mongodb/index.js; the legacy one is app/integrations/mongo.js beside it. Require the advanced one by its full path — require('./app/integrations/mongodb/index').
  • Both payloads come from one mongosh round-trip. The legacy event is emitted byte-for-byte as it always was, so existing dashboards keep working; the advanced event is additive.
  • mongosh is Promise-based, so a rejection escapes a synchronous try/catch and kills the script. Every safe() callback in evalScript.js must await inside it.
  • replSetGetStatus rejects normally on a standalone. That is not an error and must not be logged as one.
  • Arguments go through execFile, never a shell, so a password containing a quote or ; cannot break out into the command line. Keep it that way.
  • Storage and index traversal are throttled to 300s independently of the 60s tick. Walking every collection every minute is the main way a monitoring agent becomes the problem it was installed to detect.
Last Updated:: 8/13/26, 12:54 AM
Contributors: mohammad
Prev
Kubernetes