cpu utilization break down via sysctl

David Wolfskill david at catwhisker.org
Mon Aug 4 16:53:51 UTC 2014


On Mon, Aug 04, 2014 at 07:40:36PM +0300, Stefan Parvu wrote:
> > Sure; I've done the data acquisition with sysctl & awk, then
> > post-processed that with a bit of Perl.  I wrote some code in R to
> > generate graphs....  I did some similar stuff using RRDTool a whlie
> > back.
> 
> Im planning in using BSD::Sysctl to fetch all needed values.

For my data acquisition, I wasn't assuming that Perl would be available
-- I therefore intentionally restricted myself to tools in base
FreeBSD.  Your situation is, of course, almost certainly different. :-)

> ...
> I see. Cool. If I understood right these will be the break down for 4 vcpu system:
> 
> $ sysctl kern.cp_times
> kern.cp_times: 28845 2060 22253 1805 1197920 27677 1477 22399 2109 1199180 32342 1649 19499 894 1198458 29670 1678 20324 1471 1199699
> 
> which maps to:
> 
> time1: cpu0: user_28845: nice_2060: system_22253: intr_1805: idle_1197920
> time1: cpu1: user_27677: nice_1477 system_22399 intr_2109: idle_1199180 
> time1: cpu2: user_32342: nice_1649: system_19499: intr_894: idle_1198458
> time1: cpu3 user_29670: nice_1678: system_20324: intr_1471: idle_1199699

Err... Well... Maybe?  The numeric values are the values of the counters
at the time the information was acquired.

I'd probably depict them more as:

       user  nice system  intr     idle
cpu0: 28845  2060  22253  1805  1197920
cpu1: 27677  1477  22399  2109  1199180
cpu2: 32342  1649  19499   894  1198458
cpu3: 29670  1678  20324  1471  1199699

> ..
> Right I need to do delta between 2 readings to get the correct values.

Yes.

> Same as in KSTAT in Solaris perl interface. 

It's been a long time since I did anything with Solaris. :-}

> One more check here: 
> 
>  CPU_Utilization = User + System + Nice + Intr ? 

If you mean total non-idle CPU, yes.  For determining available CPU, you
need to include idle.

> Many thanks indeed. I need to experiment with these ...

Glad to help; the source for top(1) can also be instructive.

Peace,
david
-- 
David H. Wolfskill				david at catwhisker.org
Taliban: Evil cowards with guns afraid of truth from a 14-year old girl.

See http://www.catwhisker.org/~david/publickey.gpg for my public key.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 949 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20140804/492e635d/attachment.sig>


More information about the freebsd-hackers mailing list