返回慢查询
返回 Performance Advisor 和查询分析器识别的慢速查询日志条目。性能优化顾问会监控 MongoDB 认为其速度缓慢的查询,并建议使用新索引来提高查询性能。MongoDB Cloud 根据集群上的平均操作时间确定慢速查询的阈值。这将启用与工作负载相关的建议。 要使用此资源,请求的服务账户或 API 密钥必须具有任一项目数据访问角色或项目可观察性查看者角色。
路径参数
-
用于标识项目的唯一 24-十六进制数字字符串。 使用 /groups 端点检索身份验证的用户有权访问权限的所有项目。
注意:群组和项目是同义词。您的群组 ID 与项目 ID 相同。对于现有群组,群组/项目 ID 保持不变。资源和相应的端点使用“群组”一词。
格式应符合以下模式:
^([a-f0-9]{24})$
。 -
为 MongoDB 进程提供服务的主机和端口的组合。主机必须是运行 MongoDB 进程(
mongod
或mongos
)的主机的主机名、FQDN、IPv4 地址或 IPv6 地址。该端口必须是 MongoDB 进程侦听请求的 IANA 端口。格式应符合以下模式:
^([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]+)?(\:[0-9]{4,5})$
。
查询参数
-
指示应用程序是否将响应包装在
envelope
JSON 对象中的标志。某些 API 客户端无法访问 HTTP 响应标头或状态代码。要修复此问题,请在查询中设置 Envelope=true。返回结果列表的端点将结果对象用作 envelope。应用程序将状态参数添加到响应正文中。默认值为
false
。 -
指示响应正文是否应采用 prettyprint 格式的标记。
默认值为
false
。Prettyprint -
查询在集群的托管命名空间中查找慢查询的时间长度。此参数以毫秒为单位。
- 如果不指定 since 参数,则端点将返回涵盖当前时间之前持续时间的数据。
- 如果您既不指定 duration 也不指定 since 参数,该端点将返回过去 24 小时的数据。
-
要从中检索慢速查询的命名空间。命名空间由一个数据库和一个集合资源组成,写作
.
:<database>.<collection>
。要包含多个命名空间,请多次传递该参数,并在每个命名空间之间用与号 (&
) 分隔。省略此参数可返回所有命名空间的结果。 -
日志中要返回的最大行数。
最小值为
0
,最大值为20000
。默认值为20000
。 -
查询检索慢查询开始的日期和时间。该参数以自 UNIX 纪元以来经过的毫秒数表示其值。
- 如果不指定持续时间参数,端点将返回从 since 值到当前时间的数据。
- 如果您既不指定 duration 也不指定 since 参数,该端点将返回过去 24 小时的数据。
最小值为
1199145600000
。 -
是否将从慢查询日志中提取的指标作为单独的字段包含在内。
默认值为
false
。 -
当慢查询日志作为单独字段生成时,是否包含托管的副本状态。
默认值为
false
。 -
是否将从慢查询日志中提取的操作类型(读取/写入/命令)作为单独的字段包含在内。
默认值为
false
。
atlas api performanceAdvisor listGroupProcessPerformanceAdvisorSlowQueryLogs --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.ListGroupProcessPerformanceAdvisorSlowQueryLogsApiParams{}
sdkResp, httpResp, err := client.PerformanceAdvisorApi.
ListGroupProcessPerformanceAdvisorSlowQueryLogsWithParams(ctx, params).
Execute()
}
curl --include --header "Authorization: Bearer ${ACCESS_TOKEN}" \
--header "Accept: application/vnd.atlas.2023-02-01+json" \
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/processes/{processId}/performanceAdvisor/slowQueryLogs?pretty=true"
curl --user "${PUBLIC_KEY}:${PRIVATE_KEY}" \
--digest --include \
--header "Accept: application/vnd.atlas.2023-02-01+json" \
-X GET "https://cloud.mongodb.com/api/atlas/v2/groups/{groupId}/processes/{processId}/performanceAdvisor/slowQueryLogs?pretty=true"
{
"slowQueries": [
{
"line": "string",
"metrics": {
"docsExamined": 42,
"docsExaminedReturnedRatio": 42.0,
"docsReturned": 42,
"fromUserConnection": true,
"hasIndexCoverage": true,
"hasSort": true,
"keysExamined": 42,
"keysExaminedReturnedRatio": 42.0,
"numYields": 42,
"operationExecutionTime": 42,
"responseLength": 42
},
"namespace": "string",
"opType": "string",
"replicaState": "string"
}
]
}
{
"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": 429,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Too Many Requests",
"errorCode": "RATE_LIMITED"
}
{
"error": 500,
"detail": "(This is just an example, the exception may not be related to this endpoint)",
"reason": "Internal Server Error",
"errorCode": "UNEXPECTED_ERROR"
}