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

Re: How to calculate Percentage CPU Usage



Please make sure to include the list when responding. There are other people who may have the same issue and may want to reference this.

----- Original Message -----
> From: "David Dimas" <david dimas333 gmail com>
> To: "Matt Wringe" <mwringe redhat com>
> Sent: Wednesday, March 30, 2016 5:04:54 PM
> Subject: Re: How to calculate Percentage CPU Usage
> 
> Thanks a lot for your answer.
> I am getting this value now. [{'max': 76312576.0, 'samples': 120, 'start':
> 1459371158160, 'median': 47266353.998971954, 'min': 44068864.0, 'avg':
> 55078570.666666664, 'end': 1459371757731, 'empty': False}]
> So Can I use this data directly?
> for instance, max 76312576bytes.(for 1 hours)

What this means is that for that time frame, the average memory usage was 55078570 bytes, the minimum memory usage was 44068864, and the maximum usage was 76312576

If you want to do something like graph the usage over an hour, it would be best to request multiple buckets for your time frame and then graph the average of those buckets. That is what the console is currently doing.

> Regards
> 
> On Wed, Mar 30, 2016 at 8:42 PM, Matt Wringe <mwringe redhat com> wrote:
> 
> > ----- Original Message -----
> > > From: "David Dimas" <david dimas333 gmail com>
> > > To: "Matt Wringe" <mwringe redhat com>
> > > Sent: Monday, March 28, 2016 11:50:13 PM
> > > Subject: Re: How to calculate Percentage CPU Usage
> > >
> > > Hi, Matt.
> > > how are you?
> > > I am calculating Percentage CPU Usage with your help.
> > > I am going to calculate Memory Usage now.
> > > Can you please explain how to calculate this?
> >
> > Memory usage is a 'gauge' type metric (eg it can increase or decrease at
> > anytime) and is a quite different than the cpu usage which is a
> > 'cumulative' metric (eg is always increasing). Think of it as the
> > difference between a speedometer and an odometer in a car.
> >
> > For memory usage, its actually much easier. The memory usage value is how
> > much memory (in bytes) is being used at that particular time. You don't
> > need to do any fancy calculations, you can directly use it.
> >
> > >
> > > Regards.
> > > David
> > >
> > > On Mon, Mar 28, 2016 at 7:24 PM, David Dimas <david dimas333 gmail com>
> > > wrote:
> > >
> > > > Thanks a lot.
> > > > I will calculate with your guide.
> > > > Regards
> > > >
> > > > 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
> > > >> <
> > https://hawkular-metrics.example.com/hawkular/metrics/counters/data?tags=descriptor_name:cpu/usage,pod_namespace:openshift-infra%5C&buckets=1%5C&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]