功能
通过nrpe运行本地check_oracle_health脚本,监控oracle相关性能参数
安装perl模块
cpan DBI
cpan DBD::Oracle
数据库访问权限
用管理员帐号通过sqlplus登录数据库,添加nagios用户及访问权限
1
2
3
4
5
6
7
8
CREATE USER nagios IDENTIFIED BY nagios;
GRANT CREATE SESSION TO nagios;
GRANT SELECT any dictionary TO nagios;
GRANT SELECT ON V_$SYSSTAT TO nagios;
GRANT SELECT ON V_$INSTANCE TO nagios;
GRANT SELECT ON V_$LOG TO nagios;
GRANT SELECT ON SYS.DBA_DATA_FILES TO nagios;
GRANT SELECT ON SYS.DBA_FREE_SPACE TO nagios;
下载安装
wget
http://labs.consol.de/wp-content/uploads/2010/10/check_oracle_health-1.6.6.1.tar.gz
tar xvfz check_oracd
cd check_oracle_health-1.6.6.1
./configure
make && make install
配置nrpe
vim /usr/local/nagios/etc/nrpe.d/oracle.cfg
command[check_oracle_health_hit]=/usr/local/nagios/libexec/check_oracle_health.pl --connect $ARG1$ --username $ARG2$ --password $ARG3$ --warning $ARG4$ --critical $ARG5$ --mode $ARG6$
command[check_oracle_health_usage]=/usr/local/nagios/libexec/check_oracle_health.pl --connect $ARG1$ --username $ARG2$ --password $ARG3$ --warning $ARG4$ --critical $ARG5$ --mode tablespace-usage --tablespace $ARG6$
更新nrpe启动脚本
vim /etc/init.d/nrpe
添加oracle环境变量,注意与安装oracle数据时所设置环境一致
ORACLE_BASE=/home/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/10.2.0/db_1; export ORACLE_HOME
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
重启nrpe服务
service nrpe restart
如果不设置以上环境变量,nagios用户运行监控脚本会报错
CRITICAL – cannot connect to Instanz.WORLD.
install_driver(Oracle) failed: Can’t load
‘/usr/lib/perl5/site_perl/5.8.8/x86_64-linux-thread-multi/auto/DBD/Oracle/Oracle.so’
for module DBD::Oracle: libnnz10.so: cannot open shared object
file: No such file or directory at
/usr/lib/perl5/5.8.8/x86_64-linux-thread-multi/DynaLoader.pm line
230. at (eval 16) line 3 Compilation failed in require at (eval 16)
line 3. Perhaps a required shared library or dll isn’t installed
where expected at /usr/local/nagios/libexec/check_oracle_health
line 3977
nagios配置脚本
checkcommands.cfg
1
2
3
4
5
6
7
8
9
10
define command {
command_name check_remote_oracle_hit
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$
;command_example !check_oracle_health_hit!orcl!nagios!nagios!90:!80:!sga-data-buffer-hit-ratio
}
define command {
command_name check_remote_oracle_tablespace
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$ -a $ARG2$ $ARG3$ $ARG4$ $ARG5$ $ARG6$ $ARG7$
;command_example !check_oracle_health_usage!orcl!nagios!nagios!80!90!USERS
serviceTemplates.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
define service {
name oracle_pga-in-memory-sort-ratio
service_description oracle_pga-in-memory-sort-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!80:!70:!pga-in-memory-sort-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_sga-data-buffer-hit-ratio
service_description oracle_sga-data-buffer-hit-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!80:!70:!sga-data-buffer-hit-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_sga-dictionary-cache-hit-ratio
service_description oracle_sga-dictionary-cache-hit-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!80:!70:!sga-dictionary-cache-hit-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_sga-latches-hit-ratio
service_description oracle_sga-latches-hit-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!80:!70:!sga-latches-hit-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_sga-library-cache-hit-ratio
service_description oracle_sga-library-cache-hit-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!80:!70:!sga-library-cache-hit-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_sga-shared-pool-reload-ratio
service_description oracle_sga-shared-pool-reload-ratio
use generic-service
check_command check_remote_oracle_hit!check_oracle_health_hit!orcl!nagios!nagios!1!10!sga-shared-pool-reload-ratio
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_tablespace_sysaux
service_description oracle_tablespace_sysaux
use generic-service
check_command check_remote_oracle_tablespace!check_oracle_health_usage!orcl!nagios!nagios!80!90!SYSAUX
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_tablespace_system
service_description oracle_tablespace_system
use generic-service
check_command check_remote_oracle_tablespace!check_oracle_health_usage!orcl!nagios!nagios!80!90!SYSTEM
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_tablespace_temp
service_description oracle_tablespace_temp
use generic-service
check_command check_remote_oracle_tablespace!check_oracle_health_usage!orcl!nagios!nagios!80!90!TEMP
register 0
;TEMPLATE-HOST-LINK app-oracle
}
define service{
name oracle_tablespace_users
service_description oracle_tablespace_users
use generic-service
check_command check_remote_oracle_tablespace!check_oracle_health_usage!orcl!nagios!nagios!80!90!USERS
register 0
;TEMPLATE-HOST-LINK app-oracle
}
hostTemplates.cfg
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
define host{
name app-oracle
use generic-host
alias app-oracle
register 0
}
define host{
name generic-host
alias generic-host
check_command check_host_alive
max_check_attempts 3
active_checks_enabled 1
passive_checks_enabled 0
check_period 24x7
contact_groups Supervisors
notification_period 24x7
notification_options d,u,r,f,s
notifications_enabled 1
register 0
}
检测
/usr/local/nagios/libexec/check_nrpe -H 10.60.30.15 -c check_oracle_health_hit -a orcl nagios nagios 90: 80: pga-in-memory-sort-ratio
OK - PGA in-memory sort ratio 100.00% | pga_in_memory_sort_ratio=100.00%;90:;80:;0;100
/usr/local/nagios/libexec/check_nrpe -H 10.60.30.15 -c check_oracle_health_usage -a orcl nagios nagios 80 70 SYSAUX
OK - tbs SYSAUX usage is 0.88% | 'tbs_sysaux_usage_pct'=0.88%;80;70 'tbs_sysaux_usage'=287MB;26214;22937;0;32767 'tbs_sysaux_alloc'=290MB;;;0;32767
附: check-oracle-install.sh
ubuntu 9.10 下oracle监控安装脚本,必须在oracle数据库服务器上安装
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#DL_SERVER="www.puppeter.cn"
SRC_DIR="/home/op_system"
INSTALL_DIR="/usr/local"
INIT_DIR="/etc/init.d"
DBORACLE_FILE="DBD-Oracle-1.27"
ORACLE_CLIENT_FILE="instantclient_11_2"
TNSNAME_FILE="tnsnames.ora"
NRPE_INIT_FILE="nrpe"
ORACLE_SERVER="127.0.0.1"
ORACLE_SID="orcl"
LINE="##########################################"
echo "$LINE"
echo
echo "Oracle Client Installation Script"
echo
echo " version 1.0"
echo
echo "$LINE"
echo
read -p "Please Input DOWNLOAD_SERVER IP or Domain Name: " DL_SERVER
echo "DOWNLOAD_SERVER IP is $DL_SERVER."
echo
echo "$LINE"
echo "Section: Installing Oracle Client"
echo "$LINE"
[ ! -d $SRC_DIR ] && mkdir -p $SRC_DIR
cd $SRC_DIR
wget http://$DL_SERVER/$ORACLE_CLIENT_FILE.tar.gz
tar xvfz $ORACLE_CLIENT_FILE.tar.gz > /dev/null 2>&1
sudo mv $ORACLE_CLIENT_FILE $INSTALL_DIR
sudo chown -R zoomi:zoomi $INSTALL_DIR/$ORACLE_CLIENT_FILE
read -p "Please Input ORACLE SERVER IP Address: " ORAClE_SERVER
echo "ORACLE_SERVER IP is $ORACLE_SERVER."
read -p "Please Input ORACLE_SID Name: " ORACLE_SID
echo "ORACLE_SID Name is $ORACLE_SID."
sed -i "s/127.0.0.1/$ORACLE_SERVER/g" $INSTALL_DIR/$ORACLE_CLIENT_FILE/$TNSNAME_FILE
sed -i "s/orcl/$ORACLE_SID/g" $INSTALL_DIR/$ORACLE_CLIENT_FILE/$TNSNAME_FILE
echo ". Oracle Cliient installed. ok!"
echo
echo "$LINE"
echo "Section: Installing perl module DB-ORACLE"
echo "$LINE"
sudo apt-get -y install perl-doc libdbi-perl libaio1 libaio-dev > /dev/null 2>&1
sudo wget http://$DL_SERVER/$DBORACLE_FILE.tar.gz > /dev/null 2>&1
tar xvfz $DBORACLE_FILE.tar.gz > /dev/null 2>&1
cd $DBORACLE_FILE
export ORACLE_HOME=/usr/local/$ORACLE_CLIENT_FILE
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export SQLPATH=$ORACLE_HOME
export TNS_ADMIN=$ORACLE_HOME
export ORACLE_SID=orcl
perl Makefile.PL > /dev/null 2>&1
make > /dev/null 2>&1
sudo make install > /dev/null 2>&1
cd $INIT_DIR
sudo mv $NRPE_INIT_FILE $NRPE_INIT_FILE.bak
sudo wget http://$DL_SERVER/$NRPE_INIT_FILE > /dev/null 2>&1
sudo chmod 755 $NRPE_INIT_FILE > /dev/null 2>&1
sudo $INIT_DIR/$NRPE_INIT_FILE restart > /dev/null 2>&1
echo ". Nrpe installed. ok!"
sudo rm -rf $SRC_DIR > /dev/null 2>&1
echo
exit 0
nrpe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: nagios-nrpe-server
# Required-Start: $local_fs $remote_fs $syslog $named $network $time
# Required-Stop: $local_fs $remote_fs $syslog $named $network
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/Stop the Nagios remote plugin execution daemon
### END INIT INFO
# 添加oracle信息,使nagios用户可以调用oracle数据库
export ORACLE_HOME=/usr/local/instantclient_11_2
export PATH=$PATH:$ORACLE_HOME
export LD_LIBRARY_PATH=$ORACLE_HOME
export SQLPATH=$ORACLE_HOME
export TNS_ADMIN=$ORACLE_HOME
export ORACLE_SID=orcl
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/nagios/bin/nrpe
NAME=nagios-nrpe
DESC=nagios-nrpe
CONFIG=/usr/local/nagios/etc/nrpe.cfg
test -x $DAEMON || exit 0
if ! [ -x "/lib/lsb/init-functions" ]; then
. /lib/lsb/init-functions
else
echo "E: /lib/lsb/init-functions not found, lsb-base (>= 3.0-6) needed"
exit 1
fi
if [ "$NICENESS" ]; then NICENESS="-n $NICENESS"; fi
set -e
case "$1" in
start)
if [ "$INETD" = 1 ]; then
exit 1
fi
log_daemon_msg "Starting $DESC" "$NAME"
start_daemon $NICENESS $DAEMON -c $CONFIG -d $DAEMON_OPTS
log_end_msg $?
;;
stop)
log_daemon_msg "Stopping $DESC" "$NAME"
start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
log_end_msg $?
;;
reload|force-reload)
log_daemon_msg "Reloading $DESC configuration files" "$NAME"
start-stop-daemon --stop --signal HUP --quiet --exec $DAEMON
log_end_msg $?
;;
restart)
$0 stop
sleep 1
$0 start
;;
*)
log_failure_msg "Usage: $N {start|stop|restart|reload|force-reload}"
exit 1
;;
esac
exit 0