https://github.com/iamseth/oracledb_exporter
一款模仿 MySQL 导出器的 Oracle的Prometheus导出器。
目前已公开的指标:
docker run -d --name oracle -p 1521:1521 wnameless/oracle-xe-11g-r2:18.04-apex
docker run -d --name oracledb_exporter --link=oracle -p 9161:9161 -e DATA_SOURCE_NAME=system/oracle@oracle/xe iamseth/oracledb_exporter
注:
配置项 | 解释 |
---|---|
–link=oracle | 与容器名为oracle的数据库建立连接 |
-p 9161:9161 | 对外开放的端口 |
-e DATA_SOURCE_NAME=system/oracle@oracle/xe | 数据源配置信息(管理员账号/密码@数据库/库名) |
iamseth/oracledb_exporter | 镜像名 |
注:
确保在启动前正确设置环境变量 DATA_SOURCE_NAME。DATA_SOURCE_NAME 应采用 Oracle EZCONNECT 格式:
https://docs.oracle.com/en/database/oracle/oracle-database/19/netag/configuring-naming-methods.html#GUID-B0437826-43C1-49EC-A94D- B650B6A4A6EE
19c Oracle 客户端支持增强型 EZCONNECT,您可以故障转移到备用数据库或从活动备用数据库收集一些重要指标并指定一些附加参数。在 19c 客户端中,您也可以连接 12c 主/备用数据库
例如:
# export Oracle location:
export DATA_SOURCE_NAME=system/password@oracle-sid
# or using a complete url:
export DATA_SOURCE_NAME=user/password@//myhost:1521/service
# 19c client for primary/standby configuration
export DATA_SOURCE_NAME=user/password@//primaryhost:1521,standbyhost:1521/service
# 19c client for primary/standby configuration with options
export DATA_SOURCE_NAME=user/password@//primaryhost:1521,standbyhost:1521/service?connect_timeout=5&transport_connect_timeout=3&retry_count=3
# 19c client for ASM instance connection (requires SYSDBA)
export DATA_SOURCE_NAME=user/password@//primaryhost:1521,standbyhost:1521/+ASM?as=sysdba
# Then run the exporter
/path/to/binary/oracledb_exporter --log.level error --web.listen-address 0.0.0.0:9161
mkdir /etc/oracledb_exporter
chown root:oracledb_exporter /etc/oracledb_exporter
chmod 775 /etc/oracledb_exporter
[Unit]
Description=Service for oracle telemetry client
After=network.target
[Service]
Type=oneshot
#!!! Set your values and uncomment
#User=oracledb_exporter
#Group=oracledb_exporter
#Environment="DATA_SOURCE_NAME=dbsnmp/Bercut01@//primaryhost:1521,standbyhost:1521/myservice?transport_connect_timeout=5&retry_count=3"
#Environment="LD_LIBRARY_PATH=/u01/app/oracle/product/19.0.0/dbhome_1/lib"
#Environment="ORACLE_HOME=/u01/app/oracle/product/19.0.0/dbhome_1"
#Environment="CUSTOM_METRICS=/etc/oracledb_exporter/custom-metrics.toml"
ExecStart=/usr/local/bin/oracledb_exporter \
--default.metrics "/etc/oracledb_exporter/default-metrics.toml" \
--log.level error --web.listen-address 0.0.0.0:9161
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start oracledb_exporter
systemctl status oracledb_exporter
上面的ExecStart=/usr/local/bin/oracledb_exporter \ 后面的其他配置可选项:
Usage of oracledb_exporter:
--log.format value
If set use a syslog logger or JSON logging. Example: logger:syslog?appname=bob&local=7 or logger:stdout?json=true. Defaults to stderr.
--log.level value
Only log messages with the given severity or above. Valid levels: [debug, info, warn, error, fatal].
--custom.metrics string
File that may contain various custom metrics in a TOML file.
--default.metrics string
Default TOML file metrics.
--web.listen-address string
Address to listen on for web interface and telemetry. (default ":9161")
--web.telemetry-path string
Path under which to expose metrics. (default "/metrics")
--database.maxIdleConns string
Number of maximum idle connections in the connection pool. (default "0")
--database.maxOpenConns string
Number of maximum open connections in the connection pool. (default "10")
--web.secured-metrics boolean
Expose metrics using https server. (default "false")
--web.ssl-server-cert string
Path to the PEM encoded certificate file.
--web.ssl-server-key string
Path to the PEM encoded key file.
该exporter同时提供自定义指标功能,这里不展开叙述;
自定义指标
export WALLET_PATH=/wallet/path/to/use
export TNS_ENTRY=tns_entry
export DB_USERNAME=db_username
export TNS_ADMIN=/tns/admin/path/to/use
mkstore -wrl $WALLET_PATH -create
mkstore -wrl $WALLET_PATH -createCredential $TNS_ENTRY $DB_USERNAME
echo "
WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = $WALLET_PATH )))
SQLNET.WALLET_OVERRIDE = TRUE
SSL_CLIENT_AUTHENTICATION = FALSE
" >> $TNS_ADMIN/sqlnet.ora
DATA_SOURCE_NAME=username/password@tcps://dbhost:port/service?ssl_server_dn_match=false&wallet_location=wallet_path
有关更多详细信息,请查看以下位置:https : //github.com/iamseth/oracledb_exporter/issues/84