Question

Get droplet metric data via the API

Posted May 27, 2021 199 views
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.

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.

×
Submit an Answer
2 answers

Hey @RiversideRocks,

I believe that the monitoring data is not available via the DigitalOcean API as of the time being.

What I could suggest in the time being is to use a monitoring system like Nagios or Zabbix for example. You can find some tutorials on how to setup that here:

https://www.digitalocean.com/community/tags/monitoring

Regarding the API, the best thing to do to get your voice heard regarding this would be to head over to our Product Ideas board and post a new idea, including as much information as possible for what you’d like to see implemented.

https://ideas.digitalocean.com/

Hope that helps!
- 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