Prometheus 监控 Oracle
启动 oracledb_exporter 容器
由于安装的 Oracle 版本为 11.2.0.4,如果使用二进制文件部署监控服务,会提示找不到库文件,所以这里使用 docker 运行 oralcedb_exporter 容器。以下是运行命令
1
2
3
4
5docker run -d \
--restart=always \
--name oracledb_exporter \
-p 9161:9161 \
-e DATA_SOURCE_NAME='system/"Huaxue,001"'@192.168.64.64:1521/ahwms iamseth/oracledb_exporter参数说明:
- DATA_SOURCE_NAME: Oracle 数据库的连接信息 ‘user/“passwd”‘@host:port/sid
由于存在多个数据库需要监控,这里以端口和容器名称进行区分,为方便管理,以下使用 docker-compose 进行配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29version: "3.5"
services:
oracle-ahwms-local-test:
container_name: oracle-ahwms-local-test
image: "iamseth/oracledb_exporter"
environment:
DATA_SOURCE_NAME: 'system/123123@192.168.64.64:1521/ahwms'
ports:
- target: 9161
published: 9161
restart: always
oracle-qdmwms-local-pre:
container_name: oracle-qdmwms-local-test
image: "iamseth/oracledb_exporter"
environment:
DATA_SOURCE_NAME: 'system/123123@192.168.64.26:1521/qdmwms'
ports:
- target: 9161
published: 9162
restart: always
oracle-settle-local-pre:
container_name: oracle-settle-local-pre
image: "iamseth/oracledb_exporter"
environment:
DATA_SOURCE_NAME: 'system/123123@192.168.64.29:1521/settle'
ports:
- target: 9161
published: 9163
restart: always启动 oracle-exporter 容器
1
docker-compose up -d
配置 Prometheus
Prometheus 新建
configs/oracle.yml
配置文件,内容如下:1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27- labels:
env: 'test'
region: 'dg2'
sid: 'ahwms'
hostname: 'ahwms-db'
server: '192.168.64.64'
project: 'ahwms'
targets:
- '192.168.64.61:9161'
- labels:
env: 'product'
region: 'dg2'
sid: 'qdmwms'
hostname: 'qdmwms-db'
server: '192.168.64.26'
project: 'qdmwms'
targets:
- '192.168.64.61:9162'
- labels:
env: 'product'
region: 'dg2'
sid: 'settle'
hostname: 'settle-db'
server: '192.168.64.29'
project: 'settle'
targets:
- '192.168.64.61:9163'修改 Prometheus 主配置文件 prometheus.yml,加载 oracle.yml 文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72# my global config
global:
scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
# scrape_timeout is set to the global default (10s).
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets:
- localhost:9093
# Load rules once and periodically evaluate them according to the global 'evaluation_interval'.
rule_files:
- "rules/host_status.yml"
- "rules/containers_status.yaml"
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs:
# The job name is added as a label `job=<job_name>` to any timeseries scraped from this config.
- job_name: 'prometheus'
# metrics_path defaults to '/metrics'
# scheme defaults to 'http'.
static_configs:
- targets: ['localhost:9090'] # 收集 Prometheus 服务本身的信息
# 以下为需要监控的主机系统指标配置
- file_sd_configs:
- files:
- 'configs/host.yml' # 需要抓取的主机配置文件
refresh_interval: 10s
job_name: 'Host'
metrics_path: /metrics
relabel_configs:
- source_labels: [__address__]
regex: (.*):(\d+)
target_label: instance
replacement: $1
# 以下是需要监控容器运行状态的配置
- file_sd_configs:
- files:
- 'configs/dockers.yml' # 需要抓取的 Docker 主机配置文件
refresh_interval: 10s
job_name: 'Docker'
metrics_path: /metrics
metric_relabel_configs:
- target_label: env
replacement: test
relabel_configs:
- source_labels: [__address__]
regex: (.*):(\d+)
target_label: instance
replacement: $1
# 以下是需要监控容器运行状态的配置
- file_sd_configs:
- files:
- 'configs/oracle.yml' # 需要抓取的 oracle 主机配置文件
refresh_interval: 10s
job_name: 'OracleDB'
metrics_path: /metrics
metric_relabel_configs:
relabel_configs:
- source_labels: [__address__]
regex: (.*):(\d+)
target_label: instance
replacement: $1
配置 Grafana 面板
- 前往 Grafana Dashboard 页面搜索一个 Dashboard。
- 下载选择好的 Dashboard json 文件,导入 Grafana;
- 修改 variable,以及各图表对应的数据查询语句(主要是针对变量);