27 Feb 2024 10:30 AM
Hi,
I want to get all the process groups in my environment, I am using below API to get but not getting all the data at once.
at one time getting 50 records so is there a way to get all data at once.
Solved! Go to Solution.
27 Feb 2024 11:00 AM
Hi,
You can generate your query from Data Explorer, but you need to select a metric where you can split by process group:
builtin:tech.generic.count:splitBy("dt.entity.process_group"):sort(value(auto,descending))
Notice default limit has been removed, it shows more than 100 values.
You can try a similar query:
curl -X GET "https://XXXX.live.dynatrace.com/api/v2/metrics/query?metricSelector=(builtin:tech.generic.count:splitBy(\"dt.entity.process_group\"):sort(value(auto,descending))):names&from=-2h&to=now&resolution=Inf" -H "accept: application/json" -H "Authorization: Api-Token XXXX-XXXX"
Best regards
27 Feb 2024 11:41 AM
Hi @AntonPineiro ,
I am using powershell to execute but getting below error.
Metric selector parse warning: Metric selectors could only be parsed in backward compatibility mode. Consider querying `(builtin:tech.generic.count:splitBy("'dt.entity.process_group'"))` instead., The dimension key 'dt.entity.process_group' has been referenced, but the metric has no such key.
27 Feb 2024 05:05 PM - edited 27 Feb 2024 05:05 PM
Hi,
I do not use powershell but I guess you should adapt ' and " and ` correct expression in Powershell. This is an example about bash vs powershell differences:
curl -X "GET" ^
"https://XXXXX.live.dynatrace.com/api/v2/entities?entitySelector=type%28%22HOSTS%22%29&from=now-30m" ^
-H "accept: application/json; charset=utf-8" ^
-H "Authorization: Api-Token XXXXX"
curl.exe -X 'GET' `
'https://XXXXX.live.dynatrace.com/api/v2/entities?entitySelector=type%28%22HOSTS%22%29&from=now-30m' `
-H 'accept: application/json; charset=utf-8' `
-H 'Authorization: Api-Token XXXXX'
Best regards
27 Feb 2024 12:02 PM - edited 27 Feb 2024 12:08 PM
You can also use DQL:
fetch dt.entity.process_group
You even get yourself a little crazier and go with something like this:
fetch dt.entity.process_group
| fields entity.name, id, lifetime, managementZones, softwareTechnologies, runs[dt.entity.service]
and get additional info for each process:
Query can be executed via the DQL API call also, with the /query: execute , with start/end you can play with the delta and get only the ones that have a delta against now()
27 Feb 2024 12:15 PM
Hi @Dant3 ,
I am automating something so need it for my script to get it via API.
27 Feb 2024 12:32 PM
You can execute DQL via API call, swagger to check the schema:
28 Feb 2024 09:34 AM
Hi @Naveen ,
Dynatrace API uses pagination concept. So, you have to adopt it in your script (you get next page key in the answer JSON). Theoretically you could define page size with pageSize=xxx, but you will need to know in advance how much PG's you have (or pick it up from the API call as it is there in JSON too).
Br,
Ingrida
28 Feb 2024 10:18 AM
you can add something similar to this in a python code to extract the information.
def send_request(tenant, token, nextPageKey=None):
base_url = f"{tenant}/api/v2/entities?entitySelector=type(\"PROCESS_GROUP_INSTANCE\")"
url = get_entity_url(base_url, nextPageKey)
headers = {'Authorization': f'Api-Token {token}'}
try:
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
except requests.exceptions.RequestException as e:
print(f"Error: {e}")
return None
..................................
nextPageKey = None
result = []
while True:
response = send_request(tenant, token, nextPageKey)
if not response:
break
result += process_response(response)
nextPageKey = response.get('nextPageKey')
if not nextPageKey:
break