Scale up as you grow — whether you're running one virtual machine or ten thousand.

From GPU-powered inference and Kubernetes to managed databases and storage, get everything you need to build, scale, and deploy intelligent applications.

I followed this docs: https://docs.digitalocean.com/reference/api/api-reference/#operation/monitoring_get_DropletCpuMetrics And I got data like this:
{
"status": "success",
"data": {
"resultType": "matrix",
"result": [
{
"metric": {
"host_id": host_id,
"mode": "idle"
},
"values": [
[
1708955160,
"836680.1399999999"
],
[
1708955280,
"836918.48"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "iowait"
},
"values": [
[
1708955160,
"529.21"
],
[
1708955280,
"529.51"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "irq"
},
"values": [
[
1708955160,
"0"
],
[
1708955280,
"0"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "nice"
},
"values": [
[
1708955160,
"18.490000000000002"
],
[
1708955280,
"18.490000000000002"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "softirq"
},
"values": [
[
1708955160,
"24.68"
],
[
1708955280,
"24.689999999999998"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "steal"
},
"values": [
[
1708955160,
"102.99000000000001"
],
[
1708955280,
"103.00999999999999"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "system"
},
"values": [
[
1708955160,
"759.1199999999999"
],
[
1708955280,
"759.5699999999999"
]
]
},
{
"metric": {
"host_id": host_id,
"mode": "user"
},
"values": [
[
1708955160,
"948.6099999999999"
],
[
1708955280,
"949.23"
]
]
}
]
}
}
How can I calculate the cpu% usage? this is my function:
def get_cpu_usage(host_id, start_time, end_time, token)
uri = URI("https://api.digitalocean.com/v2/monitoring/metrics/droplet/cpu")
uri.query = URI.encode_www_form({ host_id: host_id, start: start_time, end: end_time })
request = Net::HTTP::Get.new(uri)
request["Content-Type"] = "application/json"
request["Authorization"] = "Bearer #{token}"
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
http.request(request)
end
if response.code == '200'
data = JSON.parse(response.body)
else
puts "Failed to fetch droplet metrics. HTTP Error #{response.code}: #{response.message}"
end
end
fee71e5946274084b0c69c0f36c441
ebeecroft
Darion Wood
endtoendpaper
Mitcheljager
Kainat Naz
Alexzander Tetreault
erickhansx
Arslan Ali
sergeykhval
ephraim784fb14b13cd7ac613a
coreymartella