【问题标题】:Query GCP monitoring API for current postgres connections query?查询当前 postgres 连接查询的 GCP 监控 API?
【发布时间】:2020-11-24 00:52:47
【问题描述】:

我们可以在 GCP 控制台中看到 postgres 连接,所以我们假设它可以通过监控 API 进行查询。控制台为我们提供了这个 MQL 查询:

fetch cloudsql_database
| metric 'cloudsql.googleapis.com/database/postgresql/num_backends'
| filter (resource.database_id == 'my-project-id:my-database-id')
| group_by 1m, [value_num_backends_mean: mean(value.num_backends)]
| every 1m

监控APIhttps://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query

表示query参数是必需的,查询为监控查询语言格式。但是,当我“尝试此 API”并尝试将查询设置为从上面的控制台获得的内容时,我收到 | 字符的“遇到意外字符”错误。如何正确格式化查询以获得我正在寻找的结果?我查看了Retrieving data with timeSeries.query 文档,并没有提到需要转义这些字符。

【问题讨论】:

  • 删除这些字符时是否收到错误消息?如果这样做,请确保使用该信息编辑原始帖子

标签: google-cloud-platform google-cloud-monitoring


【解决方案1】:

因此 MQL 更多地用于在 Monitoring Metrics Explorer 中进行查询,而 Monitoring API 使用不同类型的语言进行过滤。类似于

resource.type = "the_resource_type"
resource.labels.a_label_for_the_resource_type = "label_value"

这就是您将用于使用 API 而不是 MQL 进行查询的方法。

exa 看起来像这样:

metric.type = "compute.googleapis.com/instance/cpu/usage_time" AND
    metric.labels.instance_name = "my-instance-name"

https://cloud.google.com/monitoring/api/v3/filters

您可能还想考虑使用 time series list 作为另一种可能的 API 方法,因为这不需要 MQL。

【讨论】:

    猜你喜欢
    • 2019-06-27
    • 1970-01-01
    • 2021-02-20
    • 2015-09-23
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多