oracledb_exporter部署

oracledb_exporter
服务端口:9161

部署

1.下载安装包并解压

安装包:oracledb_exporter.0.2.8-ora18.5.linux-amd64.tar.gz
解压:

tar -zxvf oracledb_exporter.0.2.8-ora18.5.linux-amd64.tar.gz -C /usr/local
cd /usr/local/ && mv oracledb_exporter.0.2.8-ora18.5.linux-amd64 oracledb_exporter

下载地址:https://github.com/iamseth/oracledb_exporter

2.下载并安装oracle客户端

oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
oracle-instantclient18.5-sqlplus-18.5.0.0.0-3.x86_64.rpm
https://www.oracle.com/database/technologies/instant-client/downloads.html


oracledb_exporterer连接oracle数据库,需依赖oracle client,因此也要提前下载好oracle client。如果是Oracle 19C可用21版本的Client,如果是Oracle 11g可用18版本的Client,如果操作系统比较新(如是CentOS7以上),则可以装21,对于去连接Oracle 19C和11g,因为大版本是可向下兼容的。这边我用以前下载的18.5为案例,一个basic的rpm,一个sqlplus的rpm。

rpm -ivh oracle-instantclient18.5-basic-18.5.0.0.0-3.x86_64.rpm
rpm -ivh oracle-instantclient18.5-sqlplus-18.5.0.0.0-3.x86_64.rpm

3.oracle上创建监控用户

create user prometheus identified by xxxxxx;
grant connect,resource to prometheus;
ps:权限问题,可以逐步开放

4.配置监听文件

vim /usr/lib/oracle/18.5/client64/tnsnames.ora

prometheus =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = xxx.xxx.xxx.xxx)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = 实例名)
    )
  )

5.添加全局环境变量并验证远程sqlplus登陆

vim /etc/profile
export ORACLE_HOME=/usr/lib/oracle/18.5/client64
export TNS_ADMIN=/usr/lib/oracle/18.5/client64/network
export LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib
export PATH=$PATH:$ORACLE_HOME/bin
export NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
export DATA_SOURCE_NAME="prometheus/xxxxxx@数据库ip:1521/实例名"
source /etc/profile

5.1验证是否可以登陆:

sqlplus prometheus/xxxxxx@数据库ip/实例名

6.配置环境文件

(全局变量改成env文件)

vim /usr/local/oracledb_exporter/oracle-env
ORACLE_HOME=/usr/lib/oracle/18.5/client64
TNS_ADMIN=/usr/lib/oracle/18.5/client64/network
LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:$ORACLE_HOME/lib
PATH=$PATH:$ORACLE_HOME/bin
NLS_LANG=AMERICAN_AMERICA.ZHS16GBK
DATA_SOURCE_NAME="prometheus/xxxxxx@数据库ip:1521/实例名"

7.采集器加入开机自启动并校验是否服务是否正常

vim /etc/systemd/system/oracledb_exporter.service
[Unit]
Description=oracledb_exporter
After=network.target
[Service]
Type=simple
EnvironmentFile=-/usr/local/oracledb_exporter/oracle-env
User=root
ExecStart=/usr/local/oracledb_exporter/oracledb_exporter\
           --default.metrics /usr/local/oracledb_exporter/default-metrics.toml\
           --query.timeout=50\
           --web.listen-address=:9161
Restart=on-failure

加入开机自启动并启动
systemctl enable oracledb_exporter.service
systemctl status oracledb_exporter.service
校验
curl http://xxx.xxx.xxx.xxx:9161/metrics

8.加入告警规则

groups:
  - name: oracle-alerting
    rules:
    - alert: instance-down
      expr: up{job=~"oracledb"} == 0
      for: 2m
      labels:
        severity: high
        alertinfo: push_oracle_alert
      annotations:
        summary: "Instance {{ $labels.instance }} down"
        description: "{{ $labels.tags }} has been down for more than 2 min."
    - alert: tablespace_use_status
      expr: 100*(oracledb_tablespace_bytes{type=~"PERMANENT"}-oracledb_tablespace_free{type=~"PERMANENT"})/oracledb_tablespace_max_bytes{type=~"PERMANENT"} >95
      for: 2m
      labels:
        severity: high
        alertinfo: push_oracle_alert
      annotations:
        summary: "{{ $labels.tablespace }} 表空间不足高于95%"
        description: "{{ $labels.tablespace }} 表空间高于95%"

9.配置加入prometheus

vim /etc/prometheus/prometheus.yml

  - job_name: 'oracledb'
    scrape_interval: 50s
    scrape_timeout: 50s
    static_configs:
    - targets: ['监控服务所在的服务器ip:9161']
      labels:
        instance: '10.120.100.2'
        tags: 'oracle数据库-10.120.100.2'

systemctl restart prometheus
systemctl restart grafana-server

10.grafana-server加入监控页面json

参考:
https://grafana.com/grafana/dashboards/11121-oracledb/
https://grafana.com/grafana/dashboards/13555-oracledb-monitoring-performance-and-table-space-stats/

posted @ 2023-03-12 20:26  海yo  阅读(1441)  评论(0编辑  收藏  举报