本頁面列出可用於監控 AlloyDB Omni 執行個體的工具。
監控工具
下表列出可選擇及安裝的工具,用來監控 AlloyDB Omni 執行個體:
收件者 | 使用 | 說明 |
---|---|---|
監控效能和可用性 | Datadog | 監控 AlloyDB Omni 執行個體的效能、可用性和健康狀態。 |
從執行個體匯出可觀測性資料 | Postgres Exporter | 匯出可觀測性查詢的結果。安裝 Postgres Exporter |
以可讀取的格式擷取可觀測性資料 | Prometheus | 監控系統,以可讀取的格式傳回可觀測性資料。安裝 Prometheus |
在資訊主頁中顯示資料 | Grafana | 建立資訊主頁來顯示指標。安裝 Grafana |
擷取成效資料以供分析 | 成效快照報表 | 擷取效能資料,找出效能問題的原因。 |
安裝 Postgres Exporter
Postgres Exporter 是一種工具,可匯出 Prometheus (監控系統) 可讀取的格式,匯出工具內建許多標準查詢,您也可以視需求新增其他查詢和規則。您也可以設定其他安全性選項,例如 SSL 和使用者驗證。在本範例中,只會使用基本設定選項。
安裝
為 Postgres Exporter 建立目錄。
sudo mkdir /opt/postgres_exporter
sudo chown USER_ACCOUNT:USER_ACCOUNT /opt/postgres_exporter
cd /opt/postgres_exporter
下載 Postgres Exporter。
wget https://github.com/prometheus-community/postgres_exporter/releases/download/v0.15.0/postgres_exporter-0.15.0.linux-amd64.tar.gz
擷取 Postgres Exporter。
tar -xzvf postgres_exporter-0.15.0.linux-amd64.tar.gz
將 Postgres Exporter 複製到您建立的目錄。
cd postgres_exporter-0.15.0.linux-amd64
sudo cp postgres_exporter /usr/local/bin
為 Postgres Exporter 建立適當的
.env
檔案。cd /opt/postgres_exporter
sudo vi postgres_exporter.env
將資料來源新增至「
/opt/postgres_exporter/postgres_exporter.env
」,即可監控一或多個資料庫。如要監控單一資料庫,請新增下列程式碼:
DATA_SOURCE_NAME="postgresql://USERNAME:PASSWORD@POSTGRES_IP_ADDRESS:PORT/DATABASE_NAME?sslmode=disable"
如要監控所有資料庫,請新增下列程式碼行:
DATA_SOURCE_NAME="postgresql://USERNAME:PASSWORD@POSTGRES_IP_ADDRESS:PORT/?sslmode=disable"
請替換下列變數:
USERNAME
:登入資料庫的使用者名稱。PASSWORD
:使用者帳戶的密碼。POSTGRES_IP_ADDRESS
:AlloyDB Omni 執行個體的 IP 位址。PORT
:資料庫的代管通訊埠。DATABASE_NAME
:資料庫名稱。
將下列資訊新增至
/etc/systemd/system/postgres_exporter.service
,確保 Postgres Exporter 在重新啟動後仍可運作。[Unit] Description=Prometheus exporter for Postgresql Wants=network-online.target After=network-online.target [Service] User=postgres Group=postgres WorkingDirectory=/opt/postgres_exporter EnvironmentFile=/opt/postgres_exporter/postgres_exporter.env ExecStart=/usr/local/bin/postgres_exporter --web.listen-address=:POSTGRES_EXPORTER_PORT --web.telemetry-path=/metrics Restart=always [Install] WantedBy=multi-user.target
請替換下列變數:
POSTGRES_EXPORTER_PORT
:Postgres Exporter 的主機連接埠。建議使用連接埠9187
。
重新載入 Postgres Exporter。
sudo systemctl daemon-reload
啟動 Postgres Exporter。
sudo systemctl start postgres_exporter
sudo systemctl enable postgres_exporter
sudo systemctl status postgres_exporter
Postgres Exporter 現在應該可透過下列網址存取:
http://POSTGRES_EXPORTER_HOST_IP_ADDRESS:POSTGRES_EXPORTER_PORT/metrics
請替換下列變數:
POSTGRES_EXPORTER_HOST_IP_ADDRESS
:電腦的 IP 位址。POSTGRES_EXPORTER_PORT
:您在步驟 7 中使用的通訊埠。
Prometheus
Prometheus 是一種監控系統,可用來查詢 Postgres Exporter,並以可讀取的格式傳回可觀測性資料。
安裝
建立
prometheus
使用者。sudo groupadd --system prometheus
sudo useradd -s /sbin/nologin --system -g prometheus prometheus
為 Prometheus 建立目錄。
sudo mkdir /etc/prometheus
sudo mkdir /var/lib/prometheus
下載 Prometheus。
wget https://github.com/prometheus/prometheus/releases/download/v2.52.0/prometheus-2.52.0.linux-amd64.tar.gz
擷取 Prometheus。
sudo tar xvf prometheus*.tar.gz
cd prometheus*/
sudo mv prometheus /usr/local/bin
sudo mv promtool /usr/local/bin
將 Prometheus 的擁有權設為
prometheus
使用者。sudo chown prometheus:prometheus /usr/local/bin/prometheus
sudo chown prometheus:prometheus /usr/local/bin/promtool
將設定檔移至正確位置。
sudo mv consoles /etc/prometheus
sudo mv console_libraries /etc/prometheus
sudo mv prometheus.yml /etc/prometheus
將 Prometheus 目錄的擁有權設為
prometheus
使用者。sudo chown prometheus:prometheus /etc/prometheus
sudo chown prometheus:prometheus /etc/prometheus/*
sudo chown -R prometheus:prometheus /etc/prometheus/consoles
sudo chown -R prometheus:prometheus /etc/prometheus/console_libraries
sudo chown -R prometheus:prometheus /var/lib/prometheus
在
/etc/prometheus/prometheus.yml
中新增下列資訊,讓 Prometheus 可以查詢 Postgres Exporter。global: scrape_interval: 15s scrape_configs: - job_name: postgres static_configs: - targets: ['POSTGRES_EXPORTER_MACHINE_IP_ADDRESS:9187']
將下列資訊新增至
/etc/systemd/system/prometheus.service
,確保 Prometheus 在重新啟動後仍可運作。[Unit] Description=Prometheus Wants=network-online.target After=network-online.target [Service] User=prometheus Group=prometheus Type=simple ExecStart=/usr/local/bin/prometheus \ --config.file /etc/prometheus/prometheus.yml \ --storage.tsdb.path /var/lib/prometheus/ \ --web.console.templates=/etc/prometheus/consoles \ --web.console.libraries=/etc/prometheus/console_libraries [Install] WantedBy=multi-user.target
重新載入 Prometheus。
sudo systemctl daemon-reload
啟動 Prometheus。
sudo systemctl start prometheus
sudo systemctl enable prometheus
sudo systemctl status prometheus
現在應該可以透過下列網址存取 Prometheus:
http://PROMETHEUS_HOST_IP_ADDRESS:9090
請替換下列變數:
PROMETHEUS_HOST_IP_ADDRESS
:機器的 IP 位址。
Grafana
Grafana 是一種資訊主頁工具,可透過資訊主頁向使用者公開 Prometheus 指標。Postgres Exporter 提供多個標準資訊主頁,而這個可觀測性範例會運用這些資訊主頁。Grafana 可透過一般 apt
和 yum
存放區取得,我們會使用這些存放區安裝這項產品。
安裝
安裝 Grafana。
如為 Ubuntu 和 Debian 系統,請執行下列指令:
sudo apt-get update
sudo apt-get install grafana
如果是 RHEL、CentOS 或 Rocky Linux 系統,請完成下列工作:
匯入 GPG 金鑰。
wget -q -O gpg.key https://rpm.grafana.com/gpg.key
sudo rpm --import gpg.key
建立
/etc/yum.repos.d/grafana.repo
檔案,並加入下列內容:[grafana] name=grafana baseurl=https://rpm.grafana.com repo_gpgcheck=1 enabled=1 gpgcheck=1 gpgkey=https://rpm.grafana.com/gpg.key sslverify=1 sslcacert=/etc/pki/tls/certs/ca-bundle.crt
安裝 Grafana。
sudo dnf install grafana
重新載入 Grafana。
sudo systemctl daemon-reload
啟動 Grafana。
sudo systemctl start grafana-server
sudo systemctl enable grafana-server
sudo systemctl status grafana-server
Grafana 現在應該可透過下列網址存取:
http://GRAFANA_HOST_IP_ADDRESS:9090
請替換下列變數:
GRAFANA_HOST_IP_ADDRESS
:機器的 IP 位址。
載入資訊主頁
如需設定及操作 Grafana 的一般操作說明,請參閱「設定 Grafana」。有許多公開資訊主頁可供使用,但我們建議使用下列 PostgreSQL 統計資料資訊主頁。
如要載入資訊主頁,請完成下列工作:
設定 Grafana。
建立新資訊主頁。
依序前往「首頁」 >「資訊主頁」。
點按「New」(新增)。
選取「新增資訊主頁」。
按一下「匯入資訊主頁」。
輸入下列網址: https://grafana.com/grafana/dashboards/13494-postgresql-statistics/。
按一下「載入」。
將資訊主頁的「名稱」變更為
PRODUCT_NAME PostgreSQL statistics
。將
PRODUCT_NAME
替換為產品名稱。從「Prometheus」欄位選取資料來源。
按一下「匯入」。
成效數據匯報
效能快照報表是 AlloyDB Omni 內建工具,可擷取及分析效能資料,協助您找出效能問題的原因。這項工具可與其他 AlloyDB Omni 可觀測性功能相輔相成,例如系統洞察、查詢洞察和 Metrics Explorer,這些功能可提供執行個體的即時指標。
詳情請參閱「比較效能快照來提升資料庫效能」。