本文介紹如何通過部署 OBCloud Exporter 和 Prometheus 進行 OceanBase 雲資料庫的監控。
背景資訊
OBCloud Exporter 是OceanBase 提供的一款資料庫資料處理工具,可通過該工具完成 OceanBase 資料庫的鑒權和資料擷取。再結合本地 Prometheus 工具對資料庫進行相應的監控。
下文通過系統直接部署和通過 docker 部署兩種方式說明相應的工具使用方法。
前提條件
已部署 Java 8 及以上的運行環境。
已完成 Docker 部署。
系統運行 Prometheus 監控 OceanBase 雲資料
下載 OBCloud Exporter。
說明目前 OBCloud Exporter 暫未放開直接下載,可聯絡技術支援人員擷取。
部署 OBCloud Exporter。
解壓 OBCloud Exporter 安裝包,安裝目錄為
/opt/obcloud-exporter
。mkdir /opt/obcloud-exporter tar -zxvf Obcloud_Exporter.tar.gz -C /opt/obcloud-exporter --strip-components=1
解壓後目錄包含如下檔案:
Dockerfile:Docker 容器構建檔案。
muticloud_metric_config.yaml:指標設定檔,此檔案預設不需要修改。
application.yaml:採集設定檔。
obcloud-exporter-1.0-SNAPSHOT-jar-with-dependencies.jar:OBCloud Exporter 程式。
readme.md:專案說明。
編輯設定檔 application.yaml。
# 監控名稱 aliyun_monitor: # 身份憑據 credential: access_key_id: xxx access_key_secret: xx region_id: ap-southeast-1 # 終端地址 end_point: xxx # 是否定時重新整理 metric 指標,預設為 false。 metric_meta_auto_refresh: false instances: # 執行個體 ID - instance_id: xxx # 查詢叢集下指定租戶,需配置 tenant_id tenant_id: xxx # 執行個體類型:cluster 叢集執行個體,tenant 租戶執行個體/Serverless 執行個體。 instance_type: tenant metrics:
參數說明:
access_key_id、access_key_secret:鑒權資訊,可在對應平台申請。具體操作,請參見,建立AccessKey。
region_id、end_point:請參見 公用雲端服務地區說明。
metric_meta_auto_refresh:是否定時重新整理 metric 指標,預設為 false。
instances:監控執行個體,可包含多個叢集、租戶執行個體,通過短劃線(-)並列填入。
instance_id:叢集 ID、serverless 執行個體 ID、租戶執行個體 ID。
說明不支援使用叢集下的租戶 ID。
instance_type:固定為 cluster(叢集)或 tenant(租戶)。當 instance_id 為叢集執行個體時,填入 cluster;當 instance_id 為租戶執行個體、Serverless 執行個體時,填入 tenant。
tenant_id:查詢叢集下指定租戶,需配置 tenant_id。
metrics:指標資訊,不填表示採集全部指標。當需要採集指定指標時,格式如下:
instances: -instance_id: xxx tenant_id: xxx instance_type: cluster metrics: - sql_all_rt - sql_delete_rt
說明採集指標過多可能會影響採集速度,適當情況下拆分為多個 exporter。
通過 Java 直接運行 OBCloud Exporter。
java -jar /opt/obcloud-exporter/obcloud-exporter-1.0-SNAPSHOT-jar-with-dependencies.jar
通過瀏覽器驗證部署結果,訪問對應 IP 位址的 9400 連接埠,確認是否擷取到監控資料。
說明實際使用中,根據實際配置的地址連接埠進行訪問。
下載 Prometheus 軟體,在官網找到所需版本的 Prometheus 安裝包,進行下載,如下以 2.50.1 的 Linux 版本為例。
wget https://github.com/prometheus/prometheus/releases/download/v2.50.1/prometheus-2.50.1.linux-amd64.tar.gz
部署 Prometheus。
解壓並安裝 Prometheus 軟體,安裝目錄為
/opt/prometheus
。mkdir -p /opt/prometheus tar -zxvf prometheus-2.50.1.linux-amd64.tar.gz -C /opt/prometheus --strip-components=1
轉移設定檔 prometheus.yml 到工作目錄,並根據需要進行編輯。
mv /opt/prometheus/prometheus.yml /usr/local/bin/ vi /usr/local/bin/prometheus.yml
修改如下參數:
global: scrape_interval: 30s scrape_timeout: 20s scrape_configs: - job_name: "nodes" static_configs: - targets: ['localhost:9400']
建立 Prometheus 服務檔案和相關資料存放區目錄。
mkdir /var/lib/prometheus/ sudo vim /etc/systemd/system/Prometheus.service
填寫如下內容並儲存。
說明User(使用者)和 Group(使用者組)參數是可選的,設定方法請參考下一步驟 設定使用者名稱和使用者組。
[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Restart=on-failure ExecStart=/opt/prometheus/prometheus \ --config.file /usr/local/bin/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ [Install] WantedBy=multi-user.target
(可選)設定使用者名稱和使用者組,上一步驟中配置已有的使用者/使用者組或者沒有配置,可忽略此步驟。
sudo groupadd prometheus sudo useradd -r -g prometheus prometheus sudo chown -R prometheus:prometheus /opt/prometheus /var/lib/prometheus sudo chmod -R 755 /opt/prometheus /var/lib/prometheus
啟動 Prometheus 服務。
# 載入新的 systemd 配置 sudo systemctl daemon-reload # 啟動 Prometheus 服務 sudo systemctl start prometheus # 設定開機啟動 sudo systemctl enable prometheus # 檢查服務狀態 sudo systemctl status prometheus
確認 Prometheus 是否啟動成功。
sudo netstat -ntlp | grep 9090
通過 docker 部署 prometheus 監控 OceanBase 雲資料庫
下載 OBCloud Exporter。
說明目前 OBCloud Exporter 暫未放開直接下載,可聯絡技術支援人員擷取。
部署 OBCloud Exporter。
解壓 OBCloud Exporter 安裝包,安裝目錄為
/opt/obcloud-exporter
。mkdir /opt/obcloud-exporter tar -zxvf Obcloud_Exporter.tar.gz -C /opt/obcloud-exporter --strip-components=1
解壓後目錄包含如下檔案:
Dockerfile:Docker 容器構建檔案。
muticloud_metric_config.yaml:指標設定檔,此檔案預設不需要修改。
application.yaml:採集設定檔。
obcloud-exporter-1.0-SNAPSHOT-jar-with-dependencies.jar:OBCloud Exporter 程式。
readme.md:專案說明。
編輯設定檔 application.yaml。
# 監控名稱 aliyun_monitor: # 身份憑據 credential: access_key_id: xxx access_key_secret: xx region_id: ap-southeast-1 # 終端地址 end_point: xxx # 是否定時重新整理 metric 指標,預設為 false。 metric_meta_auto_refresh: false instances: # 執行個體 ID - instance_id: xxx # 查詢叢集下指定租戶,需配置 tenant_id tenant_id: xxx # 執行個體類型:cluster 叢集執行個體,tenant 租戶執行個體/Serverless 執行個體。 instance_type: tenant metrics:
參數說明:
access_key_id、access_key_secret:鑒權資訊,可在對應平台申請。具體操作,請參見,建立AccessKey。
region_id、end_point:請參見 公用雲端服務地區說明。
metric_meta_auto_refresh:是否定時重新整理 metric 指標,預設為 false。
instances:監控執行個體,可包含多個叢集、租戶執行個體,通過短劃線(-)並列填入。
instance_id:叢集 ID、serverless 執行個體 ID、租戶執行個體 ID。
說明不支援使用叢集下的租戶 ID。
instance_type:固定為 cluster(叢集)或 tenant(租戶)。當 instance_id 為叢集執行個體時,填入 cluster;當 instance_id 為租戶執行個體、Serverless 執行個體時,填入 tenant。
tenant_id:查詢叢集下指定租戶,需配置 tenant_id。
metrics:指標資訊,不填表示採集全部指標。當需要採集指定指標時,格式如下:
instances: -instance_id: xxx tenant_id: xxx instance_type: cluster metrics: - sql_all_rt - sql_delete_rt
說明metric 指標的詳細介紹,請參見 監控指標清單。
採集指標過多可能會影響採集速度,適當情況下拆分為多個 exporter。
通過 Docker 啟動 OBCloud Exporter。
在
/opt/obcloud-exporter
目錄下,構建 obcloud-exporter 容器。cd /opt/obcloud-exporter docker build -t obcloud-exporter:1.0 .
啟動容器或者映射外部設定檔啟動。
直接啟動 Docker 容器
docker run -itd -p9400:9400 --name obcloud-exporter obcloud-exporter:1.0
通過映射外部設定檔啟動 Docker 容器。
docker run -itd -p9400:9400 -v /opt/obcloud-exporter/application.yaml:/app/application.yaml --name obcloud-exporter obcloud-exporter:1.0
通過瀏覽器驗證部署結果,訪問對應 IP 位址的 9400 連接埠,確認是否擷取到監控資料。
說明實際使用中,根據實際配置的地址連接埠進行訪問。
建立 Prometheus 設定檔 prometheus.yml。
vi /usr/local/bin/prometheus.yml
編輯設定檔內容:
global: scrape_interval: 30s evaluation_interval: 30s scrape_configs: - job_name: obcloud-exporter-test static_configs: # 本機伺服器加連接埠 - targets: ['obcloud-exporter:9400'] labels: instance: obcloud-exporter
啟動 Prometheus 服務。
docker run -d \ -p 9090:9090 \ -v /usr/local/bin/prometheus.yml:/etc/prometheus/prometheus.yml \ --link obcloud-exporter \ --name prometheus \ prom/prometheus
確認 Prometheus 是否啟動成功。
sudo netstat -ntlp | grep 9090
通過 Prometheus 查看資料庫監控
通過瀏覽器訪問 Prometheus 服務地址:http://localhost:9090/targets
,查看相應的監控資訊。
監控指標清單
配置 OBCloud Exporter 時,其支援的指標項遵循 OceanBase 雲資料庫自身所涵蓋的指標範圍。在運行時,系統會同步 OceanBase 雲資料庫叢集的自訂監控指標,包括叢集自訂監控指標中的 叢集主機 部分及租戶層級下的所有自訂監控指標。詳細內容,請參見 叢集監控指標清單,租戶監控指標清單。
當 application.yaml 設定檔中的 metric_meta_auto_refresh 參數設定為 false 時,支援的指標保持初次訪問返回的結果;當 metric_meta_auto_refresh 參數設定為 true 時,則每 10 分鐘會更新一次支援的指標清單。