本文共 2897 字,大约阅读时间需要 9 分钟。
使用python脚本编写脚本,监控oracle连接数;连接Oracle需要安装cx_Oracle模块,安装完成后检查是否正常,没有任何信息返回即正常;
python -c "import cx_Oracle"
通常,还需要加载oralce的客户端配置环境和库
libclntsh.so.11.1libnnz11.so
#!/usr/bin/python# coding:utf-8## check Oracle process# dbsession: current connect session# dbprocess: db max connect session# presession: current connect session precentimport cx_Oracleimport sys# conn to DBconn = cx_Oracle.connect('user/passwd@orcl')cursor = conn.cursor()dbProcess = {}# current connect sessionsessionSQL = "select count(*) process from v$session"cursor.execute(sessionSQL)sessionRow = cursor.fetchone()dbProcess['dbsession'] = sessionRow[0]# db max connect sessionprocessSQL = "select value count from v$parameter where name ='processes'"cursor.execute(processSQL)proce***ow = cursor.fetchone()dbProcess['dbprocess'] = proce***ow[0]# current connect session precentpresession = (dbProcess['dbsession']) / float(dbProcess['dbprocess'])dbProcess['presession'] = '%.2f' % (presession * 100)cursor.close()# close dbconn.close()#print(dbProcess)try: if sys.argv[1]: if sys.argv[1] == 'dbsession': print(dbProcess['dbsession']) if sys.argv[1] == 'dbprocess': print(dbProcess['dbprocess']) if sys.argv[1] == 'presession': print(dbProcess['presession'])except: print("Usage: %s dbsession |dbprocess |presession" % sys.argv[0])
验证脚本
[zabbix@DB1 script]$ python zabbix_check_process.pyUsage: zabbix_check_process.py dbsession |dbprocess |presession[zabbix@DB1 script]$ python zabbix_check_process.py dbsession597[zabbix@DB1 script]$ python zabbix_check_process.py dbprocess1000[zabbix@DB1 script]$ python zabbix_check_process.py presession59.40
## db connect sessionUserParameter=oracle.dbsession,source ~/.bash_profile;/usr/bin/python /opt/zabbix/share/script/zabbix_check_process.py dbsessionUserParameter=oracle.dbprocess,source ~/.bash_profile;/usr/bin/python /opt/zabbix/share/script/zabbix_check_process.py dbprocessUserParameter=oracle.presession,source ~/.bash_profile;/usr/bin/python /opt/zabbix/share/script/zabbix_check_process.py presession
[root@zabbix ~]# zabbix_get -s 192.168.1.10 -p 10050 -k 'oracle.dbsession'581[root@zabbix ~]# zabbix_get -s 192.168.1.10 -p 10050 -k 'oracle.presession'58.10[root@zabbix ~]# zabbix_get -s 192.168.1.10 -p 10050 -k 'oracle.dbprocess'1000
Oracel数据库当前连接数的百分比 oracle.presession 60s 30d 90d Zabbix 客户端 Oracle连接数 已启用Oracel数据库最大连接数 oracle.dbprocess 60s 30d 90d Zabbix 客户端 Oracle连接数 已启用Oracle数据库当前连接数 oracle.dbsession 60s 30d 90d Zabbix 客户端 Oracle连接数 已启用
上传的资料包含监控模板、数据库连接数监控、表空间自动发现规则(监控),
转载于:https://blog.51cto.com/balich/2161422