Hello,
I want to extract metrics with a python script and Dynatrace API V2.
import requests
import json
from pathlib import Path
#fichier de parametrage
file=Path(“logs/dump.json”)
API_TOKEN = “xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx”
# données authentification
headers = {‘content-type’: ‘application/json’,
‘Authorization’ : 'Api-Token ’ + API_TOKEN}
#param
payload = {
“metricSelector”: “builtin:service.response.time:names”,
“entitySelector”: “type(SERVICE)”,
“tags”: [
{
“context”: “CONTEXTLESS”,
“key”: “Environnement”,
“value”: “Production”,
“stringRepresentation”: “Environnement:Production”
},
{
“context”: “CONTEXTLESS”,
“key”: “Projet OpenShift”,
“value”: “ged”
},
{
“context”: “CONTEXTLESS”,
“key”: “Service Name”,
“value”: “svc-document”
}
]
}
r = requests.get(‘https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/api/v2/metrics/query’, verify=False, headers=headers, params=payload)
print("CODE RETOUR: ", r.status_code)
with open(file,‘w’, encoding=“utf8”) as outputjson_file:
outputjson_file.write(json.dumps(r.json(), indent=4))
outputjson_file.close()
I’ve got a HTTP 200 code for result, but i take back all the metrics.
It seem that the tags filter doesn’t work.
How i sould use tags for only get the metric for service name svc-document