From owner-freebsd-questions@FreeBSD.ORG Tue May 5 21:55:43 2009 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 8C5E0106567C for ; Tue, 5 May 2009 21:55:43 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from email1.allantgroup.com (email1.emsphone.com [199.67.51.115]) by mx1.freebsd.org (Postfix) with ESMTP id 437808FC1A for ; Tue, 5 May 2009 21:55:42 +0000 (UTC) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (dan.emsphone.com [199.67.51.101]) by email1.allantgroup.com (8.14.0/8.14.0) with ESMTP id n45Ltf9u015923 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 5 May 2009 16:55:41 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: from dan.emsphone.com (smmsp@localhost [127.0.0.1]) by dan.emsphone.com (8.14.3/8.14.3) with ESMTP id n45Ltfmi064987 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 5 May 2009 16:55:41 -0500 (CDT) (envelope-from dan@dan.emsphone.com) Received: (from dan@localhost) by dan.emsphone.com (8.14.3/8.14.3/Submit) id n45LtdNa064975; Tue, 5 May 2009 16:55:39 -0500 (CDT) (envelope-from dan) Date: Tue, 5 May 2009 16:55:39 -0500 From: Dan Nelson To: Maxim Khitrov Message-ID: <20090505215539.GE3371@dan.emsphone.com> References: <26ddd1750905051039y67bed9a5g6e1419b57b9e74fe@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <26ddd1750905051039y67bed9a5g6e1419b57b9e74fe@mail.gmail.com> X-OS: FreeBSD 7.2-STABLE User-Agent: Mutt/1.5.19 (2009-01-05) X-Virus-Scanned: ClamAV version 0.94.1, clamav-milter version 0.94.1 on email1.allantgroup.com X-Virus-Status: Clean X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-2.0.2 (email1.allantgroup.com [199.67.51.78]); Tue, 05 May 2009 16:55:41 -0500 (CDT) X-Scanned-By: MIMEDefang 2.45 Cc: Free BSD Questions list Subject: Re: Measuring CPU usage via SNMP X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 May 2009 21:55:43 -0000 In the last episode (May 05), Maxim Khitrov said: > Simple question - does the sum of differences in ssCpuRawIdle, > ssCpuRawUser, ssCpuRawNice, ssCpuRawKernel, and ssCpuRawInterrupt OIDs on > a FreeBSD 7.2 system give me total CPU allocation (i.e. is a constant)? > I've configured a few scripts to read these values from bsnmpd, store them > via rrdtool, and then generate a single graph with idle on the negative y > axis and everything else stacked on top. I want to make sure that no > other counter is missing from this ensemble and the ones listed do not > overlap. If either of those conditions is not met, my usage percent > calculation will not be accurate. > > The OIDs that I left out are: > > ssCpuRawSoftIRQ - documentation states that this is for Linux only, > but FreeBSD 7.2 does provide a value for it > ssCpuRawWait - always 0? > ssCpuRawSystem - seems to be a sum of ssCpuRawKernel and ssCpuRawInterrupt > > As far as I can tell, these three do not factor into the equation. The > only one I'm not sure about is ssCpuRawSystem. Is there ever a time when > it will not equal to ssCpuRawKernel + ssCpuRawInterrupt? The nice thing about open source software is you can read the source and see what's going on :) The FreeBSD kernel statclock() function: http://fxr.watson.org/fxr/source/kern/kern_clock.c#L442 updates the cp_time[] array, and it increments one of CP_NICE, CP_USER, CP_INTR, CP_SYS, and CP_IDLE on each tick. The Net-SNMP var_extensible_vmstat() function: http://net-snmp.svn.sourceforge.net/viewvc/net-snmp/trunk/net-snmp/agent/mibgroup/ucd-snmp/vmstat_freebsd2.c?revision=HEAD&view=markup#l_165 fetches that array and maps those indexes to CPURAWNICE, CPURAWUSER, CPURAWINTR, CPURAWKERNEL, and CPURAWIDLE. So fetching the matching ssCpuRaw* oids and totaling them up should always equal 100% cpu. -- Dan Nelson dnelson@allantgroup.com