一、配置
1.1 zabbix部分配置
ListenPort=10051
LogFile=/tmp/zabbix_server.log
DebugLevel=3
DBHost=192.168.0.55
DBName=dbname
DBUser=zabbix
DBPassword=mantou123
DBPort=1521
StartPollers=10
StartDiscoverers=5
HousekeepingFrequency=3
MaxHousekeeperDelete=10000
Timeout=4
AlertScriptsPath=/usr/local/zabbix-server/share/zabbix/alertscripts
LogSlowQueries=3000
1.2 orabbix配置
#comma separed list of Zabbix servers
ZabbixServerList=ZabbixServer1
#zabbix服务器列表,如果你没有zabbix proxy,只有一个zabbix服务器就不用管
ZabbixServer1.Address=127.0.0.1
#zabbix-service端地址
ZabbixServer1.Port=10051
#zabbix端口号
##ZabbixServer2.Address=IP_ADDRESS_OF_ZABBIX_SERVER
##ZabbixServer2.Port=PORT_OF_ZABBIX_SERVER
#pidFile
OrabbixDaemon.PidFile=./logs/orabbix.pid
#frequency of item's refresh
OrabbixDaemon.Sleep=300
#MaxThreadNumber should be >= than the number of your databases
OrabbixDaemon.MaxThreadNumber=100
#put here your databases in a comma separated list
DatabaseList=10.0.0.201
#Oracle数据库名字列表,zabbix监控中的主机名必须是这里定义的名字,
否则无法监控
#Configuration of Connection pool
#if not specified Orabbis is going to use default values (hardcoded)
#Maximum number of active connection inside pool
DatabaseList.MaxActive=10
#The maximum number of milliseconds that the pool will wait
#(when there are no available connections) for a connection to be returned
#before throwing an exception, or <= 0 to wait indefinitely.
DatabaseList.MaxWait=100
DatabaseList.MaxIdle=1
#define here your connection string for each database
10.0.0.201.Url=jdbc:oracle:thin:@10.0.0.201:1521:orcl
#databaselist后的名字,后加上要监控的oracle服务器的IP地址,端口号和实例名
10.0.0.201.User=zabbix2
10.0.0.201.Password=zabbix
#访问数据库的用户名和密码
#Those values are optionals if not specified Orabbix is going to use the general values
10.0.0.201.MaxActive=10
10.0.0.201.MaxWait=100
10.0.0.201.MaxIdle=1
10.0.0.201.QueryListFile=./conf/query.props
二、监控配置
2.1 zabbix+orabbit实现监控oracle
个人感觉是没什么用的插件,完全可以使用odbc实现,orabbix只能实现类似K:V单值的数据获取,基本无用,且对于新版本的oracle,如19c(大概吧,这项目好几年前做的了)还需要替换orabbix的连数据库的插件
之前的按照排错文档,可以参考:【有道云笔记】orabbix
https://note.youdao.com/s/U5GgIMdP
2. 通过自动发现(discovery)+shell脚本监控Oracle表空间、磁盘组
zabbix的discovery主要就是,将数据json化,然后前端配置discovery规则
- 通过shell脚本读取所有表空间容量空间数据,存储到指定文件
下面的sql,是DBA包装过的,所以我的sql很简单只是查了个视图
source /home/oracle/.bash_profile
sqlplus -S "dbsnmp/xxxxxx" > /tmp/tablespace.log<<EOF
set feedback off
set linesize 200
set pagesize 100
select t.tablespace_name,t.total_mb,t.free_mb,t.used_mb from sfdba.v_zabbix_spsize t;
EOF
- 读去上面生成的表空间文件,解析成json格式
#!/bin/bash
TABLESPACE=`cat /tmp/tablespace.log |awk '{print$1}'|awk 'NR>3{print}'`
COUNT=`echo "$TABLESPACE" |wc -l`
INDEX=0
echo '{"data":['
echo "$TABLESPACE" | while read LINE; do
echo -n '{"{#TABLENAME}":"'$LINE'"}'
INDEX=`expr $INDEX + 1`
if [ $INDEX -lt $COUNT ]; then
echo ','
fi
done
echo ']}'
// 按照现在看,以上步骤如果会Python等脚本,会更简单,没必要好几个脚本又放crontab跑的
该脚本获取所有的表空间名称,输出为json,这样就可以配置自动发现啦,在zabbix前端上
- 根据表空间名称获取相应的指标
这个脚本是放在zabbix-agent的自定义指标参数里执行的,discovery自动创建的监控项作为参数调用该脚本
#!/bin/bash
ZBX_REQ_DATA_TAB="$1"
EQ_DATA="$2"
SOURCE_DATA=/tmp/tablespace.log
case $2 in
TOTAL_MB)
grep -w "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $2}';;
FREE_MB)
grep -w "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $3}';;
USED_MB)
grep -w "$ZBX_REQ_DATA_TAB" $SOURCE_DATA |awk '{print $4}';;
*)
echo $ERROR_WRONG_PARAM; exit 1;;
esac
exit 0
continue…