Observability:捕获 Elastic Agent 和 Elasticsearch 之间的延迟

在现代 IT 基础设施的动态环境中,高效的数据收集和分析至关重要。 Elastic Agent 是 Elastic Stack 的关键组件,通过促进将数据无缝摄取到 Elasticsearch 中,在此过程中发挥着至关重要的作用。 然而,显着影响此过程整体有效性的关键性能指标之一是延迟,即数据从 Elastic Agent 传输到 Elasticsearch 所需的时间。 在本文中,我们将深入研究捕获 Elastic Agent 和 Elasticsearch 之间的延迟时间。

有关如何设置 Agent 并采集数据,请阅读文章:

捕获延迟时间指南

利用处理器 (processors) 为所有事件合并代理 (agent) 时间戳。 处理器的目的是最小化导出事件中的字段或使用附加元数据对其进行扩充。 此操作发生在代理内,发生在日志进行解析之前。

让我们以系统 (System) 集成为例,以便更好地理解和计算延迟时间。

System Integration

展开收集指标 (Collect metrics ) 部分并打开 System process metrics -> Advance Options。 添加脚本处理器,它将为所有事件添加代理时间戳。

在上面点击 "Advanced options"

Script Processor:

vbnet 复制代码
1.  - script:
2.     lang: javascript
3.     source: >
4.       function process(event) {
5.           event.Put("event.agent_timestamp",new Date());
6.         return event;
7.       }

如果你想记录每个事件的采集时间,你可以参考下面的脚步代码,并直接计算一个采集时间值。在下面的代码中,它使用运行时字段的方法来进行计算。如果数据比较多,性能还是有一些的影响。

我们必须在映射 metrics-system.process@custom 组件模板中添加 event.agent_timestamp 字段。

单击编辑图标,它将导航到组件模板编辑页面。 现在添加 event.agent_timestamp 字段作为日期类型并保存集成。

就是这样,我们已经将 event.agent_timestamp 字段添加到所有 System process metrics 事件中,我们可以在 Discover 中看到这一点。

现在我们可以使用运行时字段来计算延迟。 在 Kibana 中,转到 "Data Views" 部分,然后单击 "metrics-*" Data view。

创建一个新的运行时字段 event.agent_latency 并使用以下脚本设置延迟值。

通过提供包含以下内容的文档 ID 来预览延迟值 event.agent_timestamp 字段。

Script:

scss 复制代码
1.  def agent_timestamp = doc["event.agent_timestamp"];
2.  if(null != agent_timestamp){
3.  long latency = doc['event.ingested'].value.toInstant().toEpochMilli() - agent_timestamp.value.toInstant().toEpochMilli();
4.   emit(latency);
5.   return;
6.  }
7.  emit(0);

该脚本将时间戳转换为自纪元以来的毫秒数并计算差值。

在 Discover 中,我们可以可视化 event.agent_latency 字段显示 Elastic Agent 和 Elasticsearch 之间的延迟时间。

减少 Elastic Agent 和 Elasticsearch 之间的延迟对于维护响应迅速且高效的数据分析环境至关重要。 通过了解影响延迟的因素并实施优化策略,组织可以确保其 Elastic Stack 发挥最佳性能,从而从其处理的数据中获得及时且可操作的见解。 定期监控、性能调整和及时了解最佳实践将有助于实现良好优化和低延迟的 Elastic Stack 部署。

在最新的 Elastic Stack 8.11 中,我们开始提供 ES|QL 管道查询语言。在查询时,我们可以更方便地生成所需要的字段。详情请阅读文章 "Elasticsearch:ES|QL 查询展示"。

相关推荐
Elasticsearch2 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch3 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
海兰5 天前
离线合同结构化提取与检索:LangExtract + 本地DeepSeek + Elasticsearch 9.x
大数据·elasticsearch·django
yumgpkpm5 天前
AI视频生成:Wan 2.2(阿里通义万相)在华为昇腾下的部署?
人工智能·hadoop·elasticsearch·zookeeper·flink·kafka·cloudera
Sheffield5 天前
如果把ZooKeeper按字面意思比作动物园管理员……
elasticsearch·zookeeper·kafka
嗝屁小孩纸5 天前
ES索引重建(零工具纯脚本执行)
大数据·elasticsearch·搜索引擎
Elastic 中国社区官方博客5 天前
使用 Jina Embeddings v5 和 Elasticsearch 构建“与你的网站数据聊天”的 agent
大数据·人工智能·elasticsearch·搜索引擎·容器·全文检索·jina
Elastic 中国社区官方博客5 天前
Elastic 公共 roadmap 在此
大数据·elasticsearch·ai·云原生·serverless·全文检索·aws
码云数智-大飞5 天前
像写 SQL 一样搜索:dbVisitor 如何用 MyBatis 范式颠覆 ElasticSearch 开发
sql·elasticsearch·mybatis