Apache Cassandra

Apache Cassandra 整合功能會收集要求、工作和儲存空間指標,突顯執行個體的負載。此外,這項整合服務也能收集與記憶體和垃圾收集相關的一般 JVM 指標。這項整合功能也會收集系統、偵錯和垃圾收集記錄。這些記錄會剖析為 JSON 酬載,其中包含訊息、Java 類別和行號等欄位。

如要進一步瞭解 Cassandra,請參閱 Apache Cassandra 說明文件。

必要條件

如要收集 Cassandra 遙測資料,請安裝 Ops Agent:

  • 如要查看指標,請安裝 2.6.0 以上版本。
  • 如要收集記錄,請安裝 2.5.0 以上版本。

這項整合支援 Cassandra 3.11 和 4.0 版。

設定 Cassandra 執行個體

如要公開 JMX 端點,您必須在啟動 JVM 時設定 com.sun.management.jmxremote.port 系統屬性。我們也建議將 com.sun.management.jmxremote.rmi.port 系統屬性設為相同通訊埠。如要從遠端公開 JMX 端點,您也必須設定 java.rmi.server.hostname 系統屬性。

根據預設,這些屬性是在 Cassandra 部署作業的 cassandra-env.sh 檔案中設定。

如要使用指令列引數設定系統屬性,請在啟動 JVM 時,在屬性名稱前加上 -D。例如,如要將 com.sun.management.jmxremote.port 設為通訊埠 7199,請在啟動 JVM 時指定下列內容:

-Dcom.sun.management.jmxremote.port=7199

設定 Cassandra 的 Ops Agent

按照設定 Ops Agent 指南,新增必要元素,從 Cassandra 執行個體收集遙測資料,然後重新啟動代理程式。

範例設定

下列指令會建立設定,收集及擷取 Cassandra 的遙測資料:

# Configures Ops Agent to collect telemetry from the app. You must restart the agent for the configuration to take effect.

set -e

# Check if the file exists
if [ ! -f /etc/google-cloud-ops-agent/config.yaml ]; then
  # Create the file if it doesn't exist.
  sudo mkdir -p /etc/google-cloud-ops-agent
  sudo touch /etc/google-cloud-ops-agent/config.yaml
fi

# Create a back up of the existing file so existing configurations are not lost.
sudo cp /etc/google-cloud-ops-agent/config.yaml /etc/google-cloud-ops-agent/config.yaml.bak

# Configure the Ops Agent.
sudo tee /etc/google-cloud-ops-agent/config.yaml > /dev/null << EOF
metrics:
  receivers:
    cassandra:
      type: cassandra
      endpoint: service:jmx:rmi:///jndi/rmi://127.0.0.1:7199/jmxrmi
  service:
    pipelines:
      cassandra:
        receivers:
          - cassandra
logging:
  receivers:
    cassandra_system:
      type: cassandra_system
    cassandra_debug:
      type: cassandra_debug
    cassandra_gc:
      type: cassandra_gc
  service:
    pipelines:
      cassandra:
        receivers:
          - cassandra_system
          - cassandra_debug
          - cassandra_gc
EOF

如要讓這些變更生效,請重新啟動 Ops Agent:

Linux

  1. 如要重新啟動代理程式,請在執行個體上執行下列指令:
    sudo systemctl restart google-cloud-ops-agent
    
  2. 如要確定代理程式已重新啟動,請執行下列指令,並驗證「指標代理程式」和「Logging 代理程式」元件是否已啟動:
    sudo systemctl status "google-cloud-ops-agent*"
    

Windows

  1. 使用 RDP 或類似工具連線至執行個體,然後登入 Windows。
  2. 在 PowerShell 圖示上按一下滑鼠右鍵,然後選取「Run as Administrator」(以系統管理員身分執行),開啟具有管理員權限的 PowerShell 終端機。
  3. 如要重新啟動代理程式,請執行下列 PowerShell 指令:
    Restart-Service google-cloud-ops-agent -Force
    
  4. 如要確定代理程式已重新啟動,請執行下列指令,並驗證「指標代理程式」和「Logging 代理程式」元件是否已啟動:
    Get-Service google-cloud-ops-agent*
    

設定記錄收集

如要從 Cassandra 擷取記錄,您必須為 Cassandra 產生的記錄建立接收器,然後為新的接收器建立管道。

如要為 cassandra_system 記錄檔設定接收器,請指定下列欄位:

欄位 預設 說明
exclude_paths 檔案系統路徑模式清單,用於從 include_paths 比對的集合中排除。
include_paths [/var/log/cassandra/system*.log] 檔案系統路徑清單,用於讀取每個檔案的結尾。路徑中可以使用萬用字元 (*),例如 /var/log/cassandra/system*.log。
record_log_file_path false 如果設為 true,則取得記錄項目的特定檔案路徑,會顯示在輸出記錄項目中,做為 agent.googleapis.com/log_file_path 標籤的值。使用萬用字元時,系統只會記錄取得記錄的檔案路徑。
type 這個值必須是 cassandra_system。
wildcard_refresh_interval 60s include_paths 中萬用字元檔案路徑的重新整理間隔。以時間長度表示,例如 30s 或 2m。如果記錄檔的輪替速度快於預設間隔,這項屬性在記錄檔處理量較高時可能很有用。

如要為 cassandra_debug 記錄檔設定接收器,請指定下列欄位:

欄位 預設 說明
exclude_paths 檔案系統路徑模式清單,用於從 include_paths 比對的集合中排除。
include_paths [/var/log/cassandra/debug*.log] 檔案系統路徑清單,用於讀取每個檔案的結尾。路徑中可以使用萬用字元 (*),例如 /var/log/cassandra/system*.log。
record_log_file_path false 如果設為 true,則取得記錄項目的特定檔案路徑,會顯示在輸出記錄項目中,做為 agent.googleapis.com/log_file_path 標籤的值。使用萬用字元時,系統只會記錄取得記錄的檔案路徑。
type 這個值必須是 cassandra_debug。
wildcard_refresh_interval 60s include_paths 中萬用字元檔案路徑的重新整理間隔。以時間長度表示,例如 30s 或 2m。如果記錄檔的輪替速度快於預設間隔,這項屬性在記錄檔處理量較高時可能很有用。

如要為 cassandra_gc 記錄檔設定接收器,請指定下列欄位:

欄位 預設 說明
exclude_paths 檔案系統路徑模式清單,用於從 include_paths 比對的集合中排除。
include_paths [/var/log/cassandra/gc.log.*.current] 檔案系統路徑清單,用於讀取每個檔案的結尾。路徑中可以使用萬用字元 (*),例如 /var/log/cassandra/system*.log。
record_log_file_path false 如果設為 true,則取得記錄項目的特定檔案路徑,會顯示在輸出記錄項目中,做為 agent.googleapis.com/log_file_path 標籤的值。使用萬用字元時,系統只會記錄取得記錄的檔案路徑。
type 這個值必須是 cassandra_gc。
wildcard_refresh_interval 60s include_paths 中萬用字元檔案路徑的重新整理間隔。以時間長度表示,例如 30s 或 2m。如果記錄檔的輪替速度快於預設間隔,這項屬性在記錄檔處理量較高時可能很有用。

記錄內容

logName 衍生自設定中指定的接收器 ID。LogEntry 內的詳細欄位如下。

cassandra_system 記錄在 LogEntry 中包含下列欄位:

欄位 類型 說明
jsonPayload.javaClass 字串 記錄來源的 Java 類別
jsonPayload.level 字串 記錄項目層級
jsonPayload.lineNumber 字串 記錄來源檔案的行號
jsonPayload.message 字串 記錄訊息,包括詳細的堆疊追蹤 (如有提供)
jsonPayload.module 字串 記錄來源的 Cassandra 模組
severity 字串 (LogSeverity) 記錄項目層級 (已翻譯)。

cassandra_debug 記錄在 LogEntry 中包含下列欄位:

欄位 類型 說明
jsonPayload.javaClass 字串 記錄來源的 Java 類別
jsonPayload.level 字串 記錄項目層級
jsonPayload.lineNumber 字串 記錄來源檔案的行號
jsonPayload.message 字串 記錄訊息
jsonPayload.module 字串 記錄來源的 Cassandra 模組
severity 字串 (LogSeverity) 記錄項目層級 (已翻譯)。

cassandra_gc 記錄在 LogEntry 中包含下列欄位:

欄位 類型 說明
jsonPayload.level 字串 記錄項目的層級
jsonPayload.message 字串 記錄訊息
jsonPayload.pid 字串 記錄訊息的 Java 程序 ID
jsonPayload.tid 字串 記錄訊息的 Java 程序執行緒 ID
jsonPayload.timeStopped 字串 JVM 停止垃圾收集的秒數
jsonPayload.timeStopping 字串 JVM 在垃圾收集前停止執行緒所花費的秒數
jsonPayload.uptime 字串 JVM 運作時間 (秒)
severity 字串 (LogSeverity) 記錄項目層級 (已翻譯)。

設定指標收集

如要從 Cassandra 擷取指標,您必須為 Cassandra 產生的指標建立接收器,然後為新的接收器建立管道。

這個接收器不支援在設定中使用多個執行個體,例如監控多個端點。所有這類執行個體都會寫入相同的時間序列,Cloud Monitoring 無法區分。

如要為 cassandra 指標設定接收器,請指定下列欄位:

欄位 預設 說明
collect_jvm_metrics true 設定接收器,一併收集支援的 JVM 指標。
collection_interval 60s 時間長度值,例如 30s 或 5m。
endpoint localhost:7199 JMX 服務網址,或用於建構服務網址的主機和通訊埠。這個值必須採用 service:jmx:<protocol>:<sap> 或 host:port 格式。host:port 表單中的值會用於建立 service:jmx:rmi:///jndi/rmi://<host>:<port>/jmxrmi 的服務網址。
password 如果 JMX 設為需要驗證,則為設定的密碼。
type 這個值必須是 cassandra。
username 如果 JMX 設為需要驗證,則為設定的使用者名稱。

監控的內容

下表列出 Ops Agent 從 Cassandra 執行個體收集的指標。

指標類型
種類、類型
受監控資源
標籤
workload.googleapis.com/cassandra.client.request.count
CUMULATIVE, INT64
gce_instance
operation
workload.googleapis.com/cassandra.client.request.error.count
CUMULATIVE, INT64
gce_instance
operation
status
workload.googleapis.com/cassandra.client.request.range_slice.latency.50p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.range_slice.latency.99p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.range_slice.latency.max
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.read.latency.50p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.read.latency.99p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.read.latency.max
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.write.latency.50p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.write.latency.99p
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.client.request.write.latency.max
GAUGE, DOUBLE
gce_instance
 
workload.googleapis.com/cassandra.compaction.tasks.completed
CUMULATIVE, INT64
gce_instance
 
workload.googleapis.com/cassandra.compaction.tasks.pending
GAUGE, INT64
gce_instance
 
workload.googleapis.com/cassandra.storage.load.count
GAUGE, INT64
gce_instance
 
workload.googleapis.com/cassandra.storage.total_hints.count
CUMULATIVE, INT64
gce_instance
 
workload.googleapis.com/cassandra.storage.total_hints.in_progress.count
GAUGE, INT64
gce_instance
 

驗證設定

本節說明如何確認 Cassandra 接收器設定正確。Ops Agent 可能需要一兩分鐘才會開始收集遙測資料。

如要確認 Cassandra 記錄檔是否已傳送至 Cloud Logging,請執行下列操作:

  1. 前往 Google Cloud 控制台的 「Logs Explorer」頁面:

    前往「Logs Explorer」(記錄檔探索工具)

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Logging」的結果。

  2. 在編輯器中輸入下列查詢,然後點選「執行查詢」:
    resource.type="gce_instance"
    (log_id("cassandra_system") OR log_id("cassandra_debug") OR log_id("cassandra_gc"))
    

如要確認 Cassandra 指標是否已傳送至 Cloud Monitoring,請按照下列步驟操作:

  1. 前往 Google Cloud 控制台的「Metrics Explorer」頁面:

    前往「Metrics Explorer」

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。

  2. 在查詢建立工具窗格的工具列中,選取名為 「PromQL」PromQL的按鈕。
  3. 在編輯器中輸入下列查詢,然後點選「執行查詢」:
    {"workload.googleapis.com/cassandra.client.request.count", monitored_resource="gce_instance"}
    

查看資訊主頁

如要查看 Cassandra 指標,您必須設定圖表或資訊主頁。Cassandra 整合功能提供一或多個資訊主頁。 設定整合作業且 Ops Agent 開始收集指標資料後,系統會自動安裝所有資訊主頁。

您也可以查看資訊主頁的靜態預覽畫面,不必安裝整合項目。

如要查看已安裝的資訊主頁,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Dashboards」(資訊主頁) 頁面:

    前往「Dashboards」(資訊主頁)

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。

  2. 選取「Dashboard List」(資訊主頁清單) 分頁標籤,然後選擇「Integrations」(整合) 類別。
  3. 按一下要查看的資訊主頁名稱。

如果您已設定整合,但尚未安裝資訊主頁,請確認 Ops Agent 是否正在執行。如果資訊主頁中的圖表沒有指標資料,資訊主頁就會安裝失敗。Ops Agent 開始收集指標後,系統就會為您安裝資訊主頁。

如要查看資訊主頁的靜態預覽畫面,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Integrations」(整合) 頁面:

    前往「Integrations」

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。

  2. 按一下「Compute Engine」部署平台篩選器。
  3. 找出 Cassandra 的項目,然後按一下「查看詳細資料」。
  4. 選取「資訊主頁」分頁標籤,即可查看靜態預覽畫面。如果已安裝資訊主頁,請點選「View dashboard」(查看資訊主頁) 前往該頁面。

如要進一步瞭解 Cloud Monitoring 中的資訊主頁,請參閱「資訊主頁和圖表」。

如要進一步瞭解如何使用「Integrations」(整合) 頁面,請參閱「管理整合」。

安裝警告政策

警告政策會指示 Cloud Monitoring 在發生指定情況時通知您。Cassandra 整合包含一或多項警告政策,可供您使用。您可以在 Monitoring 的「Integrations」(整合) 頁面查看及安裝這些警告政策。

如要查看可用警告政策的說明並安裝,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Integrations」(整合) 頁面:

    前往「Integrations」

    如果您是使用搜尋列尋找這個頁面,請選取子標題為「Monitoring」的結果。

  2. 找出 Cassandra 的項目,然後按一下「查看詳細資料」。
  3. 選取「快訊」分頁標籤。這個分頁會說明可用的警告政策,並提供安裝介面。
  4. 安裝警告政策。警告政策需要知道警告觸發時應將通知傳送至何處,因此您必須提供相關資訊,才能安裝。如要安裝警告政策,請按照下列步驟操作:
    1. 從可用警告政策清單中,選取要安裝的政策。
    2. 在「Configure notifications」(設定通知) 部分,選取一或多個通知管道。您可以選擇停用通知管道,但如果這麼做,警告政策就不會傳送通知。您可以在 Monitoring 中查看狀態,但不會收到通知。

      如要進一步瞭解通知管道,請參閱「管理通知管道」。

    3. 點選「建立政策」。

如要進一步瞭解 Cloud Monitoring 的警告政策,請參閱「警告簡介」。

如要進一步瞭解如何使用「Integrations」(整合) 頁面,請參閱「管理整合」。

後續步驟

如要瞭解如何使用 Ansible 安裝 Ops Agent、設定第三方應用程式,以及安裝範例資訊主頁,請觀看安裝 Ops Agent 以排解第三方應用程式的問題影片。