下载一个项目中一台集群主机的日志
返回压缩 (.gz) 日志文件,其中包含指定项目中指定主机的一系列日志信息。MongoDB 每五分钟更新一次集群后端基础架构的进程和审核日志。日志以长度约为五分钟的数据块存储,但此持续时间可能会有所不同。如果您轮询 API 的日志文件,我们建议每五分钟轮询一次,即使连续轮询可能包含一些重叠的日志。此功能不适用于 M0
免费集群、M2
、M5
、Flex 或无服务器集群。要使用此资源,请求的服务账户或 API 密钥必须具有项目数据访问只读或更高角色。该 API 不支持直接调用并返回 JSON 格式的响应模式。您必须使用以下格式的接受标头来请求 gzip 响应模式:“Accept: application/vnd.atlas.YYYY-MM-DD+gzip”。已弃用的版本:v2-{2023-01-01}
路径参数
-
用于标识项目的唯一 24-十六进制数字字符串。 使用 /groups 端点检索身份验证的用户有权访问权限的所有项目。
注意:群组和项目是同义词。您的群组 ID 与项目 ID 相同。对于现有群组,群组/项目 ID 保持不变。资源和相应的端点使用“群组”一词。
格式应符合以下模式:
^([a-f0-9]{24})$
。 -
用户可读的标签,用于标识存储要下载的日志文件的主机。
格式应符合以下模式:
^([0-9]{1,3}\.){3}[0-9]{1,3}|([0-9a-f]{1,4}:){7}([0-9a-f]{1,4})|(([a-z0-9]+\.){1,10}[a-z]+)?$
。 -
用户可读的标签,用于标识要返回的日志文件。要返回审核日志,请为指定项目启用数据库审核。
取值为
mongodb
、mongos
、mongodb-audit-log
或mongos-audit-log
。设置数据库审核
查询参数
-
指示应用程序是否将响应包装在
envelope
JSON 对象中的标志。某些 API 客户端无法访问 HTTP 响应标头或状态代码。要修复此问题,请在查询中设置 Envelope=true。返回结果列表的端点将结果对象用作 envelope。应用程序将状态参数添加到响应正文中。默认值为
false
。 -
指定要检索的日志消息范围终点的日期和时间,单位为自 UNIX 纪元起经过的秒数。此值将默认为开始日期后 24 小时。如果还未指定开始日期,则该值将默认为请求的时间。
最小值为
1199145600
。 -
指定要检索的日志消息范围起点的日期和时间,单位为自 UNIX 纪元起经过的秒数。此值将默认为结束日期前 24 小时。如果还未指定结束日期,则该值将默认为请求的时间前 24 小时。
最小值为
1199145600
。
atlas api monitoringAndLogs downloadGroupClusterLog --help
import (
"os"
"context"
"log"
sdk "go.mongodb.org/atlas-sdk/v20230201001/admin"
)
func main() {
ctx := context.Background()
clientID := os.Getenv("MONGODB_ATLAS_CLIENT_ID")
clientSecret := os.Getenv("MONGODB_ATLAS_CLIENT_SECRET")
// See https://dochub.mongodb.org/core/atlas-go-sdk-oauth
client, err := sdk.NewClient(sdk.UseOAuthAuth(clientID, clientSecret))
if err != nil {
log.Fatalf("Error: %v", err)
}
params = &sdk.DownloadGroupClusterLogApiParams{}
sdkResp, httpResp, err := client.MonitoringandLogsApi.
DownloadGroupClusterLogWithParams(ctx, params).
Execute()
}
curl --include --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header "Accept: application/vnd.atlas.2023-02-01+gzip" \
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz" \
--output "file_name.gz"
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
--digest --include \
--header "Accept: application/vnd.atlas.2023-02-01+gzip" \
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/clusters/{hostName}/logs/{logName}.gz" \
--output "file_name.gz"
{
"error": 400,
"detail": "(This is just an example, the exception may not be related to this endpoint) No provider AWS exists.",
"reason": "Bad Request",
"errorCode": "VALIDATION_ERROR"
}
{
"error": 401,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Unauthorized",
"errorCode": "NOT_ORG_GROUP_CREATOR"
}
{
"error": 403,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Forbidden",
"errorCode": "CANNOT_CHANGE_GROUP_NAME"
}
{
"error": 404,
"detail": "(This is just an example, the exception may not be related to this endpoint) Cannot find resource AWS",
"reason": "Not Found",
"errorCode": "RESOURCE_NOT_FOUND"
}
{
"error": 409,
"detail": "(This is just an example, the exception may not be related to this endpoint) Cannot delete organization link while there is active migration in following project ids: 60c4fd418ebe251047c50554",
"reason": "Conflict",
"errorCode": "CANNOT_DELETE_ORG_ACTIVE_LIVE_MIGRATION_ATLAS_ORG_LINK"
}
{
"error": 500,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Internal Server Error",
"errorCode": "UNEXPECTED_ERROR"
}