Jason Schoonover 2007-04-23 http://unnoc.org Process CPU Usage This document will quickly explain how the CPU usage is collected per process. For any given process that Unnoc finds (either via the proc{} directive for Windows, or via snmpd.conf for Unix servers), it will do a lookup corresponds to the particular process in the HOST-RESOURCES-MIB MIB. Particularly, the hrSWRunPerfCPU MIB. Here is a description of what the hrSWRunPerfCPU MIB presents: "The number of centi-seconds of the total system's CPU resources consumed by this process. Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time." So Unnoc will connect to a server, read the list of processes, grab the PerfCPU counter and then subtract the previous PerfCPU counter value from the current one. This gives us the amount of time, in centi-seconds, that this particular process has used from the last read to the current read. So now we have the amount of centi-seconds used. We'll call this cpu_used. At the same time, we are also collecting the uptime, in centiseconds (or milliseconds, for Windows machines). And we take that value and subtract the previous uptime value from the current one. This will give us approximately how much time has passed between the previous read and the current read. So now we have the amount of time that has passed between the previous and current read. Well call this cpu_avail. So now we simply use the following formula: cpu_percentage = (cpu_used / cpu_avail) * 100 That is, we take the total CPU used and then divide that into the total amount of cpu centiseconds that we available, and that will give us approximately how much cpu centiseconds were used by this particular process. There are a few caveats, the big one is the note given in the MIB explanation, particularly the part that says: "Note that on a multi-processor system, this value may increment by more than one centi-second in one centi-second of real (wall clock) time." That makes the values not so accurate. However, this will give us an approximate value of a CPU. If you see a process using 50-something percent, then chances are, that means that it's using alot of your CPU. For multiple processes (for instance, multiple imapd processes), Unnoc simply adds up all the processes's memory/CPU usage, and will use the total to do all calculations. Again, this CPU number is approximate, but can help considerably when troubleshotting sluggish machines, or simply trying to optimize your machine. vim:tw=72:wm=1