diff --git a/media/prometheus-ob-monitor/grafana-json.png b/media/prometheus-ob-monitor/grafana-json.png new file mode 100644 index 0000000000000000000000000000000000000000..d06b54b5b1b11f5c3f38edf23b824145410e11aa Binary files /dev/null and b/media/prometheus-ob-monitor/grafana-json.png differ diff --git a/media/prometheus-ob-monitor/grafana-metrics.png b/media/prometheus-ob-monitor/grafana-metrics.png new file mode 100644 index 0000000000000000000000000000000000000000..2c79a6f4c1fe32d3ba5dd12ff948e1ffa5d9ef6b Binary files /dev/null and b/media/prometheus-ob-monitor/grafana-metrics.png differ diff --git a/media/prometheus-ob-monitor/grafana-source.png b/media/prometheus-ob-monitor/grafana-source.png new file mode 100644 index 0000000000000000000000000000000000000000..012b2cfcf990e036e7022c4709f638bb675bec55 Binary files /dev/null and b/media/prometheus-ob-monitor/grafana-source.png differ diff --git a/media/prometheus-ob-monitor/prometheus-alert.png b/media/prometheus-ob-monitor/prometheus-alert.png new file mode 100644 index 0000000000000000000000000000000000000000..a08618d04101300c2a0e7b147fb3deda4b1897cf Binary files /dev/null and b/media/prometheus-ob-monitor/prometheus-alert.png differ diff --git a/media/prometheus-ob-monitor/prometheus-full-arch.png b/media/prometheus-ob-monitor/prometheus-full-arch.png new file mode 100644 index 0000000000000000000000000000000000000000..554e4d2b03cb9e55e8a90b8431e857fb7554fac1 Binary files /dev/null and b/media/prometheus-ob-monitor/prometheus-full-arch.png differ diff --git a/media/prometheus-ob-monitor/prometheus-monitor-physical-arch.png b/media/prometheus-ob-monitor/prometheus-monitor-physical-arch.png new file mode 100644 index 0000000000000000000000000000000000000000..f17f04bd8b9d63c4720f65cdcfe5f9abe2f97edf Binary files /dev/null and b/media/prometheus-ob-monitor/prometheus-monitor-physical-arch.png differ diff --git a/media/prometheus-ob-monitor/prometheus-monitor-screen.png b/media/prometheus-ob-monitor/prometheus-monitor-screen.png new file mode 100644 index 0000000000000000000000000000000000000000..0098ff5710a28dac40159dea309dac2059fa6221 Binary files /dev/null and b/media/prometheus-ob-monitor/prometheus-monitor-screen.png differ diff --git "a/\345\274\200\345\217\221\350\277\220\347\273\264-\345\246\202\344\275\225\346\220\255\345\273\272\345\237\272\344\272\216Prometheus\347\232\204OceanBase\344\270\200\344\275\223\345\214\226\347\233\221\346\216\247\346\226\271\346\241\210.md" "b/\345\274\200\345\217\221\350\277\220\347\273\264-\345\246\202\344\275\225\346\220\255\345\273\272\345\237\272\344\272\216Prometheus\347\232\204OceanBase\344\270\200\344\275\223\345\214\226\347\233\221\346\216\247\346\226\271\346\241\210.md" new file mode 100644 index 0000000000000000000000000000000000000000..e2b82ec725b519cbb89f14e889a1a7c738a44e1b --- /dev/null +++ "b/\345\274\200\345\217\221\350\277\220\347\273\264-\345\246\202\344\275\225\346\220\255\345\273\272\345\237\272\344\272\216Prometheus\347\232\204OceanBase\344\270\200\344\275\223\345\214\226\347\233\221\346\216\247\346\226\271\346\241\210.md" @@ -0,0 +1,162 @@ +本文分享的内容是基于 OceanBase 的社区生态工具 obagent 构建基于 Prometheus的一体化解决方案,Prometheus 是一款云原生监控解决方案,提供时许数据存储、PromQL查询,最终通过 Grafana 丰富的图形化展示给大家。可以满足企业已有 Prometheus 集群监控体系的接入。 + +大家可以通过以下图片对**整个监控体系的架构**有一个整体了解: + +![](./media/prometheus-ob-monitor/prometheus-full-arch.png) + +总结一下上图提到的各个组件: + +- Grafana + OceanBase Metrics - 展示层,OB 提供 Grafana 可导入的监控界面 +- Prometheus + Alert Manager - 监控服务,提取、存储监控指标数据,通过Alert Manager 告警(本文不详细展开 Alert Manager 配置,如有需要请自己查阅资料) +- OBServer x - OB 集群节点 +- OBAgent - 代理服务,采集 OBServer 指标信息,并暴露数据给 Prometheus +- OBProxy - OB 代理服务,对外暴露 2884 端口给 Prometheus + + +# 1. 前置条件 + +本方案只涉及 OBAgent 和 Prometheus 内容,有一些前置条件需要大家提前有所准备。下面一一列出,大家可以选择性的准备: + +- OceanBase 集群:本文章不涉及集群部署,请参考官方文档自行部署 +- OBProxy:集群路由,与 OB 集群一起部署 +- Prometheus 软件:Prometheus 软件是监控服务的核心,用来收集监控数据,提供存储、查询和告警功能,Prometheus 所需要的配置文件,OBAgent 会自动生成 +- Grafana 软件:Grafana 是视图展示层,取 Prometheus 存储的数据,社区也有发布对应的 Dashboard 方便大家一键集成 + +本文中采用了一个最简单的三节点 OceanBase 集群架构,另外配置了一台 OBProxy 机器,共 4 台机器,Prometheus 和 Grafana 服务都部署到 OBProxy 机器上,服务器物理架构如下: + +![](./media/prometheus-ob-monitor/prometheus-monitor-physical-arch.png) + +# 2. OBAgent 部署 + +OBProxy 的 2884 端口是服务安装时已经配置好的,所以不需要部署 OBAgent 服务,我们需要使用 OBDeploy 工具将 OBAgent 部署到 OBServer 服务器即可。 + +**首先**,我们在 obd 机器上,编写配置文件 + +```yaml +obagent: + servers: + - name: server1 + ip: 10.211.55.74 + - name: server2 + ip: 10.211.55.75 + - name: server3 + ip: 10.211.55.76 + global: + home_path: /home/chris/obagent + server_port: 8088 + pprof_port: 8089 + sql_port: 2881 + rpc_port: 2882 + log_level: INFO + log_path: log/monagent.log + crypto_method: plain + log_size: 30 + log_expire_day: 7 + log_file_count: 10 + http_basic_auth_user: admin + http_basic_auth_password: root + pprof_basic_auth_user: admin + pprof_basic_auth_password: root + monitor_user: root + monitor_password: observer + cluster_name: obcluster + + server1: + zone: zone1 + server2: + zone: zone2 + server3: + zone: zone3 +``` + +**然后**,直接执行 obd 命令,部署 obagent,执行过程会从 OceanBase 官方仓库拉取 OBAgent 并安装 + +```shell +[chris@obd ~]$ obd cluster deploy obagent-only -c obagent_only.yaml +... ... +obagent-only deployed +[chris@obd ~]$ obd cluster list ++------------------------------------------------------------------------+ +| Cluster List | ++--------------+---------------------------------------+-----------------+ +| Name | Configuration Path | Status (Cached) | ++--------------+---------------------------------------+-----------------+ +| obcluster | /home/chris/.obd/cluster/obcluster | running | +| obagent-only | /home/chris/.obd/cluster/obagent-only | deployed | ++--------------+---------------------------------------+-----------------+ +``` + +**最后**,使用 obd 启动刚才部署的 OBAgent 集群;启动 OBAgent 之前,我先启动 OceanBase 集群(如果您的集群已经在服务,该步骤可以省略) + +```shell +[chris@obd ~]$ obd cluster start obagent-only +Get local repositories and plugins ok +Open ssh connection ok +Load cluster param plugin ok +Check before start obagent ok +Start obagent ok +obagent program health check ok ++--------------------------------------------------+ +| obagent | ++--------------+-------------+------------+--------+ +| ip | server_port | pprof_port | status | ++--------------+-------------+------------+--------+ +| 10.211.55.74 | 8088 | 8089 | active | +| 10.211.55.75 | 8088 | 8089 | active | +| 10.211.55.76 | 8088 | 8089 | active | ++--------------+-------------+------------+--------+ +obagent-only running +``` + +# 3. Prometheus 及 Grafana 配置 + +## 3.1 拉取 obagent 自动生成的配置并启动 Prometheus + +OBAgent 启动后会在 OBServer 服务器上自动生成 Prometheus 所需要的配置文件,该配置文件被放在 OBAgent 安装目录下,例如我这里的地址: /home/chris/obagent/conf/prometheus_config/。配置文件可以从任何 OBServer 服务器上拿下来直接给 Prometheus 使用。我这里直接打包 prometheus_config 下的所有文件,放到监控服务器对应的 prometheus 可执行程序同级目录下: + +```shell +tar -czvf prule.tgz prometheus.yaml rules +cd /home/chris/prometheus-2.35.0.darwin-amd64 +scp chris@observer1:/home/chris/obagent/conf/prometheus_config/prule.tgz . +mv prometheus.yml prometheus.yml.bak +tar xzvf prule.tgz +``` + +指定配置文件启动 Prometheus: + +```shell +nohup ./prometheus --config.file=prometheus.yaml & +``` + +## 3.2 检查 Prometheus 监控状态 + +通过上一步启动 Prometheus 服务后,正常情况下,可以通过访问地址来查看监控状态了,我这里的地址是:http://10.211.55.73:9090/targets + +可以看到,如下图,OBServer 的监控目标一切正常: + +![](./media/prometheus-ob-monitor/prometheus-monitor-screen.png) + +## 3.3 Grafana 配置 + +完成了上面 Prometheus 的配置后,下面我们开始配置 Grafana,同样需要把安装包解压到 OBD 服务器下,然后直接启动服务就可以了,配置都是在页面上进行的: + +```shell +tar xzvf grafana-8.5.2.tgz +cd grafana-8.5.2/bin +nohup ./grafana-server & +``` + +访问 Grafana 页面:http://10.211.55.73:3000 ,初次访问用户名为 admin,密码会让您自己设定一下。在网页上分别配置数据源,并导入如下三个 Dashboard: + +- Oceanbase Metrics:https://grafana.com/grafana/dashboards/15215 +- Host Metrics:https://grafana.com/grafana/dashboards/15216 +- Obproxy Metrics:https://grafana.com/grafana/dashboards/15354 + +![](./media/prometheus-ob-monitor/grafana-source.png) + +![](./media/prometheus-ob-monitor/grafana-json.png) + +![](./media/prometheus-ob-monitor/grafana-metrics.png) + +至此,基于 Prometheus 的 OceanBase 一体化解决方案就完成了,希望大家通过我的文章能对这个基于 obagent 的方案有一个整体认识,谢谢。 +