17 May 2024 12:12 PM - last edited on 07 Jun 2024 11:48 AM by Michal_Gebacki
I am trying to utilize this python script:
import requests
import csv
DYNATRACE_BASE_URL = 'https://your-dynatrace-instance.com/api/v1'
API_TOKEN = 'your-api-token'
MANAGEMENT_ZONE_ID = 'your-management-zone-id'
headers = {
'Authorization': 'Api-Token {}'.format(API_TOKEN)
}
def get_metrics(management_zone_id):
endpoint = '{}/metrics'.format(DYNATRACE_BASE_URL)
params = {
'managementZone': management_zone_id
}
response = requests.get(endpoint, headers=headers, params=params)
response.raise_for_status()
return response.json()
def export_metrics_to_csv(metrics, filename='metrics.csv'):
if not metrics:
print('No metrics to export.')
return
headers = metrics[0].keys()
with open(filename, 'w', newline='') as csvfile:
writer = csv.DictWriter(csvfile, fieldnames=headers)
writer.writeheader()
writer.writerows(metrics)
print('Metrics exported to {}'.format(filename))
def main():
try:
metrics_data = get_metrics(MANAGEMENT_ZONE_ID)
metrics = metrics_data.get('metrics', [])
if not metrics:
print('No metrics found for the specified management zone.')
return
export_metrics_to_csv(metrics)
except Exception as e:
print('Error occurred: {}'.format(e))
if __name__ == '__main__':
main()
But on the execution, it says "the hostname does not match either of *.ypz572.dynatrace-managed.com"
my hostname is dynatrace.app.intra.pfs.local
Solved! Go to Solution.
17 May 2024 05:35 PM
Hi,
Which metrics you are interested in?
Best regards
18 May 2024 09:35 AM
Number of web service requests and response time for each of the element of the management zone,
18 May 2024 01:26 PM
Hi,
Easier way to me is from Data Explorer:
Select "..." and "Copy request":
You will have a way to export information in JSON or CSV, just input your token:
Notice it is filtered by "mzId", you can filter also by "mzName" if you prefer.
This would be for one specific managment zone. If you need all of them:
Best regards