CentOS 上基于 SQL*Plus 的 Oracle 性能监控工具推荐
一 工具选型总览
二 仅用 SQL*Plus 的高频巡检 SQL
select instance_name, status from v$instance;select name, open_mode from v$database;select count(*), status from v$session group by status;select sid, serial#, username, program, action, state from v$session where status='ACTIVE';select sql_text, executions, elapsed_time from v$sql order by elapsed_time desc where rownum <= 10;select * from v$sysstat where name in ('CPU used by this session','physical reads','physical writes');select event, count(*) from v$session_wait group by event order by count(*) desc;select event, total_waits, total_timeouts, time_waited from v$system_event order by time_waited desc;col TABLESPACE_NAME for a20select tbs_used_info.tablespace_name,
tbs_used_info.alloc_mb,
tbs_used_info.used_mb,
tbs_used_info.max_mb,
tbs_used_info.free_of_max_mb,
tbs_used_info.used_of_max || '%' used_of_max_pct
from (
select a.tablespace_name,
round(a.bytes_alloc/1024/1024) alloc_mb,
round((a.bytes_alloc - nvl(b.bytes_free,0))/1024/1024) used_mb,
round((a.bytes_alloc - nvl(b.bytes_free,0))*100/a.maxbytes) used_of_max,
round((a.maxbytes - a.bytes_alloc + nvl(b.bytes_free,0))/1048576) free_of_max_mb,
round(a.maxbytes/1048576) max_mb
from (select f.tablespace_name,
sum(f.bytes) bytes_alloc,
sum(decode(f.autoextensible,'YES',f.maxbytes,'NO',f.bytes)) maxbytes
from dba_data_files f group by f.tablespace_name) a,
(select f.tablespace_name, sum(f.bytes) bytes_free
from dba_free_space f group by f.tablespace_name) b
where a.tablespace_name = b.tablespace_name(+)
) tbs_used_info
order by tbs_used_info.used_of_max desc;
rman target / list backup;lsnrctl status;端口连通:netstat -tlnp | grep 1521三 轻量命令行工具与脚本化采集
sqlplus -s 静默执行并接入日志或告警系统;例如每 5 分钟采集一次:*/5 * * * * sqlplus -s username/password@service @/path/monitor.sql >> /var/log/oracle_monitor.log 2>&1
top/htop、iostat -xz 1、vmstat 1 5、sar -n DEV 1 5、nmon 观察主机资源,有助于判断瓶颈是在数据库还是 OS/I/O。四 企业级与开源平台集成
sqlplus 验证连通性后由 Zabbix 定时抓取并告警。五 关键告警阈值与巡检清单