假设我有一个名为a.b.c.count的度量。我正在尝试编写一个Python脚本,该脚本读取 Graphite 中的a.b.c.count指标的最新值。

我浏览了一下文档,发现可以使用curl使用函数http://graphite.readthedocs.org/en/0.9.13-pre1/functions.html从 Graphite 中检索度量。

但是仍然无法弄清楚如何实现相同的目标。

最佳答案

我还没有一种向Graphite询问单个值的方法,但是您可以要求在可配置的期间内总结一个值,然后取最后一个。 (这只是为了最大程度地减少返回的数据,您可以轻松地在给定的时间范围内从任何序列中提取最后一个值。)示例渲染参数:

target=summarize(a.b.c.count,'1hour','last')&from=-1h&format=json

返回的JSON将如下所示:
[{"target": "summarize(a.b.c.count, \"1hour\", \"last\")",
  "datapoints": [[5.1333330000000004, 1442160000],
                 [5.5499989999999997, 1442163600]]}]

这是一个使用the 'requests' HTTP library检索和解析此内容的Python代码段
import requests
r = requests.get("http://graphite.yourdomain.com/render/?" +
                 "target=summarize(a.b.c.count,'1hour','last')&from=-1h&format=json")
print r.json()[0][u'datapoints'][-1][0]

关于graphite - 从 Graphite 中检索电流度量值,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32495198/

10-16 07:04