[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: How to calculate Percentage CPU Usage

Thanks a lot.
I will calculate with your guide.

On Mon, Mar 28, 2016 at 4:33 PM, Matt Wringe <mwringe redhat com> wrote:
----- Original Message -----
> From: "David Dimas" <david dimas333 gmail com>
> To: dev lists openshift redhat com
> Sent: Friday, March 25, 2016 11:45:05 AM
> Subject: How to calculate Percentage CPU Usage
> Hello
> How are you?
> I am running curl command with your help successfully.
> Now I am going to calculate percentage CPU Usage. I have read this doc.
> [
> https://github.com/openshift/origin-metrics/blob/master/docs/hawkular_metrics.adoc#calcuating-percentage-cpu-usage
> ]
> In this guide, How can I get 'cpu/usage' and 'uptime'.
> I am running this command to get 'cpu/usage'.
> curl -k -H "Authorization: Bearer iCm-Mglj1TvBPd_VoJesqoqIAbVM2psZcXrykyshBU"
> -H "Hawkular-tenant: sample" -X GET
> https://hawkular-metrics.example.com/hawkular/metrics/counters/data?tags=descriptor_name:cpu/usage,pod_namespace:openshift-infra\&buckets=1\&start=`date
> -d -10minutes +%s%3N` | python -m json.tool
> Result is [{'min': 555115703.0, 'samples': 120, 'end': 1458837494033,
> 'median': 1391865412.971584, 'avg': 26785974599.89168, 'max':
> 144149182129.0, 'start': 1458836895027, 'empty': False}].
> so I think 'cpu/usage' is 'avg' value from this result. it this right?

The cpu/usage metric is a cumulative metric, which means that it always increases unless the container has been restarted (at which point it resets back to zero). For your example, the 'avg' value will give you the average over the 10 minute window you specified. Since the value is cumulative and always increasing (assuming no restarts, to find how much as used in that 10 minute window, you would take the max value minus the min value

> After this, I calculated the percentage of a CPU core used with the following
> function.
> %core = 'cpu/usage' / ('uptime' * 1000000)
> I am getting 0.0005564113359207296 as core result. Is this right value?

Simplifying a bit taking the result from the example above (and assuming no container restart)

'cpu/usage' as 'max' - 'min' = 143594066426 nanoseconds
cheating by taking 'uptime' as 'end' - 'start' milliseconds = 599006 milliseconds = 599006000000 nanoseconds

143594066426 nanoseconds / 599006000000 nanoseconds = 0.239720581 = 23.9720581%

So in the last 10 minutes, that container used 23.97% of a cpu core (assuming I didn't make some simple calculation error above)

> Please give me a word of advice. I need your help.
> Best Regards
> _______________________________________________
> dev mailing list
> dev lists openshift redhat com
> http://lists.openshift.redhat.com/openshiftmm/listinfo/dev

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]