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

按照配置 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. 如需确认代理已重启,请运行以下命令并验证“Metrics Agent”和“Logging Agent”组件是否已启动:
    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. 如需确认代理已重启,请运行以下命令并验证“Metrics Agent”和“Logging Agent”组件是否已启动:
    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] 要通过对每个文件执行 tail 来读取的文件系统路径列表。路径中可以使用通配符 (*)。
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] 要通过对每个文件执行 tail 来读取的文件系统路径列表。路径中可以使用通配符 (*)。
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 页面:

    进入 Metrics Explorer

    如果您使用搜索栏查找此页面,请选择子标题为监控的结果。

  2. 在查询构建器窗格的工具栏中,选择名为  MQL PromQL 的按钮。
  3. 验证已在语言 (Language) 切换开关中选择 PromQL。语言切换开关位于同一工具栏中,用于设置查询的格式。
  4. 在编辑器中输入以下查询,然后点击运行查询
    {"workload.googleapis.com/elasticsearch.node.open_files", monitored_resource="gce_instance"}
    

查看信息中心

如需查看 Elasticsearch 指标,您必须配置一个图表或信息中心。 Elasticsearch 集成服务可为您提供一个或多个信息中心。在您配置集成并且 Ops Agent 开始收集指标数据后,所有信息中心都会自动安装。

您还可以在不安装集成的情况下查看信息中心的静态预览。

如需查看已安装的信息中心,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往 信息中心页面:

    前往信息中心

    如果您使用搜索栏查找此页面,请选择子标题为监控的结果。

  2. 选择信息中心列表标签页,然后选择集成类别。
  3. 点击您要查看的信息中心的名称。

如果您已配置集成,但尚未安装信息中心,请检查 Ops Agent 是否正在运行。如果信息中心内没有图表的指标数据,则信息中心的安装将失败。Ops Agent 开始收集指标后,系统会为您安装信息中心。

如需查看信息中心的静态预览,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往 集成页面:

    前往集成

    如果您使用搜索栏查找此页面,请选择子标题为监控的结果。

  2. 点击 Compute Engine 部署平台过滤条件。
  3. 找到 Elasticsearch 的条目,然后点击查看详细信息
  4. 选择信息中心标签页以查看静态预览。如果信息中心已安装,您可以通过点击查看信息中心来转到信息中心。

如需详细了解 Cloud Monitoring 中的信息中心,请参阅信息中心和图表

如需详细了解如何使用集成页面,请参阅管理集成

安装提醒政策

提醒政策会指示 Cloud Monitoring 在满足指定条件时通知您。 Elasticsearch 集成服务可提供一项或多项提醒政策供您使用。您可以从 Monitoring 中的集成页面查看和安装这些提醒政策。

如需查看可用提醒政策的说明并安装它们,请执行以下操作:

  1. 在 Google Cloud 控制台中,前往 集成页面:

    前往集成

    如果您使用搜索栏查找此页面,请选择子标题为监控的结果。

  2. 找到 Elasticsearch 的条目,然后点击查看详细信息
  3. 选择提醒标签页。此标签页提供可用提醒政策的说明,并提供一个安装政策的界面。
  4. 安装提醒政策。提醒政策需要知道将提醒触发的通知发送到何处,因此它们需要您提供信息才能进行安装。如需安装提醒政策,请执行以下操作:
    1. 从可用提醒政策列表中,选择您要安装的提醒政策。
    2. 配置通知部分中,选择一个或多个通知渠道。您可以选择禁止使用通知渠道,但如果您这样做,则您的提醒政策将以静默方式触发。您可以在 Monitoring 中查看其状态,但不会收到通知。

      如需详细了解通知渠道,请参阅管理通知渠道

    3. 点击创建政策

如需详细了解 Cloud Monitoring 中的提醒政策,请参阅提醒简介

如需详细了解如何使用集成页面,请参阅管理集成

后续步骤

如需查看有关如何使用 Ansible 安装 Ops Agent、配置第三方应用和安装示例信息中心的演示,请观看安装 Ops Agent 以排查第三方应用的问题视频。