如何获得JSON格式的石墨树结构

时间:2014-01-08 06:22:33

标签: python django json graphite

我想以json格式查看所有石墨树结构。我目前正在使用

GET /metrics/find/?format=treejson&query=stats.gauges.*

给出:

[{"leaf": 0, "context": {}, "text": "echo_server", 
     "expandable": 1, "id": "stats.gauges.echo_server", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "logstash",
     "expandable": 1, "id": "stats.gauges.logstash", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "server0",
     "expandable": 1, "id": "stats.gauges.server0", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "server1", 
     "expandable": 1, "id": "stats.gauges.server1", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "stats", 
     "expandable": 1, "id": "stats.gauges.stats", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "statsd", 
     "expandable": 1, "id": "stats.gauges.statsd", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "vamsi", 
     "expandable": 1, "id": "stats.gauges.vamsi", "allowChildren": 1},
 {"leaf": 0, "context": {}, "text": "vamsi-server",
     "expandable": 1, "id": "stats.gauges.vamsi-server", "allowChildren": 1}
]

为了获得直接的孩子,理想情况下我想拥有所有元素。

[[UPDATE]]

使用GET/metrics/index.json提供所需的JSON。

那么,我们如何构建树视图?

1 个答案:

答案 0 :(得分:3)

我显然正在做同样的事情。我的解决方案是:

  

http://graphite/metrics/find/?format=treejson&query= *

返回树节点的第一级。然后对于每一个你必须这样做:

  

http://graphite/metrics/find/?format=treejson&query=previous_node_levels_with_dots *

并获取该子树的下一级节点。

通过递归执行此操作直到您点击“leaf = 1”节点,您可以构建整个树。