Elasticsearch

Elasticsearch 是基于 Lucene 搜索库的开源搜索服务器。它可在运行多种操作系统的 Java 虚拟机中运行。elasticsearch 接收器从 Elasticsearch 实例收集节点级和集群级遥测数据。

如需详细了解 Elasticsearch,请参阅 Elasticsearch 文档

前提条件

如需收集 Elasticsearch 遥测数据,您必须安装 Ops Agent

  • 对于指标,请安装 2.10.0 版或更高版本。2.21.0 版中添加了更多指标。
  • 对于日志,请安装 2.9.0 版或更高版本。

此集成支持 Elasticsearch 7.9 及更高版本。

配置 Elasticsearch 实例

如果您启用了 Elasticsearch 安全功能,则必须配置一个拥有 monitormanage 集群权限的用户。

为 Elasticsearch 配置 Ops Agent

按照配置 Ops Agent 指南,添加从 Elasticsearch 实例收集遥测数据所需的元素并重启代理

配置示例

以下命令会创建相关配置来收集和注入 Elasticsearch 的遥测数据,并重启 Ops Agent。

# Configures Ops Agent to collect telemetry from the app and restart Ops Agent.

set -e

# 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
  service:
    pipelines:
      elasticsearch:
        receivers:
          - elasticsearch

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

sudo service google-cloud-ops-agent restart
sleep 60

配置日志收集

如需从 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 中通配符文件路径的刷新间隔。指定为 time.ParseDuration 可解析的时长,例如 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 中通配符文件路径的刷新间隔。指定为 time.ParseDuration 可解析的时长,例如 30s2m。该属性在高日志记录吞吐量下可能很有用,因为日志文件的轮替速度快于默认时间间隔。

记录的内容

logName 派生自配置中指定的接收器 ID。LogEntry 中的详细字段如下所示。 日志条目不包含任何空白字段或缺失字段。

elasticsearch_json 日志包含 LogEntry 中的以下字段:

字段 类型 说明
jsonPayload.cluster 字符串 发出日志记录的集群
jsonPayload.cluster.name 字符串 发出日志记录的集群的名称
jsonPayload.cluster.uuid 字符串 发出日志记录的集群的 UUID
jsonPayload.component 字符串 发出日志的 Elasticsearch 的组件
jsonPayload.level 字符串 日志条目级别
jsonPayload.message 字符串 日志消息
jsonPayload.node 字符串 发出日志记录的节点
jsonPayload.node.name 字符串 发出日志记录的节点的名称
jsonPayload.node.uuid 字符串 发出日志记录的节点的 UUID
jsonPayload.type 字符串 日志类型,表明记录来自哪个日志(例如 server 表示此 LogEntry 来自服务器日志)
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 http://localhost:92002 Elasticsearch REST API 的基准网址。
insecure true 设置是否使用安全 TLS 连接。如果设置为 false,则启用 TLS。
insecure_skip_verify false 设置是否跳过证书验证。如果 insecure 设置为 true,则不使用 insecure_skip_verify 值。
key_file 用于要求 mTLS 的连接的 TLS 密钥的路径。
password 用于 Elasticsearch 身份验证的密码。如果设置了用户名,则必须指定该字段。
type 此值必须为 elasticsearch。
username 用于 Elasticsearch 身份验证的用户名。如果设置了密码,则必须指定该字段。

监控的内容

下表提供了 Ops Agent 从 Elasticsearch 实例收集的指标列表。

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

验证配置

本部分介绍如何验证您是否正确配置了 Elasticsearch 接收器。Ops Agent 可能需要一两分钟才会开始收集遥测数据。

如需验证 Elasticsearch 日志是否已发送到 Cloud Logging,请执行以下操作:

  1. 在 Google Cloud 控制台的导航面板中,选择 Logging,然后选择 Logs Explorer

    前往 Logs Explorer

  2. 在编辑器中输入以下查询,然后点击运行查询
    resource.type="gce_instance"
    (log_id("elasticsearch_json") OR log_id("elasticsearch_gc"))
    

如需验证 Elasticsearch 指标是否已发送到 Cloud Monitoring,请执行以下操作:

  1. 在 Google Cloud 控制台的导航面板中,选择 Monitoring,然后选择  Metrics Explorer

    进入 Metrics Explorer

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

查看信息中心

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

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

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

  1. 在 Google Cloud 控制台的导航面板中,选择 Monitoring,然后选择  信息中心

    前往信息中心

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

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

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

  1. 在 Google Cloud 控制台的导航面板中,选择 Monitoring,然后选择  集成

    前往集成

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

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

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

安装提醒政策

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

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

  1. 在 Google Cloud 控制台的导航面板中,选择 Monitoring,然后选择  集成

    前往集成

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

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

    3. 点击创建政策

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

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

后续步骤

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