Monitoring CPU usage within UNIX is easy with the vmstat
utility and vmstat can be used to track CPU usage via the ?runqueue?
column. Whenever the us (user) plus sy
(system) times approach 100, the CPUs are operating at full capacity. For
details, see the fallacy of
100% CPU utilization.
You can use the "ps" command to find the top CPU
consumers on a UNIX/Linux server. Below we find the Process ID which
is hogging CPU/Memory:
$ ps -e -o
pcpu,pid,user,tty,args |grep -i oracle|sort -n -k 1 -r|head
When monitoring CPU
utilization, it is not a cause for concern when the user + system CPU values
approach 100 percent. This just means that the CPUs are working to their full
potential. The only metric that identifies a CPU bottleneck is when the run
queue (r value) exceeds the number of CPUs on the server.
vmstat 5 1
kthr memory page faults cpu
----- ----------- ------------------------ ------------ -----------
r b avm fre re pi po fr sr cy in sy cs us sy id wa
3 0 217485 386 0 0 0 4 14 0 202 300 210 20 75 3 2
Long term monitoring of CPU consumption
Within UNIX, the OS is geared to drive CPU consumption to
100%, so the best way to monitor CPU usage is by tracking the ?r? column in
vmstat. See these notes on
monitoring Oracle CPU consumption for details.
This script will store CPU usage every five minutes and store the results in
an Oracle table, perfect for time-series monitoring of UNIX/Linux CPU usage.
Once stored in a table, standard SQL can be used to monitor
CPU usage and display those times when the runqueue exceed the CPU count of the
UNIX/Linux server.
Inside Oracle, you can display CPU for any
Oracle user session with this script:
select
ss.username,
se.SID,
VALUE/100 cpu_usage_seconds
from
v$session ss,
v$sesstat se,
v$statname
sn
where
se.STATISTIC# = sn.STATISTIC#
and
NAME like '%CPU used by this
session%'
and
se.SID = ss.SID
and
ss.status='ACTIVE'
and
ss.username is not null
order by VALUE desc;
For complete scripts to monitor CPU, see the
Oracle script download.