一文聊聊如何快速监控 Oracle 数据库


Cprobe 是一个探针采集器,支持常见数据库、中间件的采集,比如 MySQL、redis、MongoDB、Oracle、Kafka、ElasticSearch 等 。安装配置 Oracle简单起见,我使用 Docker 启动 Oracle , 命令如下:
docker run -d --name oracle -p 1022:22 -p 18080:8080 -p 1521:1521 wnameless/oracle-xe-11g-r2如上命令启动之后,Oracle 的监听端口是 1521,用户名/密码是 system/oracle , 数据库 SID 是 xe,要监控 Oracle,首先得有账号连上去执行 SQL,所以这些连接信息得记住喽,待会要用 。
如果是对既有的 Oracle 做监控,需要创建账号并分派权限 , 比如:
-- Create the monitoring user "cprobe"CREATE USER cprobe IDENTIFIED BY <YOUR-PASSword>;-- Grant the "cprobe" user the required permissionsGRANT CONNECT TO cprobe;GRANT SELECT ON SYS.GV_$RESOURCE_LIMIT to cprobe;GRANT SELECT ON SYS.V_$SESSION to cprobe;GRANT SELECT ON SYS.V_$WAITCLASSMETRIC to cprobe;GRANT SELECT ON SYS.GV_$PROCESS to cprobe;GRANT SELECT ON SYS.GV_$SYSSTAT to cprobe;GRANT SELECT ON SYS.V_$DATAFILE to cprobe;GRANT SELECT ON SYS.V_$ASM_DISKGROUP_STAT to cprobe;GRANT SELECT ON SYS.V_$SYSTEM_WAIT_CLASS to cprobe;GRANT SELECT ON SYS.DBA_TABLESPACE_USAGE_METRICS to cprobe;GRANT SELECT ON SYS.DBA_TABLESPACES to cprobe;GRANT SELECT ON SYS.GLOBAL_NAME to cprobe;安装 CprobeCprobe 是一个探针采集器,支持常见数据库、中间件的采集,比如 MySQL、Redis、MongoDB、Oracle、Kafka、ElasticSearch 等,最新版本是 v0.7.1,我们从 Github releases 页面下载:
https://github.com/cprobe/cprobe/releases/tag/v0.7.1我是 arm 的 linux , 所以下载的是 cprobe-v0.7.1-linux-arm64.tar.gz,如果你是 x86 的,应该下载 amd64 那个包 。如果你从 github 下载有困难,我这里提供一个国内的下载地址:
https://download.flashcat.cloud/cprobe-v0.7.1-linux-arm64.tar.gzhttps://download.flashcat.cloud/cprobe-v0.7.1-linux-amd64.tar.gz解压缩进入对应目录 , 执行 install 和 start 命令即可:
./cprobe -install./cprobe -start./cprobe -status安装完成 。
配置 Cprobe 采集首先配置要采集的 Oracle 的地址,进入刚才 cprobe 解压出的目录,编辑 conf.d/oracledb/main.yaml,修改如下:
global:scrape_interval: 15sexternal_labels:cplugin: 'oracle'scrape_configs:- job_name: 'oracle'static_configs:- targets:- 10.99.1.107:1521/xe # ip:port/servicescrape_rule_files:- 'link.toml'- 'comm.toml'上面的 IP 是我的 Oracle 的 IP,你要根据你的环境做调整 。这个 main.yaml 又引用了 link.toml 和 comm.toml,在 link.toml 中配置认证信息,比如:
[global]username = "system"password = "oracle"options = {}comm.toml 的内容不用动 。监控 Oracle 的原理就是连上去执行一堆 SQL,comm.toml 中提前帮你准备好了一堆 SQL,其实还有 cust.toml 有更多 SQL,看你需求 , 如果 cust.toml 中的监控项你也需要 , 那就把 cust.toml 也配置到 main.yaml 中 , 如下:
global:scrape_interval: 15sexternal_labels:cplugin: 'oracle'scrape_configs:- job_name: 'oracle'static_configs:- targets:- 10.99.1.107:1521/xe # ip:port/servicescrape_rule_files:- 'link.toml'- 'comm.toml'- 'cust.toml'下面我们测试一下,看看是否真的能够采集到数据:
./cprobe -no-writer -no-httpd -plugins oracledb正常来讲,会输出很多指标,类似下面这样:
./cprobe -no-writer -no-httpd -plugins oracledb2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/logger/flag.go:12 build version: 0.0.1-2023-12-25-08-39-112023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/logger/flag.go:13 command-line flags2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/logger/flag.go:20-no-httpd="true"2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/logger/flag.go:20-no-writer="true"2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/logger/flag.go:20-plugins="oracledb"2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/runner/runner.go:25hostname: ulric-flashcat.local2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/runner/runner.go:26runtime.fd_limits: (soft=61440, hard=unlimited)2023-12-25T10:27:33.868Zinfo/Users/ulric/works/cprobe/lib/runner/runner.go:27runtime.vm_limits: (soft=unlimited, hard=unlimited)>> __name__=oracledb_sessions_value cplugin=oracle instance=10.99.1.107:1521/xe job=oracle status=ACTIVE type=BACKGROUND1703500053881 22.000000>> __name__=oracledb_sessions_value cplugin=oracle instance=10.99.1.107:1521/xe job=oracle status=ACTIVE type=USER1703500053881 1.000000>> __name__=oracledb_resource_current_utilization cplugin=oracle instance=10.99.1.107:1521/xe job=oracle resource_name=processes1703500053881 29.000000>> __name__=oracledb_resource_limit_value cplugin=oracle instance=10.99.1.107:1521/xe job=oracle resource_name=processes1703500053881 100.000000...


推荐阅读