0Pricing
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) · 课时

Logstash:数据摄取与处理

掌握 Logstash,从各种来源收集、解析和转换数据。探索常用过滤器与输出组件,以构建可靠的数据管道。

Logstash:数据摄取与处理 是 CoddyKit 上的免费 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

Logstash: The Data Pipeline

Welcome to Logstash! In the ELK Stack, Logstash is your powerful, open-source data processing pipeline.

It's designed to ingest data from various sources, transform it, and then send it to various destinations, most commonly Elasticsearch.

Logstash's Core Architecture

Logstash operates on a simple, yet powerful, pipeline concept:

  • Inputs: Where data enters Logstash.
  • Filters: Where data is processed and transformed.
  • Outputs: Where processed data is sent.

Think of it as an assembly line for your logs!

Inputs: Gathering Your Logs

Inputs are the first stage of the pipeline. They define how Logstash collects data. There are many input plugins available for different sources.

Common input types include:

  • file: For reading log files from disk.
  • beats: For receiving data from Elastic Beats (like Filebeat).
  • tcp/udp: For network-based log collection.

Example: File Input

Here's a simple Logstash configuration snippet that sets up a file input plugin to read logs from a specific path.

This tells Logstash to monitor /var/log/my_app.log for new lines.

input {
  file {
    path => "/var/log/my_app.log"
    start_position => "beginning"
    # sincedb_path tracks read position. 
    # Use a persistent path in production.
    sincedb_path => "/dev/null"
  }
}

Filters: Making Sense of Data

Filters are the heart of Logstash's processing power. They take raw, unstructured data and transform it into structured, machine-readable events.

This is crucial for making your logs searchable and analyzable in Elasticsearch.

Grok Filter: Pattern Matching

The grok filter is incredibly powerful for parsing unstructured log data. It uses regular expressions combined with predefined patterns to extract specific fields.

For example, you can extract an IP address, a timestamp, or an HTTP method from a plain text log line.

Example: Grok Filter in Action

Consider a log line like: 192.168.1.1 GET /api/data 200 123ms

This grok filter extracts fields like clientip, method, request, response_code, and response_time.

filter {
  grok {
    match => { "message" => "%{IP:clientip} %{WORD:method} %{URIPATH:request} %{NUMBER:response_code:int} %{NUMBER:response_time:int}ms" }
  }
}

Other Useful Filters

While grok is essential, many other filters enhance your data:

  • date: Parses timestamps from log lines into a standard format.
  • mutate: Allows you to add, remove, rename, or modify fields.
  • json: Parses JSON strings within your log messages into structured fields.
  • kv: Extracts key-value pairs from a string.

Outputs: Sending Data Out

Outputs are the final stage of the Logstash pipeline. They define where your processed events are sent.

The most common output, especially in the ELK Stack, is elasticsearch. Other useful outputs include stdout (for debugging), file, or even message queues like kafka.

Logstash Pipeline Check

Let's test your understanding of Logstash's core components and how data flows through them.

Recap: Logstash, Your Data Processor

You've learned that Logstash is a vital component of the ELK Stack, acting as a flexible data processing engine.

  • It uses Inputs to gather data.
  • Filters (like grok) to parse and enrich that data.
  • And Outputs to send the processed, structured events to destinations like Elasticsearch.

This transforms raw logs into valuable, searchable information!

常见问题解答

「Logstash:数据摄取与处理」课时是免费的吗?

是的 — 「Logstash:数据摄取与处理」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程的其余内容,请升级到 CoddyKit PRO。 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程共包含 4 节课。

「Logstash:数据摄取与处理」这节课中我会学到什么?

掌握 Logstash,从各种来源收集、解析和转换数据。探索常用过滤器与输出组件,以构建可靠的数据管道。 你通过在浏览器中直接运行的动手代码来练习 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry),全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 需要有经验吗?

无需任何先前经验。CoddyKit 上的 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「Logstash:数据摄取与处理」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课中编写并运行代码吗?

能。每节 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. Elasticsearch:索引与搜索
  2. Logstash:数据摄取与处理
  3. Kibana:可视化与仪表板
  4. Beats:轻量级数据采集器
← 返回 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)