Google Monitoring API:获取价值 [英] Google Monitoring API : Get Values

查看:61
本文介绍了Google Monitoring API:获取价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Google监控API 来检索有关我的指标云使用情况.我正在使用适用于Python的Google客户端库.

I'm trying to use the Google Monitoring API to retrieve metrics about my cloud usage. I'm using the Google Client Library for Python.

API宣传可以访问900多个Stackdriver Monitoring指标的功能.我对访问某些Google App Engine指标感兴趣,例如实例数",总内存"等."Google API指标"页面上列出了我应该可以访问的所有指标.

The API advertises the ability to access over 900 Stackdriver Monitoring Metrics. I am interested in accessing some Google App Engine metrics, such as Instance count, total memory, etc. The Google API Metrics page has a list of all the metrics I should be able to access.

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

I've followed the guides on the Google Client Library page , but my script making the API calls is not printing the metrics, it is just printing the metric descriptions.

如何使用Google Monitoring API访问指标而不是描述?

How do I use the Google Monitoring API to access the metrics, rather than the descriptions?

我的代码:

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))

我的输出

我希望看到实际的实例数.我该如何实现?

I expect to see the actual instance count. How can I achieve this?

推荐答案

对于阅读此书的任何人,我都知道了问题所在.我以为这些值将来自api中的度量描述符"类,但这是一个错误的假设.

For anyone reading this, I figured out the problem. I was assuming the values would come from the 'metric descriptors' class in the api, but that was a poor assumption.

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

For values, you need to use a 'timeSeries' call. For this call, you need to specify the project you want to monitor, start time, end time, and a filter (the metric you want, such as cpu, memory, etc.)

因此,要检索App Engine项目的内存,上面的代码将变为

So, to retrieve the app engine project memory, the above code becomes

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()

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

This example has the start time and end time to cover a month of data.

这篇关于Google Monitoring API:获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆