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

How to get all process groups in environment?

Naveen
Guide

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.

https://{environmentid}.live.dynatrace.com/api/v2/entities?entitySelector=type%28%22PROCESS_GROUP%22...

 at one time getting 50 records so is there a way to get all data at once. 

8 REPLIES 8

AntonPineiro
DynaMight Guru
DynaMight Guru

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))

AntonPineiro_0-1709031478500.png

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

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

Naveen
Guide

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.

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

❤️ Emacs ❤️ Vim ❤️ Bash ❤️ Perl

Dant3
Pro

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:

Dant3_0-1709035418570.png

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()

Services Solution Engineer @PowerCloud - Observability/CloudOps Certified / Former SE @Dynatrace.

Hi @Dant3 ,

I am automating something so need it for my script to get it via API.

You can execute DQL via API call, swagger to check the schema:

https://{environmentid}.apps.dynatrace.com/platform/swagger-ui/index.html?urls.primaryName=Grail%20-...

Services Solution Engineer @PowerCloud - Observability/CloudOps Certified / Former SE @Dynatrace.

Ingrida
Mentor

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

PacoPorro
Dynatrace Leader
Dynatrace Leader

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

 

Featured Posts