Source Code
- Go to your cloned repo:
cd /path/to/watchlog-agent vim integration.json - 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 isapp/integrations/mongo.jsbeside it. Require the advanced one by its full path —require('./app/integrations/mongodb/index'). - Both payloads come from one
mongoshround-trip. The legacy event is emitted byte-for-byte as it always was, so existing dashboards keep working; the advanced event is additive. mongoshis Promise-based, so a rejection escapes a synchronoustry/catchand kills the script. Everysafe()callback inevalScript.jsmustawaitinside it.replSetGetStatusrejects 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.
