21 Dec 2023 02:59 PM
Hi, I am trying to use an API request to get a server disk usage percentage. How can I achieve this?
Solved! Go to Solution.
21 Dec 2023 03:49 PM
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":
And you have an example to get that data.
You need to generate a token with correct permissions in advance.
Best regards
23 Dec 2023 01:27 PM
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"
24 Dec 2023 12:14 PM - edited 24 Dec 2023 12:17 PM
Hi,
If you change visualization to "Single value":
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
21 Dec 2023 09:50 PM
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