Docs HomeMongoDB Manual

db.enableFreeMonitoring()

db.enableFreeMonitoring()

Enables free monitoring for standalones and replica sets and returns the free monitoring status.s允许对单机集和复制副本集进行免费监视,并返回免费监视状态

Important

To run db.enableFreeMonitoring(), you must have specified --enableFreeMonitoring command-line option or cloud.monitoring.free.state configuration file set to runtime.若要运行db.enableFreeMonitoring(),必须指定--enableFreeMonitoring命令行选项或cloud.monitoring.free.state配置文件设置为runtime

Otherwise, you can only enable or disable at startup. 否则,您只能在启动时启用或禁用。See --enableFreeMonitoring command-line option or cloud.monitoring.free.state for details.有关详细信息,请参阅--enableFreeMonitoring命令行选项或cloud.monitoring.free.state

The db.enableFreeMonitoring() method is a wrapper around the setFreeMonitoring command.db.enableFreeMonitoring()方法是setFreeMonitoring命令的包装器。

Behavior行为

Once enabled, the free monitoring state remains enabled until explicitly disabled. 启用后,空闲监视状态将保持启用状态,直到明确禁用为止。That is, you do not need to re-enable each time you start the server.也就是说,您不需要在每次启动服务器时重新启用。

Once enabled, you are provided with a unique URL where you can access your monitored data.一旦启用,您将获得一个唯一的URL,您可以在其中访问受监控的数据。

When enabled, the monitored data is uploaded periodically. The monitored data expires after 24 hours. 启用后,会定期上传监控数据。监视的数据将在24小时后过期。That is, you can only access monitored data that has been uploaded within the past 24 hours.也就是说,您只能访问在过去24小时内上传的监控数据。

For the frequency with which data is uploaded, see freeMonitoring.retryIntervalSecs.有关上载数据的频率,请参阅freeMonitoring.retryIntervalSecs

Access Control访问控制

When running with access control, the user must have the setFreeMonitoring and checkFreeMonitoringStatus privilege actions on the cluster. 在使用访问控制运行时,用户必须在集群上具有setFreeMonitoringcheckFreeMonitoringStatus权限操作。That is, a user must have a role that grants the following privilege:也就是说,用户必须具有授予以下权限角色

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

The built-in role clusterMonitor role provides this privilege.内置的角色clusterMonitor角色提供了此权限。

Example实例

To enable free monitoring, run the following in mongosh:要启用免费监控,请在mongosh中运行以下操作:

db.enableFreeMonitoring()

This starts the registration process for free monitoring. The method returns your free monitoring status:这将启动免费监控的注册过程。该方法返回您的免费监控状态:

{
"state" : "enabled",
"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().",
"url" : "https://cloud.mongodb.com/freemonitoring/mongo/MSBjZTZhNTJmOS0yODg1",
"userReminder" : "",
"ok" : 1
}
Tip

You can also use db.getFreeMonitoringStatus() any time to check your free monitoring status.您也可以随时使用db.getFreeMonitoringStatus()来检查您的免费监控状态。

Tip

See also: 另请参阅:

db.disableFreeMonitoring()