【问题标题】:Retrieve current metric value from graphite从石墨中检索当前度量值
【发布时间】:2015-09-10 06:59:08
【问题描述】:

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

我浏览了文档并发现我们可以使用 curl 使用函数 http://graphite.readthedocs.org/en/0.9.13-pre1/functions.html 从石墨中检索指标。

但仍然无法弄清楚如何实现。

【问题讨论】:

    标签: graphite


    【解决方案1】:

    我还没有看到向 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]]}]
    

    这是一个 Python sn-p 来检索和解析它,使用 the 'requests' HTTP library

    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]
    

    【讨论】:

      猜你喜欢
      • 2017-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 2019-12-20
      • 2013-12-11
      相关资源
      最近更新 更多