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

CPU Usage Via API

Aniket
Newcomer

Hello Everyone,

I am new to Dynatrace and its APIs, I am trying to get average CPU usage for last 5 mins for all HOSTs.

Here is my API call :
https://{your-domain}/e/{your-environment-id}/api/v2/metrics/query?metricSelector=builtin:host.cpu.u...

This gives me : CPU Usage like below.

CPU Usage per minute for last 5 minutes per host.

metricId,dt.entity.host,time,value
builtin:host.cpu.usage,HOST1,2021-07-30 11:23:00,1.8231608072916667
builtin:host.cpu.usage,HOST1,2021-07-30 11:24:00,2.5442708333333335
builtin:host.cpu.usage,HOST1,2021-07-30 11:25:00,2.3963826497395835
..
builtin:host.cpu.usage,HOST2,2021-07-30 11:23:00,2.1693929036458335
builtin:host.cpu.usage,HOST2,2021-07-30 11:24:00,
builtin:host.cpu.usage,HOST2,2021-07-30 11:25:00,0.35211181640625

 

What I want is :
I am looking for one value per most which is average CPU usage for that host for last 5 minute like below.

 

metricId,dt.entity.host,time,value
builtin:host.cpu.usage,HOST1,2021-07-30 11:xx:00,1.8231608072916667
builtin:host.cpu.usage,HOST2,2021-07-30 11:xx:00,2.5442708333333335
builtin:host.cpu.usage,HOST3,2021-07-30 11:xx:00,2.3963826497395835

 

How can I transform the API to get such results? I read about metric transformation, didn't follow it well.

Thank You.  

2 REPLIES 2

Julius_Loman
DynaMight Legend
DynaMight Legend

Hello @Aniket ,

 

I believe you want to use the fold transformation for that. It will aggregate the data points into one for each dimension.

 

https://your-domain/e/your-environment-id/api/v2/metrics/query?metricSelector=builtin:host.cpu.usage:fold&resolution=1m&from=now-5m&entitySelector=type("HOST")


Julius

Certified Dynatrace Master | Alanata a.s., Slovakia, Dynatrace Master Partner

Thanks @Julius_Loman 😊

Featured Posts