Skip to content

Instantly share code, notes, and snippets.

@theist
Created March 27, 2020 18:02
Show Gist options
  • Save theist/e8c0e5d4ea1ff52e46a5bf4b409cc9bc to your computer and use it in GitHub Desktop.
Save theist/e8c0e5d4ea1ff52e46a5bf4b409cc9bc to your computer and use it in GitHub Desktop.
import urllib2
import json
def to_dotted(var, root=""):
if isinstance(var, dict):
for k in var.keys():
for r in to_dotted(var[k], root + "." + str(k)):
yield r
elif isinstance(var, list):
for i,k in enumerate(var):
for r in to_dotted(k, root + "." + str(i)):
yield r
else:
yield [root, var]
def get_json(path):
req = urllib2.urlopen(path)
data = req.read()
return json.loads(data)
def get_es_metrics():
for item in to_dotted(get_json('http://localhost:9200/_cluster/health?level=indices'), "es.health"):
print item[0] + " = " + str(item[1])
for item in to_dotted(get_json('http://localhost:9200/_all/_stats'), "es.indices"):
print item[0] + " = " + str(item[1])
for item in to_dotted(get_json('http://localhost:9200/_nodes/stats'), "es.nodes"):
print item[0] + " = " + str(item[1])
if __name__ == "__main__":
get_es_metrics()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment