Logstash 필터와 파이프라인
조건부 로직, 여러 파이프라인, 복잡한 데이터 변환을 위한 사용자 지정 필터를 포함한 고급 Logstash 구성을 살펴봅니다.
Logstash 필터와 파이프라인은(는) CoddyKit의 무료 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Intro to Advanced Logstash
Welcome to an advanced look at Logstash! So far, you've learned how to get logs into Logstash and apply basic filters. But what happens when your data gets more complex?
In this lesson, we'll explore powerful techniques like conditional logic, managing multiple pipelines, and leveraging advanced filters for intricate data transformations. This will help you handle real-world logging challenges.
Conditional Logic: The 'if' Statement
Not all logs are created equal! You might have different log formats coming from various services, or you might want to process events differently based on their content.
Conditional logic allows Logstash to apply filters or outputs only when certain conditions are met. This is achieved using if statements, similar to programming languages.
- Use
ifto check field values, tags, or other event properties. - Apply specific filters or actions only to matching events.
Conditional Logic in Action
Let's see a simple example. We'll use if to check if a field named type exists and has a specific value. If it does, we'll add a tag.
Try inputting {"message": "Hello", "type": "app_log"} and then {"message": "World"} to see the difference.
input {
stdin {
codec => json
}
}
filter {
if [type] == "app_log" {
mutate {
add_tag => ["processed_app_log"]
}
}
}
output {
stdout {
codec => rubydebug
}
}Beyond 'if': Else and Else If
Just like in programming, you can extend your conditional logic with else if and else blocks. This allows for more complex branching and ensures every event is handled appropriately.
Logstash executes these conditions sequentially. The first matching condition's block is executed, and then it moves on.
if [field] == "value": Executes if the condition is true.else if [another_field] == "another_value": Executes if the firstifwas false, and this condition is true.else: Executes if none of the precedingiforelse ifconditions were true.
Multiple Pipelines: Why Separate?
As your system grows, you might be collecting logs from many different sources (e.g., web servers, databases, security devices). Each source might require entirely different processing logic.
Multiple pipelines allow you to isolate and manage these distinct processing flows independently. Instead of one giant, complex Logstash configuration, you can have several smaller, focused ones.
- Isolation: Errors in one pipeline won't affect others.
- Resource Management: Assign specific resources to different pipelines.
- Modularity: Easier to develop, test, and maintain configurations.
Configuring Multiple Pipelines
To use multiple pipelines, you define them in a file called pipelines.yml, usually located in your Logstash configuration directory (e.g., /etc/logstash/pipelines.yml).
Each entry specifies a unique ID, the path to its configuration file (.conf), and optional settings like number of worker threads.
Example pipelines.yml:
- pipeline.id: web_logs
path.config: "/etc/logstash/conf.d/web-pipeline.conf"
- pipeline.id: db_logs
path.config: "/etc/logstash/conf.d/db-pipeline.conf"Deep Dive: The Ruby Filter
Sometimes, built-in Logstash filters aren't enough for very specific or complex data transformations. That's where the ruby filter comes in!
The ruby filter allows you to execute arbitrary Ruby code within your Logstash pipeline. This provides immense flexibility to manipulate events in ways not possible with standard filters.
- Use for: Complex string manipulations, mathematical operations, custom data lookups, or logic that depends on multiple fields.
- Caution: Can impact performance if not used carefully.
Ruby Filter Example
Let's use the ruby filter to create a new field that combines parts of existing fields and calculates a value.
Try inputting: {"user_id": "123", "item_count": 5, "price_per_item": 10.5}
input {
stdin {
codec => json
}
}
filter {
ruby {
code => "
event.set('total_cost', event.get('item_count').to_f * event.get('price_per_item').to_f)
event.set('user_item_summary', 'User ' + event.get('user_id') + ' bought ' + event.get('item_count').to_s + ' items.')
"
}
}
output {
stdout {
codec => rubydebug
}
}Advanced Mutate Operations
The mutate filter is a workhorse for basic field manipulation, but it has some advanced operations that are incredibly useful:
split: Splits a string field into an array based on a delimiter.join: Joins an array field into a string using a specified separator.convert: Changes the data type of a field (e.g., string to integer, float to string).rename: Changes the name of an existing field.
These operations help you shape your data precisely for storage and analysis.
Quiz: Logstash Logic
Which of the following are valid reasons to use multiple Logstash pipelines?
Recap: Advanced Logstash Config
Great job! You've leveled up your Logstash skills. We covered:
- How conditional logic (
if,else if,else) allows for dynamic event processing. - The benefits and configuration of multiple pipelines for modular and isolated data flows.
- Leveraging the powerful
rubyfilter for highly custom data transformations. - Advanced operations within the
mutatefilter likesplit,join, andconvert.
These techniques are crucial for building robust and adaptable Logstash configurations for complex, real-world data.
AI 튜터와 함께 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)을(를) 배우세요 — 무료
브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.
- 코스
- 12
- 레슨
- 48
자주 묻는 질문
“Logstash 필터와 파이프라인” 강의는 무료인가요?
네 — “Logstash 필터와 파이프라인” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의 전체를 잠금 해제할 수 있습니다. System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 총 4개의 강의가 포함되어 있습니다.
“Logstash 필터와 파이프라인”에서 뭘 배우나요?
조건부 로직, 여러 파이프라인, 복잡한 데이터 변환을 위한 사용자 지정 필터를 포함한 고급 Logstash 구성을 살펴봅니다. 브라우저에서 직접 실행하는 실습 코드로 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.
“Logstash 필터와 파이프라인” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 System Observability: Logging, Metrics & Tracing (ELK + OpenTelemetry) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- Elasticsearch 쿼리 언어(DSL)
- Logstash 필터와 파이프라인
- Kibana Discover와 Lens
- 인덱스 수명 주기 관리(ILM)