对于 AI 代理:可在 https://www.mongodb.com/zh-cn/docs/llms.txt 获取文档索引—通过在任何 URL 路径后添加 .md 可获取所有页面的 Markdown 版本。

通过 Get Host API 读取复制运行状况

您可以使用 Ops Manager API来确定副本集成员是否落后太多而无法追赶。您还可以读取该成员的最后一次复制错误。

Ops Manager adds two fields to the host document, tooStale and lastReplError, and returns them from new v2.0 versions of the three Get Host endpoints. The v1.0 endpoints are unchanged and never return the new fields.

To call these endpoints, you must have the Project Read Only role.

列项
Detail

新端点

v2.0 versions of Get One Host by ID, Get One Host by Hostname and Port, and Get All Hosts. Same paths as v1.0 under /api/public/v2.0.

新领域

tooStale and lastReplError on the host document.

现有端点

v1.0 is unchanged, including the hosts endpoints in the Admin API.

  • Your deployment must run Ops Manager 8.0.28 or 9.0.2 or later.

  • 必须为项目启用监控。如果监控被禁用,运维管理器将忽略新字段。

  • Change the base path of your requests from /api/public/v1.0 to /api/public/v2.0. The rest of each request is unchanged.

1

Use v2.0 Get All Hosts to list hosts, or use the hostname:port you already know.

2
curl --user "{PUBLIC-KEY}:{PRIVATE-KEY}" --digest \ --header "Accept: application/json" \ --include \ --request GET "https://<OpsManagerHost>:<Port>/api/public/v2.0/groups/{GROUP-ID}/hosts/byName/{HOSTNAME-PORT}?pretty=true"
3
{ "hostname": "node1.example.com", "port": 27017, "replicaSetName": "rs0", "replicaStateName": "RECOVERING", "tooStale": true, "lastReplError": "error RS102 too stale to catch up"}

为了简洁起见,文档已进行删减。运维管理器返回完整的主机文档。

名称
类型
说明

太陈旧了

布尔

该成员的进程落后于操作日志窗口,无法从副本集中追赶进度。该成员需要进行初始同步。

最后一次复制错误

字符串

The member's last replication error, from rs.status().

下表描述了 Ops Manager 在特定场景下如何填充新字段。

Scenario
行为

主机是健康的副本集成员

tooStale is false. lastReplError is omitted.

成员位于 oplog 窗口后面

tooStale is true. lastReplError carries the mongod's message.

主机不是副本集成员

这两个字段均已省略。

Request uses a v1.0 endpoint

这两个字段均已省略。

获取所有主机

每个主机报告的是自己成员的值,而不是副本集的值。

这两个字段描述的是响应中的单个主机,而不是整个副本集。

The following table describes common errors and symptoms when you use the v2.0 Get Host endpoints.

症状
可能的原因
解决方案

404 from a v2.0 endpoint

The base path is /api/public/v1.0, or the host isn't in the project.

Use /api/public/v2.0 and confirm the host with v2.0 Get All Hosts.

tooStale and lastReplError are missing

The host isn't a replica set member, monitoring is disabled, or you called a v1.0 endpoint.

Confirm the host belongs to a replica set, monitoring is enabled, and the path uses v2.0.

lastReplError is missing but tooStale is present

该成员报告没有复制错误。

无需采取任何行动。

404 HOST_NOT_FOUND

HOST-ID or HOSTNAME-PORT doesn't match a host in the project.

Confirm the value with v2.0 Get All Hosts.

要以编程方式读取复制健康状况,请参阅“获取具有复制健康状况的主机”。