script to find load average on the OS Level
script to find load average on the OS Level.
Whenever there is any performance issue in a database or server level ,it is very common to verify what is the load on the server level.
Load average in Linux OS server level can be retrieved by using uptime command.
By doing this we will get the process details of any other database which is consuming/eating resources like CPU and memory and it was not noticed by respective application team or the DBAs.
Based the process details ,one can take necessary action .
In this article ,we will see how to get load average and process details automatically to our mail and how to run manually to get the output instantly.
Below commands and options have been used for preparing the script . uptime grep -o awk ‘{ print $3 }’ cut -f1 -d . ps -eo head coulmn -t mailx |
Script Details
Complete code is given below.
# Purpose:Script is used for checking load average and send mail
#!/bin/bash #script directory :/u01/app/oracle/scripts/OS #Script name : load_average.sh #Log file: /u01/app/oracle/scripts/OS/loadaverage.log ### SCRIPT_DIR=/u01/app/oracle/scripts/OS LOGFILE=loadaverage.log LOG=${SCRIPT_DIR}/$LOGFILE HOST=`hostname` echo “+++ Load Average ( If load is more than 10 ) +++” >> $LOG a=`uptime | grep -o ‘load average[s:][: ].*’ | awk ‘{ print $3 }’ | cut -f1 -d .` if [ ${a} -ge 10 ] rm $LOG |
Parameters to be passed
None
How to run this script manually ?
sh /u01/app/oracle/scripts/OS/load_average.sh
Sample output
+++ Load Average ( If load is more than 10 ) +++ Host orasrv01: Consuming High Load – 19 Getting High CPU Processes——- PID PPID CMD %MEM %CPU 121632 1 ora_j004_ORCLP 0.0 98.8 65562 31686 oracleORCLP (DESCRIPTION= 0.0 84.9 55061 31686 oracleORCLP (DESCRIPTION= 0.0 84.1 60944 31686 oracleORCLP (DESCRIPTION= 0.0 83.8 59012 31686 oracleORCLP (DESCRIPTION= 0.0 83.7 63094 31686 oracleORCLP (DESCRIPTION= 0.0 83.7 57027 31686 oracleORCLP (DESCRIPTION= 0.0 83.6 46888 31686 oracleORCLP (DESCRIPTION= 0.0 83.5 42365 31686 oracleORCLP (DESCRIPTION= 0.0 83.3 |
crontab entry
*/5 * * * * /u00/app/oracle/scripts/OS/load_average.sh > /u00/app/oracle/scripts/OS/load_average.log |
Note : Or we can also write as below . Meaning of these two options is to run a Cron Job Every 5 Minutes. But typing the whole list can be tedious and prone to errors.
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /u00/app/oracle/scripts/OS/load_average.sh > /u00/app/oracle/scripts/OS/load_average.log |
Note : Do not forget to give execute permission before we put the enty in crontab.
See also:
- script to monitor FRA space usage
- Script to setup RMAN active duplicate
- Script for DB Services and ASM Disk info
- http://oracle.com