Elasticsearch 8.0 以上版本和 9.0 以上版本

Elasticsearch 是以 Lucene 搜尋程式庫為基礎的開放原始碼搜尋伺服器。它會在多個作業系統上的 Java 虛擬機器中執行。elasticsearch 接收器會從 Elasticsearch 執行個體收集節點和叢集層級的遙測資料。

如要進一步瞭解 Elasticsearch,請參閱 Elasticsearch 8.0 以上和 9.0 以上版本說明文件

必要條件

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

  • 如要使用指標,請安裝 2.60.0 以上版本。
  • 如要查看記錄,請安裝 2.60.0 以上版本。

這項整合作業支援 Elasticsearch 8.0 以上和 9.0 以上版本。

設定 Elasticsearch 執行個體

如果啟用 Elasticsearch 安全性功能,您必須設定具有 monitormanage 叢集權限的使用者。

設定 Elasticsearch 適用的 Ops Agent

按照「設定作業套件代理程式」指南操作,新增必要元素,從 Elasticsearch 執行個體收集遙測資料,然後重新啟動代理程式

範例設定

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

# 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:
    elasticsearch:
      type: elasticsearch
      endpoint: https://localhost:9200
      username: elastic
      password: elastic_test_password_123
      insecure_skip_verify: true
      insecure: false
  service:
    pipelines:
      elasticsearch:
        receivers:
          - elasticsearch

logging:
  receivers:
    elasticsearch_gc:
      type: elasticsearch_gc
    elasticsearch_json:
      type: elasticsearch_json
  service:
    pipelines:
      elasticsearch:
        receivers:
          - elasticsearch_gc
          - elasticsearch_json
EOF

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

Linux

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

Windows

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

設定記錄檔收集作業

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

如要設定 elasticsearch_json 記錄的接收器,請指定下列欄位:

欄位 預設 說明
exclude_paths 要從 include_paths 比對的集合中排除的檔案系統路徑模式清單。
include_paths [/var/log/elasticsearch/*_server.json, /var/log/elasticsearch/*_deprecation.json, /var/log/elasticsearch/*_index_search_slowlog.json, /var/log/elasticsearch/*_index_indexing_slowlog.json, /var/log/elasticsearch/*_audit.json] 要讀取的檔案系統路徑清單,每個檔案都以尾部讀取方式讀取。路徑中可使用萬用字元 (*)。
record_log_file_path false 如果設為 true,輸出記錄項目中就會顯示記錄記錄的來源檔案路徑,做為 agent.googleapis.com/log_file_path 標籤的值。使用萬用字元時,系統只會記錄取得記錄的檔案路徑。
type 這個值必須是 elasticsearch_json
wildcard_refresh_interval 60s include_paths 中萬用字元檔案路徑的重新整理間隔。以時間長度表示,例如 30s2m。在記錄吞吐量較高的情況下,記錄檔的輪替速度會比預設間隔更快,這時這項屬性就可能派上用場。

如要設定 elasticsearch_gc 記錄的接收器,請指定下列欄位:

欄位 預設 說明
exclude_paths 要從 include_paths 比對的集合中排除的檔案系統路徑模式清單。
include_paths [/var/log/elasticsearch/gc.log] 要讀取的檔案系統路徑清單,每個檔案都以尾部讀取方式讀取。路徑中可使用萬用字元 (*)。
record_log_file_path false 如果設為 true,輸出記錄項目中就會顯示記錄記錄的來源檔案路徑,做為 agent.googleapis.com/log_file_path 標籤的值。使用萬用字元時,系統只會記錄取得記錄的檔案路徑。
type 這個值必須是 elasticsearch_gc
wildcard_refresh_interval 60s include_paths 中萬用字元檔案路徑的重新整理間隔。以時間長度表示,例如 30s2m。在記錄吞吐量較高的情況下,記錄檔的輪替速度會比預設間隔更快,這時這項屬性就可能派上用場。

記錄內容

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

elasticsearch_json 記錄包含 LogEntry 中的下列欄位:

欄位 類型 說明
jsonPayload.ecs.version 字串 ECS 版本
jsonPayload.elasticsearch.cluster.name 字串 以 ECS 格式發出記錄檔記錄的叢集名稱
jsonPayload.elasticsearch.cluster.uuid 字串 以 ECS 格式發出記錄的叢集 UUID
jsonPayload.elasticsearch.node.name 字串 以 ECS 格式發出記錄檔記錄的節點名稱
jsonPayload.event 字串 ECS 格式的活動資訊
jsonPayload.log 字串 ECS 格式的記錄詳細資料
jsonPayload.log.level 字串 ECS 格式的記錄項目層級
jsonPayload.log.logger 字串 以 ECS 格式發出記錄的記錄器元件
jsonPayload.message 字串 記錄訊息
jsonPayload.process.thread.name 字串 以 ECS 格式發出記錄的執行緒名稱
jsonPayload.service.name 字串 以 ECS 格式發出記錄的服務名稱
severity 字串 (LogSeverity) 記錄項目的嚴重性等級

elasticsearch_gc 記錄包含 LogEntry 中的下列欄位:

欄位 類型 說明
jsonPayload.gc_run 數字 垃圾收集器執行作業
jsonPayload.message 字串 記錄訊息
jsonPayload.type 字串 記錄類型
severity 字串 (LogSeverity) 記錄項目層級 (已翻譯)。

設定指標收集

如要從 Elasticsearch 擷取指標,請為 Elasticsearch 產生的指標建立接收器,然後為新的接收器建立管道。

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

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

欄位 預設 說明
ca_file CA 憑證的路徑。做為用戶端,這會驗證伺服器憑證。如果留空,接收器會使用系統根 CA。
cert_file 用於 mTLS 必要連線的 TLS 憑證路徑。
collection_interval 60s 時間長度值,例如 30s5m
endpoint https://localhost:9200 Elasticsearch REST API 的基本網址。Elasticsearch 9.0 以上版本預設使用 HTTPS。
insecure false 設定是否使用安全的 TLS 連線。Elasticsearch 9.0 以上版本預設使用 HTTPS。
insecure_skip_verify true 設定是否略過驗證憑證。如果是自行簽署的憑證 (測試環境中常見),請設為 true
key_file 用於 mTLS 必要連線的 TLS 金鑰路徑。
password 用於 Elasticsearch 驗證的密碼。適用於 Elasticsearch 9.0 以上版本。
type 這個值必須是 elasticsearch
username elastic 用於 Elasticsearch 驗證的使用者名稱。適用於 Elasticsearch 9.0 以上版本。

監控的內容

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

指標類型
類型
受監控資源
標籤
workload.googleapis.com/elasticsearch.breaker.memory.estimated
GAUGEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.breaker.memory.limit
GAUGEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.breaker.tripped
CUMULATIVEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.cluster.data_nodes
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.cluster.health
GAUGEINT64
gce_instance
instrumentation_source
status
workload.googleapis.com/elasticsearch.cluster.in_flight_fetch
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.cluster.nodes
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.cluster.pending_tasks
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.cluster.published_states.differences
GAUGEINT64
gce_instance
instrumentation_source
state
workload.googleapis.com/elasticsearch.cluster.published_states.full
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.cluster.shards
GAUGEINT64
gce_instance
instrumentation_source
state
workload.googleapis.com/elasticsearch.cluster.state_queue
GAUGEINT64
gce_instance
instrumentation_source
state
workload.googleapis.com/elasticsearch.cluster.state_update.count
CUMULATIVEINT64
gce_instance
instrumentation_source
state
workload.googleapis.com/elasticsearch.cluster.state_update.time
CUMULATIVEINT64
gce_instance
instrumentation_source
state
type
workload.googleapis.com/elasticsearch.indexing_pressure.memory.limit
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.indexing_pressure.memory.total.primary_rejections
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.indexing_pressure.memory.total.replica_rejections
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.memory.indexing_pressure
GAUGEINT64
gce_instance
instrumentation_source
stage
workload.googleapis.com/elasticsearch.node.cache.count
GAUGEINT64
gce_instance
instrumentation_source
type
workload.googleapis.com/elasticsearch.node.cache.evictions
CUMULATIVEINT64
gce_instance
cache_name
instrumentation_source
workload.googleapis.com/elasticsearch.node.cache.memory.usage
GAUGEINT64
gce_instance
cache_name
instrumentation_source
workload.googleapis.com/elasticsearch.node.cluster.connections
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.cluster.io
CUMULATIVEINT64
gce_instance
direction
instrumentation_source
workload.googleapis.com/elasticsearch.node.disk.io.read
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.disk.io.write
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.documents
GAUGEINT64
gce_instance
instrumentation_source
state
workload.googleapis.com/elasticsearch.node.fs.disk.available
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.fs.disk.free
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.fs.disk.total
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.http.connections
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.ingest.documents
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.ingest.documents.current
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.ingest.operations.failed
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.open_files
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.operations.completed
CUMULATIVEINT64
gce_instance
instrumentation_source
operation
workload.googleapis.com/elasticsearch.node.operations.time
CUMULATIVEINT64
gce_instance
instrumentation_source
operation
workload.googleapis.com/elasticsearch.node.pipeline.ingest.documents.current
GAUGEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.node.pipeline.ingest.documents.preprocessed
GAUGEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.node.pipeline.ingest.operations.failed
CUMULATIVEINT64
gce_instance
instrumentation_source
name
workload.googleapis.com/elasticsearch.node.script.cache_evictions
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.script.compilation_limit_triggered
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.script.compilations
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.shards.data_set.size
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.shards.reserved.size
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.shards.size
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.thread_pool.tasks.finished
CUMULATIVEINT64
gce_instance
instrumentation_source
state
thread_pool_name
workload.googleapis.com/elasticsearch.node.thread_pool.tasks.queued
GAUGEINT64
gce_instance
instrumentation_source
thread_pool_name
workload.googleapis.com/elasticsearch.node.thread_pool.threads
GAUGEINT64
gce_instance
instrumentation_source
state
thread_pool_name
workload.googleapis.com/elasticsearch.node.translog.operations
CUMULATIVEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.translog.size
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.node.translog.uncommitted.size
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.os.cpu.load_avg.15m
GAUGEDOUBLE
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.os.cpu.load_avg.1m
GAUGEDOUBLE
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.os.cpu.load_avg.5m
GAUGEDOUBLE
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.os.cpu.usage
GAUGEINT64
gce_instance
instrumentation_source
workload.googleapis.com/elasticsearch.os.memory
GAUGEINT64
gce_instance
instrumentation_source
state

驗證設定

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

如要確認 Elasticsearch 記錄已傳送至 Cloud Logging,請按照下列步驟操作:

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

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

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

  2. 在編輯器中輸入下列查詢,然後按一下「執行查詢」
    resource.type="gce_instance"
    (log_id("elasticsearch_json") OR log_id("elasticsearch_gc"))
    

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

  1. 前往 Google Cloud 控制台的 「指標探索器」頁面:

    前往 Metrics Explorer

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

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

查看資訊主頁

如要查看 Elasticsearch 指標,必須先設定圖表或資訊主頁。 Elasticsearch 整合功能包含一或多個資訊主頁。 設定整合作業後,系統就會自動安裝所有資訊主頁,而 Ops Agent 也會開始收集指標資料。

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

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

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

    前往「Dashboards」(資訊主頁)

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

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

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

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

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

    前往「整合」

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

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

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

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

安裝快訊政策

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

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

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

    前往「整合」

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

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

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

    3. 按一下「建立政策」

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

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

後續步驟

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