google-app-engine – Google Monitoring API:获取值

我正在尝试使用
Google Monitoring API来检索有关我的云使用情况的指标.我正在使用Google Client Library for Python.

API宣传了访问900多个Stackdriver监控指标的功能.我有兴趣访问一些Google App Engine指标,例如实例数,总内存等.Google API指标页面列出了我应该能够访问的所有指标.

我已按照Google客户端库页面上的指南进行操作,但我的API调用脚本未打印指标,只是打印指标描述.

如何使用Google Monitoring API访问指标,而不是说明?

我的代码:

from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
...
response = monitor.projects().metricDescriptors().get(name='projects/{my-project-name}/metricDescriptors/appengine.googleapis.com/system/instance_count').execute()

print(json.dumps(response, sort_keys=True, indent=4))

My Output

我希望看到实际的实例数.我怎样才能做到这一点?

最佳答案 对于读这篇文章的人,我想出了问题所在.我假设值将来自api中的“度量描述符”类,但这是一个不好的假设.

对于值,您需要使用’timeSeries’调用.对于此调用,您需要指定要监视的项目,开始时间,结束时间和过滤器(所需的度量标准,如cpu,内存等).

因此,要检索应用程序引擎项目内存,上面的代码就变成了

request = monitor.projects().timeSeries().list(name='projects/my-appengine-project',
                                        interval_startTime='2016-05-02T15:01:23.045123456Z',
                                        interval_endTime='2016-06-02T15:01:23.045123456Z', 
                                        filter='metric.type="appengine.googleapis.com/system/memory/usage"')

response = request.execute()

此示例具有覆盖一个月数据的开始时间和结束时间.

点赞