Hello, is there a way to get droplet metric data via the API? I’ve looked at the API docs page and have not seen such a thing.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
Accepted Answer
Hello,
Just a quick update here. DigitalOcean now has a Monitoring API endpoint that you could use. For more information you can take a look at the official API documentation here:
https://docs.digitalocean.com/reference/api/api-reference/#tag/Monitoring
Also, keep in mind that you need to have the DigitalOcean Metrics Agent installed on your Droplet in order to get some data back.
You can install the do-agent
as per the instructions here:
https://docs.digitalocean.com/products/monitoring/how-to/install-agent/
Hope that this helps. Best, Bobby
Hey @RiversideRocks ,
You should be able to get json output specifically for metrics from our API. Here is the API documentation link: https://docs.digitalocean.com/reference/api/api-reference/#operation/get_droplet_cpu_metrics.
Example. If you wish to get the cpu metrics for a Droplet, this would be syntax you would want to use:
curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/monitoring/metrics/droplet/cpu?host_id=$dropletid&start=$starttimeinepoch&end=$endtimeinepoch" | json_pp
You need to replace the variables $dropletid $starttimeinepoch & $endtimeinepoch
Sample output would look like this:
sandeshkotian@C02DFQNXMD6M ~ % curl -X GET \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $TOKEN" \
"https://api.digitalocean.com/v2/monitoring/metrics/droplet/cpu?host_id=257887712&start=1629003444&end=1629089844" | json_pp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 720 0 720 0 0 825 0 --:--:-- --:--:-- --:--:-- 824
{
"data" : {
"result" : [
{
"values" : [
[
1629089712,
"183181.33"
]
],
"metric" : {
"mode" : "idle",
"host_id" : "257887712"
}
},
{
"metric" : {
"host_id" : "257887712",
"mode" : "iowait"
},
"values" : [
[
1629089712,
"41.08"
]
]
},
{
"metric" : {
"mode" : "irq",
"host_id" : "257887712"
},
"values" : [
[
1629089712,
"0"
]
]
},
{
"values" : [
[
1629089712,
"962.2"
]
],
"metric" : {
"host_id" : "257887712",
"mode" : "nice"
}
},
{
"metric" : {
"mode" : "softirq",
"host_id" : "257887712"
},
"values" : [
[
1629089712,
"51.6"
]
]
},
{
"metric" : {
"mode" : "steal",
"host_id" : "257887712"
},
"values" : [
[
1629089712,
"8.5"
]
]
},
{
"metric" : {
"mode" : "system",
"host_id" : "257887712"
},
"values" : [
[
1629089712,
"1671.28"
]
]
},
{
"metric" : {
"mode" : "user",
"host_id" : "257887712"
},
"values" : [
[
1629089712,
"829354.72"
]
]
}
],
"resultType" : "matrix"
},
"status" : "success"
}
I hope this helps!
Best,
Sandesh Senior Customer Success Engineer
Yes you can, take a look at DigitalOcean’s monitoring API: https://docs.digitalocean.com/reference/api/api-reference/#tag/Monitoring
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.