I want to get CPU metrics of a droplet, I used the monitoring API also I used godo golang library I got the metrics for user, system… etc and I did this formula
totalCpu := (userCpu + systemCpu + stealCpu + softirqCpu + irqCpu + niceCpu + iowaitCpu + idleCpu) idle := (idleCpu * 100) / totalCpu cpuUsage := 100 - idleCpu
but the value is not like the one on the CPU graph on the website
thanks in advance
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!
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.
Click below to sign up and get $200 of credit to try our products over 60 days!
Your formula looks correct. I believe that the crucial part here is to pass the time frame that you want to get the CPU usage for by defining the
start: Timestamp to start metric window. Example:
end: Timestamp to end metric window. Example:
That way you can define which time period you want the CPU usage for, as if you don’t pass this you will get an average for the complete CPU usage.
Here is a simple bash script as an example:
This uses the same formula but gives you the CPU usage for the current time being. I just tested this and it seems to be reporting the same information as in the DigitalOcean Control panel.
Hope that this helps!