Question

Get droplet metric data via the API

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.


Submit an answer


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!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Bobby Iliev
Site Moderator
Site Moderator badge
June 9, 2021
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

Sandesh Kotian
DigitalOcean Employee
DigitalOcean Employee badge
August 16, 2021

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel