19 Oct 2021 05:22 PM - last edited on 18 Nov 2021 09:49 AM by MaciejNeumann
Hi, I want to get some metrics from the dynatrace but I'm not sure they belong to which version V1 or V2? Can anyone help me with finding the correct address for getting the following metrics:
memory usage(service and process), CPU usage(service and process), throughput, network traffic, responsiveness, network connectivity and data round trip time
Solved! Go to Solution.
20 Oct 2021 08:35 AM
Hi @infotech ,
it's not relevant if you use APIv1 or APIv2. All metrics are available on both API versions, just in a different way and possibilities how to get them.
You can use the "Metric" browser in Dynatrace to find the metric IDs for the ones you want to query. For example a generic memory usage of processes can be found with this ID:
20 Nov 2021 08:16 PM - last edited on 27 Mar 2023 10:19 AM by MaciejNeumann
Hi @r_weber
https://"mine".live.dynatrace.com/api/v1/timeseries/com.dynatrace.builtin:tech.generic.cpu.usage?api... token"&includeData=true&aggregationType=avg&entity=PROCESS_GROUP_INSTANCE-BD475E0A43F03373
I entered the above URL but it returned:
{"error":{"code":404,"message":"Timeseries id com.dynatrace.builtin:tech.generic.cpu.usage is not valid"}}
I got the same error for:
https://"mine".live.dynatrace.com/api/v1/timeseries/com.dynatrace.builtin:tech.generic.mem.usage?api... token"&includeData=true&aggregationType=avg&entity=PROCESS_GROUP_INSTANCE-BD475E0A43F03373
I can also see throughput for a service in Dynatrace but when I enter its entity, again I receive the same error!
22 Nov 2021 11:57 AM
Hi @infotech ,
the metric ID is "builtin:tech.generic.cpu.usage" not "com.dynatrace.builtin:...."
With that it should work. But I also recommend to using the V2 API for anything new you design, it provides some more nice features.
kr,
Reinhard
22 Nov 2021 04:04 PM
For response time , the only metric that I could successfully receive from the API, I entered "com.dynatrace...." and it worked so I thought maybe I need to enter that part for all of the metrics. I just deleted that part and still got the same error!
22 Nov 2021 09:10 AM - last edited on 27 Mar 2023 10:19 AM by MaciejNeumann
If you try it out from the web interface:
https://mine.live.dynatrace.com/rest-api-doc/index.jsp?urls.primaryName=Environment API v1
It will generate the curl command from the selections that you make, so it will be easier to figure out what is wrong.
22 Nov 2021 04:21 PM
Thank you, I went to that page and under "/metrics/{metricKey} Gets the descriptor of the specified metric" entered "tech.generic.mem.usage" but it returned a 404 error! Do I need to add anything else in that input box?
22 Nov 2021 07:05 PM - last edited on 29 May 2023 10:31 AM by MaciejNeumann
If you are using /metrics you are using APIv2. Beware that the synthax for v1 & v2 differ for metrics.
Now, if you want the values from the metrics, you should use /metrics/query
Then, you should enter builtin:tech.generic.mem.usage in metricSelector
Then click Execute, and you should get the values, and some curl like:
curl -X GET "https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin%3Atech.generic.mem.usage" -H "accept: application/json; charset=utf-8" -H "Authorization: Api-Token YOUR_API_TOKEN"
23 Nov 2021 05:51 PM
Hi again,
I could get the data from V2 but unfortunately, it lacks information such as display name, aggregation types and I need them as well. Also, I cannot get the values for only one specific entity although I added the entity id for my process.
29 Nov 2021 04:14 PM
Can you help me with the above problem?
09 Dec 2021 10:03 AM
Regarding the information that you are lacking, you might need to make other API calls. That is typically the case when you get Entity codes in the JSON replies, and you want to get detailed information about those entities.
Regarding the second part of your question, it would be important for you to post here the API call you are invoking (please do not include sensitive information, eg. url & API token).
12 Dec 2021 02:00 PM - last edited on 27 Mar 2023 10:19 AM by MaciejNeumann
So do you know which API I should call?
this is what works but I need to get the specific entity information not all of them, I entered the entity id but still get the same values!
https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mytoken
Thank you
12 Dec 2021 03:05 PM
Hi @infotech
You need to add the process name you are looking for to the enttitySelector.
In order to do taht you can go to the data explorer select Process CPU usage metric, split by process and in the filter pick the process.name you are looking for.
Then go to the code tab and copy the entitySelector part:
HTH
Yos
12 Dec 2021 04:32 PM - last edited on 27 Mar 2023 10:19 AM by MaciejNeumann
If you mean something like this:
https://mine.live.dynatrace.com/api/v2/metrics/query?metricSelector=builtin:tech.generic.cpu.usage&api-token=mine&entitySelector=PROCESS_GROUP_INSTANCE-BD475E0A43F03373
I did add the entity selector as well before replying to the above post but it returns error code 400
12 Dec 2021 05:06 PM - edited 12 Dec 2021 05:08 PM
Go to the rest api explorer, under Environment API v2 find metric/query entry and add your metric: builtin:tech.generic.cpu.usage
go to the selector filed and add type and your process ID as type("PROCESS_GROUP_INSTANCE"),entityId("PROCESS_GROUP_INSTANCE-XXXXXXXXX")
click on the execute button and you will get the response.
Then copy from the curl or url fields the whole request and paste it where you need it, this should work as a charm.
HTH
Yos
12 Dec 2021 05:27 PM
Still got the same error!
12 Dec 2021 05:33 PM
What did you put in selector filed? can you paste it here please?
12 Dec 2021 05:37 PM
What I got from data explorer:
type(process_group_instance),entityId(~"PROCESS_GROUP_INSTANCE-BD475E0A43F03373~")
12 Dec 2021 05:40 PM - edited 12 Dec 2021 05:41 PM
Try this please:
type("PROCESS_GROUP_INSTANCE"),entityId("PROCESS_GROUP_INSTANCE-BD475E0A43F03373")
Yos
12 Dec 2021 05:46 PM
Thank you very much Yosi, it works for now but I should add it to my code to see if it gives me the desired fields. Unfortunately, I still cannot get the display name and aggregation type from it, but I really appreciate your help.
12 Dec 2021 05:54 PM - edited 13 Dec 2021 07:00 AM
Your are more than welcome @infotech
For entity name use
Regarding aggregation you can add transformation after the metric name
Check if resolution can give you any additional help
All the best and stay safe
Yos