cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Dynatrace Metrics API into Jupyter Notebook

grogers
Participant

Has anyone used the Dynatrace Metrics API (v2) to pull data into a Jupyter notebook? I'm close, but need to pivot the default data format into something more friendly.

url = '{0}/api/v2/metrics/query?metricSelector={1}&from={2}&to={3}&resolution=2m&entitySelector=type({4}),entityId({5})'.format(base_url,metric,from_time,to_time,entity_type,entity_id)

result = requests.get(url, headers=headers)

result_json = result.json()

df = pd.DataFrame.from_dict(result_json['result'][0]['data'])
                                                     
df

I'm trying to gather 4-5 different metrics into a notebook to present to management.

1 REPLY 1

grogers
Participant

Got it:


metric = 'builtin:service.response.time'
entity_type = 'SERVICE'
entity_id = 'SERVICE-64FED8674FB7BA98'
from_time = 'now-1h'
to_time = 'now'

url = '{0}/api/v2/metrics/query?metricSelector={1}&from={2}&to={3}&resolution=2m&entitySelector=type({4}),entityId({5})'.format(base_url,metric,from_time,to_time,entity_type,entity_id)

result = requests.get(url, headers=headers)

result_json = result.json()

in_data = result_json['result'][0]['data'][0]
del in_data['dimensions']

df = pd.DataFrame.from_dict(in_data)

df.timestamps = pd.to_datetime(df.timestamps, unit='ms', utc=True)
df.timestamps = df.timestamps.dt.tz_convert('US/Central')

df.plot(x='timestamps', y='values')