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

Getting metrics via API

infotech
Observer

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

9 REPLIES 9

r_weber
DynaMight Pro
DynaMight Pro

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:

 

r_weber_0-1634715317013.png

 

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

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!

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

Certified Dynatrace Master, Dynatrace Partner - 360Performance.net

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!

AntonioSousa
DynaMight Leader
DynaMight Leader

@infotech,

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.

Antonio Sousa

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? 

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

AntonioSousa_0-1637607845293.png

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"

 

Antonio Sousa

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. 

Hi @AntonioSousa 

Can you help me with the above problem?