db.enableFreeMonitoring()

On this page本页内容

db.enableFreeMonitoring()

New in version 4.0.在版本4.0中新增 Available for MongoDB Community Edition.适用于MongoDB社区版。

Enables free monitoring for standalones and replica sets and returns the free monitoring status.启用对标准机和副本集的免费监视,并返回免费监视状态。

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配置文件设置为运行时。

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()db.getFreeMonitoringStatus →