OceanBase 監控工具 OBAgent

OceanBase資料庫發表於2021-11-17
作者簡介:海芊,一個對技術充滿熱情的文件工程師。

背景

運維 OceanBase 涉及到很多相關的變數和引數。實際生產中,如果只靠單一的黑屏工具檢視這些引數的話,不僅會流程繁瑣,而且檢視結果也不夠直觀,這就降低了我們的工作效率。此外,如果想查詢一些表示式,也不是很方便。基於這種背景,OceanBase 監控工具 OBAgent 應運而生。

OBAgent 是一個監控採集框架。OBAgent 支援推、拉兩種資料採集模式,可以滿足不同的應用場景。OBAgent 預設支援的外掛包括主機資料採集、OceanBase 資料庫指標的採集、監控資料標籤處理和 Prometheus 協議的 HTTP 服務。要使 OBAgent 支援其他資料來源的採集,或者自定義資料的處理流程,您只需要開發對應的外掛即可。

OBAgent 是一個開源的專案,感興趣的小夥伴可以去  GitHub 看看專案程式碼。更多關於 OBAgent 的資訊,參考  OBAgent 文件

P.S. 配合視訊教程一起食用效果更佳噢~~視訊教程,點選  OceanBase 監控工具 OBAgent

如何使用

介紹完 OBAgent 的功能,接下來我們聊聊如何使用它。要使用 OBAgent,我們首先要把這個程式啟動起來。然後再使用 Prometheus 接入,雖然 Prometheus 是個可選的步驟,但是使用起來還是很方便的,這裡我們也介紹一下。

部署 OBAgent 有兩種方式,一種是手動部署,一種是使用 OBD 部署。手動部署 OBAgent 需要配置 KV、monagent 和 Prometheus (可選,根據你的實際需求決定)。更多資訊,參考  配置檔案文件。相比之下,使用  OceanBase 開源軟體的安裝部署工具 OBD 部署就要簡單很多。只要一個 OBAgent 配置檔案就能把服務啟起來。並且,OBD 還會根據你的實際情況自動生成一份 Prometheus 的配置檔案,還會把 Prometheus 的規則寫好。你可以使用預設的規則,也可以根據需要對規則做出調整。

部署 OBAgent

接下來我們使用 OBD,一起部署 OBAgent 服務。OBAgent 可以跟 OceanBase 叢集同時啟動,也可以先啟動一個 ObceanBase 叢集,再啟動 OBAgent。我在啟動 OBAgent 之前已經有了一個 ObceanBase 叢集,因此我單獨啟動 OBAgent 就可以了。我的叢集資訊如下:

OceanBase 監控工具 OBAgent

使用 OBD 啟動 OBAgent 的示例配置檔案參考  這裡,部署文件參考  這裡

OBAgent 的以下配置欄位必須要跟 OceanBase 一樣:

obagent:
  global:
    # Username for HTTP authentication. The default value is admin.
    http_basic_auth_user: admin
    # Password for HTTP authentication. The default value is root.
    http_basic_auth_password: root
    # Username for debug service. The default value is admin.
    pprof_basic_auth_user: admin
    # Password for debug service. The default value is root.
    pprof_basic_auth_password: root
    
    # 以下配置必須與 OceanBase 資料庫一致
    # Monitor username for OceanBase Database. The user must have read access to OceanBase Database as a system tenant. The default value is root.
    monitor_user: root
    # Monitor password for OceanBase Database. The default value is empty. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the root_password in oceanbase-ce.
    monitor_password: 
    # The SQL port for observer. The default value is 2881. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the mysql_port in oceanbase-ce.
    sql_port: 2881
    # The RPC port for observer. The default value is 2882. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the rpc_port in oceanbase-ce.
    rpc_port: 2882
    # Cluster name for OceanBase Database. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the appname in oceanbase-ce.
    cluster_name: obcluster
    # Cluster ID for OceanBase Database. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the cluster_id in oceanbase-ce.
    cluster_id: 1
    # Zone name for your observer. The default value is zone1. When a depends exists, OBD gets this value from the oceanbase-ce of the depends. The value is the same as the zone name in oceanbase-ce.
    zone_name: zone1
    # Monitor status for OceanBase Database.  Active is to enable. Inactive is to disable. The default value is active. When you deploy an cluster automatically, OBD decides whether to enable this parameter based on depends.

然後使用以下命令啟動 OBAgent:

obd cluster deploy only-obagent -c only-obagent.yaml
obd cluster start only-obagent

使用以下命令確認程式是否啟動成功:

ps -ef | grep monagent
admin     3415  3373  0 19:57 pts/0    00:00:00 grep --color=auto monagent
admin    28112     1 15 18:55 ?        00:09:51 /home/admin/obagent/bin/monagent -c conf/monagent.yaml

啟動成功之後就可以檢視相關的指標了:

# 檢視主機指標curl --user admin:root 再檢視ob基本指標curl --user admin:root 也可以檢視指定指標curl --user admin:root | grep ob_cache_size_bytes

其中,主機指標的返回結果如下圖:

OceanBase 監控工具 OBAgent

部署 Prometheus(可選)

接下來我們再試試 Prometheus,大家自行下載,相信都會。使用 OBD 部署 OBAgent 會自動生成一份 Prometheus 配置檔案,我們要把目標機器上的配置檔案複製到中控機器。

# 配置檔案路徑$obagent_working_directory/conf/prometheus_config/

來到 Prometheus 的安裝目錄,現在啟動它:

cd prometheus-2.30.3.linux-amd64./prometheus --config.file=../prometheus_config/prometheus.yaml

開啟瀏覽器,輸入以下網址


就可以用 Prometheus 檢視 OceanBase 的指標了。alerts 告警,用來報告異常情況:

OceanBase 監控工具 OBAgent

接下是 Status,可以看到 Rules 下面的配置規則,當指標超出規則時就會告警。

OceanBase 監控工具 OBAgent

現在我們嘗試查詢一個表示式,以當前活躍會話數為例,可以看到具體時間的活躍會話數:

OceanBase 監控工具 OBAgent

其他的功能請大家自行探索。

參與更多技術交流,請至 OceanBase 社群版 。

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/69909943/viewspace-2842780/,如需轉載,請註明出處,否則將追究法律責任。

相關文章