OceanBase监控对接Prometheus/Grafana
总结
本文讲介绍如何让OceanBase监控对接Prometheus和Grafana.
安装流程
大致过程, 分为3大步骤: 1. 安装oceanbase和obagent 2. 安装prometheus和grafana 3. 配置prometheus和grafana
安装OceanBase和Obagent
如何安装OceanBase 可以参考上一篇文章《OceanBase离线安装》, 本节重点介绍如何安装obagent, 可以参考文档使用 OBD 部署 OBAgent
OBAgent 是一个监控采集框架。OBAgent 支持推、拉两种数据采集模式,可以满足不同的应用场景。OBAgent 默认支持的插件包括主机数据采集、OceanBase 数据库指标的采集、监控数据标签处理和 Prometheus 协议的 HTTP 服务。要使 OBAgent 支持其他数据源的采集,或者自定义数据的处理流程,您只需要开发对应的插件即可。
obagent 的配置, 在原来的配置基础上, 增加了obagent的配置, 详情可以参考distributed-with-obproxy-and-obagent-example:
1 | obagent: |
特别说明: 1. depends里面的 “oceanbase-ce” 的名字必须和配置文件集群的名字一致. 2. servers里面的配置必须与在配置文件中"oceanbase-ce"一节中servers 配置一摸一样 3. 记住home_path, 后续需要用到这个路径.
安装完成后, 可以执行“obd cluster display ” 看到obagent 已经启动了 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
33obd cluster display obtest
Get local repositories and plugins ok
Open ssh connection ok
Cluster status check ok
Connect to observer ok
Wait for observer init ok
+-------------------------------------------------+
| observer |
+---------------+---------+------+-------+--------+
| ip | version | port | zone | status |
+---------------+---------+------+-------+--------+
| 172.30.62.210 | 3.1.1 | 2881 | zone1 | active |
| 172.30.62.211 | 3.1.1 | 2881 | zone2 | active |
| 172.30.62.212 | 3.1.1 | 2881 | zone3 | active |
+---------------+---------+------+-------+--------+
Connect to obproxy ok
+-------------------------------------------------+
| obproxy |
+---------------+------+-----------------+--------+
| ip | port | prometheus_port | status |
+---------------+------+-----------------+--------+
| 172.30.62.213 | 2883 | 2884 | active |
+---------------+------+-----------------+--------+
+---------------------------------------------------+
| obagent |
+---------------+-------------+------------+--------+
| ip | server_port | pprof_port | status |
+---------------+-------------+------------+--------+
| 172.30.62.210 | 8088 | 8089 | active |
| 172.30.62.211 | 8088 | 8089 | active |
| 172.30.62.212 | 8088 | 8089 | active |
+---------------+-------------+------------+--------+
安装prometheus和grafana
选择一台机器上安装prometheus 和grafana, 这台机器尽量不是observer 中的一台, 本例中, prometheus 和grafana 部署在obproxy机器上.
- 从https://prometheus.io/download/ 上把prometheus 和alertmanager 下载下来, 本章将不介绍 alertmanager 怎么使用.
- 从https://grafana.com/grafana/download?pg=get&plcmt=selfmanaged-box1-cta1 上下载grapha
- 讲prometheus 和grafana 压缩包拷贝到obproxy 的机器上,
- 解压prometheus 和grafana ## 配置prometheus和grafana
1
2# tar -xzf prometheus-2.31.0.linux-amd64.tar.gz
# tar -xzf grafana-enterprise-8.2.3.linux-amd64.tar.gz
配置prometheus
- 讲obagent上的prometheus 的配置文件给拷贝到prometheus 的安装目录中 备注说明:
1
2
3# cd prometheus-2.31.0.linux-amd64
# mv prometheus.yml prometheus.yml.old
# scp -r observer001:/root/observer/conf/prometheus_config/* . - observer001 为安装obagent的一台机器
- /root/observer 为之前在配置文件中, 配置obagent中配置的home_path路径
- 从observer001 上会copy 过来几个文件, prometheus.yaml 和rules, rules 是存储拉取规则, prometheus 是配置prometheus的文件.
启动prometheus 1
nohup ./prometheus --config.file=./prometheus.yaml >> run.log 2>&1 &
1
# curl http://localhost:9090/metrics
配置grafana
1 | # cd grafana-8.2.3/ |
可以坚持run.log 或ps -ef|grep grafana 均可以查看到grafana 正常工作.
打开grafana 的页面, 第一次登录, 输入admin/admin, 然后设置管理员密码, 然后增加data source 进入增加data source后, 选择prometheus, 然后进入配置prometheus 后, 关键设置url
import 配置项
ob 已经提前准备好了 15215和15216 , 一个是监控oceanbase, 一个是监控host的. 当加载好模版后, 在dashboard 就可以看到2个预设好的dashboard,
恭喜你, 已经完成配置oceanbase对接prometheus 和grafana