db.enableFreeMonitoring()

  • db.enableFreeMonitoring()

New in version 4.0: Available for MongoDB Community Edition.

Enables free monitoring forstandalones and replica sets and returns the free monitoring status.s

Important

To run db.enableFreeMonitoring(), you must havespecified —enableFreeMonitoring command-line option orcloud.monitoring.free.state configuration file set toruntime.

Otherwise, you can only enable or disable at startup. See—enableFreeMonitoringcommand-line option or cloud.monitoring.free.state fordetails.

The db.enableFreeMonitoring() method is a wrapper aroundthe setFreeMonitoring command.

Behavior

Once enabled, the free monitoring state remains enabled untilexplicitly disabled. That is, you do not need to re-enable each timeyou start the server.

Once enabled, you are provided with a unique URL where you can accessyour monitored data.

When enabled, the monitored data is uploaded periodically. Themonitored data expires after 24 hours. That is, you can only accessmonitored data that has been uploaded within the past 24 hours.

For the frequency with which data is uploaded, seefreeMonitoring.retryIntervalSecs.

Access Control

When running with access control, the user must have thesetFreeMonitoring andcheckFreeMonitoringStatus privilege actions on thecluster. That is, a user must have arole that grants the following privilege:

  1. { resource: { cluster : true }, actions: [ "setFreeMonitoring" , "checkFreeMonitoringStatus"] }

The built-in role clusterMonitor role provides thisprivilege.

Example

To enable free monitoring, run the following from themongo shell:

  1. db.enableFreeMonitoring()

This starts the registration process for free monitoring. The methodreturns your free monitoring status:

  1. {
  2. "state" : "enabled",
  3. "message" : "To see your monitoring data, navigate to the unique URL below.\nAnyone you share the URL with will also be able to view this page.\n\nhttps://cloud.mongodb.com/freemonitoring/mongo/MSBjZTZhNTJmOS0yODg1\n\nYou can disable monitoring at any time by running db.disableFreeMonitoring().",
  4. "url" : "https://cloud.mongodb.com/freemonitoring/mongo/MSBjZTZhNTJmOS0yODg1",
  5. "userReminder" : "",
  6. "ok" : 1
  7. }

Tip

You can also use db.getFreeMonitoringStatus() any time tocheck your free monitoring status.

See also

db.disableFreeMonitoring()