正式上市前 (階段):2026-02-26

7 使用 Prometheus 監控 Besu 指標

您可以使用 Prometheus 和 kube-prometheus-stack 從在 Kubernetes 叢集中執行的 Besu 節點擷取指標。

若要安裝監督功能,請使用 Helm、kube-prometheus-stack 以及 Consensys/quorum-kubernetes 儲存區域中維護的預先定義值檔案 (monitoring.yml)。在此案例中,Prometheus 會在 Istio 服務網格內運作,並透過相互 TLS 安全地刮除指標。kube-prometheus-stack 套裝軟體會安裝下列軟體。
  • Prometheus
  • Prometheus 運算子
  • Grafana
  • 警示管理員
  • 標準 Kubernetes 匯出器

在 kube-prometheus-stack 架構中,Prometheus 使用稱為 ServiceMonitor 的 Kubernetes 自訂資源來尋找廢除目標。此資源定義要報廢的服務、顯示測量結果的連接埠和路徑,以及 TLS 和雙向 TLS 的組態。當您使用 Helm 來安裝 kube-prometheus-stack 時,會自動為 kube-state-metrics 和 node-exporter 等元件建立 ServiceMonitor 資源。不過,若要刮除 Oracle Blockchain Platform Enterprise Edition for Hyperledger Besu 測量結果,您必須建立和管理自己的 ServiceMonitor 資源。

安裝下列先決條件。
  • Helm v3.x. 您可以執行下列命令來驗證您的 Helm 版本。
    helm version
  • kubectl
此外,您還必須具備 Kubernetes 叢集的命令行存取權。如需詳細資訊,請參閱連線至 Oracle Kubernetes 引擎
  1. 使用與 Besu 相容的 monitoring.yml 檔案來安裝 kube-prometheus-stack。
    1. 輸入下列命令以下載檔案。monitoring.yml 檔案保存在 Consensys/quorum-kubernetes 儲存區域中。
      curl -o monitoring.yml \ 
      https://raw.githubusercontent.com/Consensys/quorum-kubernetes/master/helm/values/monitoring.yml 
    2. 如有需要,請先更新 Grafana 管理員密碼,並在部署前在 monitoring.yml 中設定警示接收器 (例如電子郵件或 Slack)。
    3. 如果尚未顯示,請新增 Prometheus 社群 Helm 儲存庫
      helm repo add prometheus-community https://prometheus-community.github.io/helm-charts 
      helm repo update 
    4. 在專用於監督的命名空間中安裝監督堆疊。在以下命令中,命名空間稱為監督
      helm install monitoring prometheus-community/kube-prometheus-stack \ 
        --version 34.10.0 \ 
        --namespace monitoring \ 
        --create-namespace \ 
        --values monitoring.yml 
    5. 執行下列命令以檢查部署狀態。
      kubectl get pods -n monitoring -l release=monitoring
    安裝程序會將監督堆疊部署到 monitoring 命名空間中,套用 monitoring.yml 檔案的覆寫以達到 Besu 相容性,並建立堆疊所需的標準 Kubernets ServiceMonitor 資源。
  2. 將 Istio 註解新增至 monitoring.yml 檔案,以啟用 Prometheus 的 Istio sidecar 插入。Prometheus 必須加入 Istio 網線,透過雙向 TLS 刮除 Besu 端點。開啟 monitoring.yml 檔案進行編輯,然後尋找下列段落。
    prometheus: 
      prometheusSpec: 
        podMetadata:
    新增下列 Istio 註解。
    prometheus: 
      prometheusSpec: 
        podMetadata: 
          annotations: 
            sidecar.istio.io/inject: "true" 
            sidecar.istio.io/userVolumeMount: | 
              [{"name": "istio-certs", "mountPath": "/etc/istio-certs", "readOnly": true}] 
            proxy.istio.io/config: | 
              proxyMetadata: 
                OUTPUT_CERTS: /etc/istio-certs 
              proxyMetadata.INBOUND_CAPTURE_PORTS: "" 
    這些註解會將 Prometheus 新增至 Istio 網格、設定 Istio 將工作負載 mTLS 憑證寫入共用磁碟區、防止 Envoy 攔截 Prometheus 內送流量,以及讓 Istio 產生的憑證可供 Prometheus 容器使用。
  3. 將磁碟區和磁碟區掛載資訊新增至 monitoring.yml 檔案,以將 Istio 憑證掛載至 Prometheus。尋找 monitoring.yml 檔案中的下列文字。
    尋找最初是空的 volumes 區段。
        volumes: []
    更新 volumes 區段,如下列文字所示。
        volumes: 
          - name: istio-certs 
            emptyDir: 
              medium: Memory 
     
    尋找最初是空的 volumeMounts 區段。
        volumeMounts: []
    更新 volumeMounts 區段,如下列文字所示。
        volumeMounts: 
          - name: istio-certs 
            mountPath: /etc/prom-certs 
            readOnly: true
    Istio 產生的憑證現在可在 Prometheus 內部取得,網址為:/etc/prom-certs/.
  4. 套用更新的組態。
    1. 使用修改過的值檔案升級現有的 Helm 版本。
      helm upgrade monitoring prometheus-community/kube-prometheus-stack \ 
        --namespace monitoring \ 
        --values monitoring.yml 
    2. 確認 Prometheus Pod 已重新啟動,並且正在使用 Istio 側邊欄執行。
      kubectl get pods -n monitoring | grep prometheus 
  5. 使用下列範例建立 Besu 測量結果的 ServiceMonitor 資源。
    apiVersion: monitoring.coreos.com/v1 
    kind: ServiceMonitor 
    metadata: 
      name: obp-besu-rpc-metrics 
      namespace: <besu-namespace> 
      labels: 
        release: monitoring   # Must match Prometheus serviceMonitorSelector 
    spec: 
      selector: 
        matchLabels: 
          app: besu 
          besu-role: rpc 
      namespaceSelector: 
        matchNames: 
          - <besu-namespace> 
      endpoints: 
        - port: metrics 
          path: /metrics 
          interval: 30s 
          scheme: https 
          tlsConfig: 
            caFile: /etc/prom-certs/root-cert.pem 
            certFile: /etc/prom-certs/cert-chain.pem 
            keyFile: /etc/prom-certs/key.pem 
            insecureSkipVerify: true 
    憑證路徑必須與掛載的位置 (etc/prom-certs) 相符。release 標籤必須與 Prometheus 中的 serviceMonitorSelector 值相符。先前範例會從 RPC 節點 (besu-role: rpc) 擷取度量。若要從啟動節點、驗證程式節點或歸檔節點廢除測量結果,請建立個別的 ServiceMonitor 資源,並據此編輯 besu-role 標籤 (bootnodevalidatorarchive)。
  6. 確認已在 Prometheus 中收集度量。
    1. 執行下列命令以轉送 Prometheus 服務的連接埠。
      kubectl port-forward -n <namespace> prometheus-monitoring-kube-prometheus-prometheus-
    2. 開啟 http://localhost:9090,然後依序選取狀態目標。確認 Besu 目標處於 UP 狀態。
    3. 執行範例查詢,如下列範例。
      besu_blockchain_chain_head_transaction_count 
  7. 存取 Grafana 以確認正在收集指標。執行下列命令以轉送 Grafana 服務的連接埠。
    kubectl port-forward svc/monitoring-grafana -n <namespace> 3000:80 
    • URL:http://localhost:3000
    • 使用者名稱:admin
    • 執行下列命令以擷取密碼:
      kubectl get secret -n <namespace> monitoring-grafana \ 
      -o jsonpath="{.data.admin-password}" | base64 --decode ; echo