我正在尝试使用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
我希望看到实际的实例计数。我如何才能做到这一点?
发布于 2016-07-26 22:36:10
对于任何阅读这篇文章的人来说,我发现了问题所在。我假设这些值来自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()此示例具有涵盖一个月数据的开始时间和结束时间。
https://stackoverflow.com/questions/38488956
复制相似问题