You are on page 1of 4

10/25/13 Document Display

Script for Checking the Grid Control Agent CPU, Memory & Threads Usage (Doc ID 464414.1)
Modified: 29-May-2013 Type: SCRIPT

In this Document

Purpose
Requirements
Configuring
Instructions
Script
Sample Output

APPLIES TO:

Enterprise Manager Base Platform - Version 10.2.0.1 to 11.1.0.1 [Release 10.2 to 11.1]
Linux x86
IBM AIX on POWER Systems (64-bit)
Oracle Solaris on SPARC (64-bit)
Linux x86-64
***Checked for relevance on 05-Oct-2011***

PURPOSE

The script is intended to provide an overview of the Agent CPU, Memory & Threads as well as of the running, ready
and scheduled collections. The script sample interval is 2 minutes. This can be customized.

REQUIREMENTS

This is a shell script. The only prerequisite is that the agent is running while running the script.

CONFIGURING

1. Download the Script or save its content in a file called "agent_snap.sh" under Agent's ORACLE_HOME/bin directory.

2. Change the permissions on the script to make it executable:

$ chmod u+x agent_snap.sh

INSTRUCTIONS

1. Make sure the $ORACLE_HOME environment variable is set to the agent oracle home before running the script:

$ export ORACLE_HOME=<path to agent home>

2. Make sure that the agent is running:

$ORACLE_HOME/bin/emctl status agent


https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=7x6o4ezyh_25 1/4
10/25/13 Document Display

3. Run the script in the background:

$ cd $ORACLE_HOME/bin
$ ./agent_snap.sh &

4.Verify that the agent_snap.log file is created under AGENT_HOME/sysman/log or


AGENT_HOME/<nodename>/sysman/log (for RAC agents) and populated with the expected information.

5. The script is set to collect data by default every 120 seconds. You can change the interval as required by modifying
the following line of the script:

sleep 120

Leave the script running for as long as you need to gather relevant information for the problem you are diagnosing.
Note that you can customize the script as needed to run other commands to capture additional information every 120
seconds.

6. To stop the script - identify the process id and kill it:

$ ps -ef | grep agent_snap.sh


$ kill -9 <pid of agent_snap.sh>

Note: The script was tested on Linux, Oracle Solaris & AIX. It may need customization on other Unix platforms.

CAUTION

This sample code is provided for educational purposes only, and is not supported by Oracle Support. It has been tested
internally, however, we do not guarantee that it will work for you. Ensure that you run it in your test environment
before using.

SCRIPT

1. agent_snap.sh for Linux (download)

#!/bin/sh

emhome=`$ORACLE_HOME/bin/emctl getemhome | tail -1 | awk 'BEGIN {FS="="} {print $2}'`


echo -e "date\t\tcpu%\tvmem\trmem\tthreads\trunning\tready\tscheduled" >>
$emhome/sysman/log/agent_snap.log
while [ 2 -gt 1 ]
do

pid=`$ORACLE_HOME/bin/emctl status agent|grep "Agent Process ID" | awk '{print $5}'`


dateStr=`date "+%m/%d %H:%M:%S"`
cpu=`ps -p $pid -o "pcpu"| tail -1 | sed 's/^[ ]*//'`
threads=`ps -p $pid -o "thcount"| tail -1 | sed 's/^[ ]*//'`
vmem=`ps -o vsz $pid | tail -1 | sed 's/^[ ]*//'`
https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=7x6o4ezyh_25 2/4
10/25/13 Document Display
rmem=`ps -o rss $pid | tail -1 | sed 's/^[ ]*//'`

$ORACLE_HOME/bin/emctl status agent scheduler > /tmp/snapschedule


running_line=`grep -n "Running entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
ready_line=`grep -n "Ready entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
scheduled_line=`grep -n "Scheduled entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print
$1}'`
final_line=`grep -n "Agent is" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
running=`expr $ready_line - $running_line - 1`;
ready=`expr $scheduled_line - $ready_line - 1`;
scheduled=`expr $final_line - $scheduled_line - 2`;

echo -e "$dateStr\t$cpu\t$vmem\t$rmem\t$threads\t$running\t$ready\t$scheduled" >>


$emhome/sysman/log/agent_snap.log

sleep 120
done

2. agent_snap.sh for Oracle Solaris (download)

#!/bin/sh

emhome=`$ORACLE_HOME/bin/emctl getemhome | tail -1 | awk 'BEGIN {FS="="} {print $2}'`


echo "date\t\tcpu\tvmem\trmem\tthreads\trun\tready\tsched" >>
$emhome/sysman/log/agent_snap.log
while [ 2 -gt 1 ]
do
pid=`$ORACLE_HOME/bin/emctl status agent|grep "Agent Process ID" | awk '{print $5}'`
dateStr=`date "+%m/%d %H:%M:%S"`
cpu=`ps -p $pid -o "pcpu"| tail -1 | sed 's/^[ ]*//'`
threads=`ps -p $pid -o "nlwp"| tail -1 | sed 's/^[ ]*//'`
vmem=`ps -p $pid -o "vsz" | tail -1 | sed 's/^[ ]*//'`
rmem=`ps -p $pid -o "rss" | tail -1 | sed 's/^[ ]*//'`
$ORACLE_HOME/bin/emctl status agent scheduler > /tmp/snapschedule

running_line=`grep -n "Running entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`


ready_line=`grep -n "Ready entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
scheduled_line=`grep -n "Scheduled entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print
$1}'`
final_line=`grep -n "Agent is" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
running=`expr $ready_line - $running_line - 1`;
ready=`expr $scheduled_line - $ready_line - 1`;
scheduled=`expr $final_line - $scheduled_line - 2`;

echo "$dateStr\t$cpu\t$vmem\t$rmem\t$threads\t$running\t$ready\t$scheduled" >>


$emhome/sysman/log/agent_snap.log

sleep 120
done

3. agent_snap.sh for AIX (download)

#!/bin/sh

https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=7x6o4ezyh_25 3/4
10/25/13 Document Display
emhome=`$ORACLE_HOME/bin/emctl getemhome | tail -1 | awk 'BEGIN {FS="="} {print $2}'`
echo "date\t\tcpu\tvmem\trmem\tthreads\trun\tready\tsched" >>
$emhome/sysman/log/agent_snap.log
while [ 2 -gt 1 ]
do
pid=`$ORACLE_HOME/bin/emctl status agent|grep "Agent Process ID" | awk '{print $5}'`
dateStr=`date "+%m/%d %H:%M:%S"`
cpu=`ps -p $pid -o "pcpu"| tail -1 | sed 's/^[ ]*//'`
threads=`ps -p $pid -o "thcount"| tail -1 | sed 's/^[ ]*//'`
vmem=`ps v $pid | tail -1 | sed 's/^[ ]*//' | awk '{print $6}'`
rmem=`ps v $pid | tail -1 | sed 's/^[ ]*//' | awk '{print $7}'`
$ORACLE_HOME/bin/emctl status agent scheduler > /tmp/snapschedule

running_line=`grep -n "Running entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`


ready_line=`grep -n "Ready entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
scheduled_line=`grep -n "Scheduled entries" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print
$1}'`
final_line=`grep -n "Agent is" /tmp/snapschedule | awk 'BEGIN {FS=":"} {print $1}'`
running=`expr $ready_line - $running_line - 1`;
ready=`expr $scheduled_line - $ready_line - 1`;
scheduled=`expr $final_line - $scheduled_line - 2`;

echo "$dateStr\t$cpu\t$vmem\t$rmem\t$threads\t$running\t$ready\t$scheduled" >>


$emhome/sysman/log/agent_snap.log

sleep 120
done

SAMPLE OUTPUT

This is a sample output:

date cpu vmem rmem threads run ready sched


02/12 13:06:50 0.1 84616 54692 30 0 0 73
02/12 13:08:54 0.1 84616 54608 23 0 0 73
02/12 13:10:58 0.1 84616 54036 29 0 0 73

The agent_snap.log file will show the timestamp, CPU usage, virtual memory usage, physical memory usage and
number of threads spawned by the agent process. It will also show the number of running, ready and scheduled
collection items. The latter are based on the 'emctl status agent scheduler' and can show interesting trends in the
number of running metric collections - that can then be linked to what we see in terms of resource consumption.

https://support.oracle.com/epmos/faces/SearchDocDisplay?_adf.ctrl-state=7x6o4ezyh_25 4/4

You might also like