我们可以在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监控接口https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.timeSeries/query
表示query参数是必需的,并且查询采用监视查询语言格式。然而,当我“尝试这个接口”并试图将查询设置为我从上面的控制台获得的内容时,我得到了一个错误,|字符的“意外字符遇到”。我如何正确地格式化查询,以获得我想要的结果?我浏览了Retrieving data with timeSeries.query文档,其中没有提到需要对这些字符进行转义。
发布于 2020-08-08 01:55:39
因此,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作为另一种可能的应用编程接口方法,因为这不需要MQL。
https://stackoverflow.com/questions/63238188
复制相似问题