[Shell] Linux monitor OS process and DB session
1.create table
SQL> create table mon_process
2 (ip_address varchar2(30),
3 hostname varchar2(20),
4 datetime varchar2(20),
5 all_process int,
6 running_process int,
7 sleeping_process int,
8 stopped_process int,
9 zmobie_process int,
10 all_session int,
11 act_session int
12 );
Table created.
2.shell script
如下指令碼的前提是在/etc/hosts配置的名字和db link上的名字是一樣的.這樣方便處理
[mon@oracle6 source]$ more mon_process
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=wlcspdb
datetime=`date +"%Y/%m/%d %H:%M:%S"`
STRS="oracle topaz standby wlcspdb1 wlcspdb2"
for STR in $STRS
do
OUTPUT=`echo "top -b -n 1 | grep Tasks" | ssh -Tq mon@$STR`
ALL_PROCESS=`echo $OUTPUT | awk '{print $2}'`
RUNNING_PROCESS=`echo $OUTPUT | awk '{print $4}'`
SLEEPING_PROCESS=`echo $OUTPUT | awk '{print $6}'`
STOPPED_PROCESS=`echo $OUTPUT | awk '{print $8}'`
ZMOBIE_PROCESS=`echo $OUTPUT | awk '{print $10}'`
SESSION=`$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
conn mon/mon
set heading off pagesize 0 feedback off verify off echo off;
select count(1),sum(decode(status,'ACTIVE',1,0)) from v\\$session@$STR;
exit
EOF`
ALL_SESSION=`echo $SESSION | awk '{print $1}'`
ACT_SESSION=`echo $SESSION | awk '{print $2}'`
IP_ADDRESS=`cat /etc/hosts | grep $STR | awk '{print $1}'`
$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
conn mon/mon
insert into mon_process values('$IP_ADDRESS','$STR','$datetime','$ALL_PROCESS','$RUNNING_PROCESS','$SLEEPING_PROCESS','$STOPPED_PROCESS','$ZMOBIE_PROCESS','$ALL_SESSION','$ACT_SESSION');
commit;
exit;
EOF
done
3.job
###############mon os process and db session#####################
* * * * * /home/mon/source/mon_process >> /home/mon/log/mon_process.log
SQL> create table mon_process
2 (ip_address varchar2(30),
3 hostname varchar2(20),
4 datetime varchar2(20),
5 all_process int,
6 running_process int,
7 sleeping_process int,
8 stopped_process int,
9 zmobie_process int,
10 all_session int,
11 act_session int
12 );
Table created.
2.shell script
如下指令碼的前提是在/etc/hosts配置的名字和db link上的名字是一樣的.這樣方便處理
[mon@oracle6 source]$ more mon_process
#!/bin/bash
export ORACLE_BASE=/u01/oracle
export ORACLE_HOME=$ORACLE_BASE/product/11.2.0/dbhome_1
export ORACLE_SID=wlcspdb
datetime=`date +"%Y/%m/%d %H:%M:%S"`
STRS="oracle topaz standby wlcspdb1 wlcspdb2"
for STR in $STRS
do
OUTPUT=`echo "top -b -n 1 | grep Tasks" | ssh -Tq mon@$STR`
ALL_PROCESS=`echo $OUTPUT | awk '{print $2}'`
RUNNING_PROCESS=`echo $OUTPUT | awk '{print $4}'`
SLEEPING_PROCESS=`echo $OUTPUT | awk '{print $6}'`
STOPPED_PROCESS=`echo $OUTPUT | awk '{print $8}'`
ZMOBIE_PROCESS=`echo $OUTPUT | awk '{print $10}'`
SESSION=`$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
conn mon/mon
set heading off pagesize 0 feedback off verify off echo off;
select count(1),sum(decode(status,'ACTIVE',1,0)) from v\\$session@$STR;
exit
EOF`
ALL_SESSION=`echo $SESSION | awk '{print $1}'`
ACT_SESSION=`echo $SESSION | awk '{print $2}'`
IP_ADDRESS=`cat /etc/hosts | grep $STR | awk '{print $1}'`
$ORACLE_HOME/bin/sqlplus -s /nolog << EOF
conn mon/mon
insert into mon_process values('$IP_ADDRESS','$STR','$datetime','$ALL_PROCESS','$RUNNING_PROCESS','$SLEEPING_PROCESS','$STOPPED_PROCESS','$ZMOBIE_PROCESS','$ALL_SESSION','$ACT_SESSION');
commit;
exit;
EOF
done
3.job
###############mon os process and db session#####################
* * * * * /home/mon/source/mon_process >> /home/mon/log/mon_process.log
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24237320/viewspace-2057850/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 6.Monitor Linux OS process and DB sessionLinuxSession
- Process Monitor Process (PMON) (121)
- [Shell] Linux monitor tablespace usageLinux
- [Shell] monitor filesystem
- A discussion of Dead Connection Detection, Resource Limits, V$SESSION, V$PROCESS and OS processesMITSession
- System Monitor Process (SMON) (120)
- session,connect,processSession
- ORACLE SESSION 和 PROCESSOracleSession
- linux||mac os如何自定義shell命令LinuxMac
- Shell入門:掌握Linux,OS X,Unix的Shell環境Linux
- process和session的總結Session
- v$session.PROCESS/V$process.SPID含義Session
- 關於v$process與v$session中process的理解Session
- 掌握Linux,OS X,Unix的Shell環境Linux
- [Shell] Monitor filesystem usage & delete expire filedelete
- How to Monitor UGA, PGA and Cursor Usage Per SessionSession
- oracle session和process的關係OracleSession
- oracle中session跟process的研究OracleSession
- MySQL 5.6 遭遇 OS bug INNODB MONITOR OUTPUT 事件MySql事件
- [Shell] monitor cpu&mem收集資料
- [Shell] monitor oracle database listener & instance statusOracleDatabase
- [Shell] monitor oracle alert.log file and sendmailOracleAI
- DB2 Event Monitor使用與查詢DB2
- 修改Oracle process 和 session 的方法--摘OracleSession
- Monitor RDBMS Session UGA and PGA Current And Maximum Usage Over TimeSession
- Procwatcher: Script to Monitor and Examine DB and Clusterware Pro-459694.1
- O/S-Error: (OS 33) The process cannot access the fileError
- v$process和v$session中欄位解釋Session
- 在Oracle中session和process的區別(轉)OracleSession
- process和session引數最大值估算方法Session
- oracle session和process的關係 .轉自CSDNOracleSession
- process/session/connection的一些問題Session
- Oracle中的Connect、session、process的區別OracleSession
- connection session process的聯絡與區別Session
- 跨 OS 平臺遷移 Oracle DBOracle
- Oracle Doc list involved with OS/DBOracle
- 3.linux monitor filesystemLinux
- [Shell] Monitor other host oracle instance alert.log and mailOracleAI