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

Host disk usage API call

Itani_ML
Participant

Hi, I am trying to use an API request to get a server disk usage percentage. How can I achieve this?

4 REPLIES 4

AntonPineiro
DynaMight Guru
DynaMight Guru

Hi,

You can go to data explorer and select metric you and instered (builtin:host.disk.usedPct in this case) and filter server by name.

After that, press "..." and select "Copy Request":

AntonPineiro_0-1703173734623.png

And you have an example to get that data.

You need to generate a token with correct permissions in advance.

Best regards

 

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

Thanks you, it really worked. One last question, with this request, is it possible to only filter out the value?

Below is my request and I am running it from Bamboo, I only want to get the value of the disk as the output

 

curl -X GET "https://{environmentid}.live.dynatrace.com/api/v2/metrics/query?metricSelector=(builtin:host.disk.fr..."dt.entity.host\",entitySelector(\"type(~\"HOST~\"),entityName.equals(~\"dhdelasticls01.discsrv.co.za~\")\"))))):splitBy():sort(value(auto,descending))):limit(100):names&from=-2h&to=now" -H "accept: application/json" -H "Authorization: Api-Token XXXX-XXXX"

Hi,

If you change visualization to "Single value":

AntonPineiro_0-1703419966595.png

Notice "&resolution=Inf" is added in the end when you copy request from wizard. For example:

 

curl -X GET "https://{environment_id}.live.dynatrace.com/api/v2/metrics/query?metricSelector=(builtin:host.disk.usedPct:filter(and(or(in(\"dt.entity.host\",entitySelector(\"type(host),entityName.equals(~\"XXXX~\")\"))))):splitBy():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

radek_jasinski
DynaMight Guru
DynaMight Guru

@Itani_ML 

Of course, I also recommend using API Explorer, which will allow you to easily prepare and check a query to retrieve the metric of your choice.

https://docs.dynatrace.com/docs/shortlink/section-api#api-explorer

You can find the metrics where the @AntonPineiro pointed out.

Radek

Have a nice day!

Featured Posts