Skip to content

Instantly share code, notes, and snippets.

@conorbranagan
Last active June 8, 2018 09:43
Show Gist options
  • Save conorbranagan/e1eae1df130e3e1027bbca38d6b4e202 to your computer and use it in GitHub Desktop.
Save conorbranagan/e1eae1df130e3e1027bbca38d6b4e202 to your computer and use it in GitHub Desktop.
Graph Query API

trace_graph_query.py provides a simple CLI for getting the trace graph data. It will use the org

Usage

usage: trace_graph.py [-h] [--api_key API_KEY]
                      [--application_key APPLICATION_KEY]
                      [--name {service,host}]

optional arguments:
  -h, --help            show this help message and exit
  --api_key API_KEY     Datadog API key
  --application_key APPLICATION_KEY
                        Datadog application key
  --name {service,host}
                        Name of graph
  1. Find the API key for the org at https://app.datadoghq.com/account/settings#api (or partlow)
  2. Run the script with python, for example:
python3 trace_graph.py --api_key=REDACTED --application_key=REDACTED --name {service,host}
"""
Fetch trace graph data
"""
import argparse
import requests
import json
URL = "https://process.datadoghq.com/api/v1/graph"
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--api_key', help="Datadog API key")
parser.add_argument('--application_key', help="Datadog application key")
parser.add_argument('--name', help="Name of graph", choices=('service', 'host'))
opts = parser.parse_args()
request_data = {
"name": opts.name
}
params = {'api_key': opts.api_key, 'application_key': opts.application_key}
res = requests.post(URL, params=params, data=json.dumps(request_data))
graph = json.loads(res.content[16:])["graphJSON"]
print(json.dumps(json.loads(graph)))
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment