일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- KoA
- venv
- ELK
- ubuntu
- kibana
- framework
- windows
- Crontab
- json
- elastic
- OPCUA
- typescript
- 7.7.1
- dense_vector
- path.data
- filebeat
- airflow
- grok
- configure
- DSL
- Tutorial
- CSV
- package.json
- elasticsearch
- query
- node.js
- PYTHON
- logstash
- devtools
- Data Engineering
- Today
- Total
Gibbs Kim's playground
[ElasticStack-15] Logstash Grok filtering 본문
.json 파일을 엘라스틱서치에 인덱싱하면 보통 "message" 필드에 중괄호( { } ) 내부에 있던 내용들이 저장된다.
이때 "key:value" 쌍이나 기타 값들을 적절하게 분류하여 필드와 데이터로 분류하고 싶다면 filter를 사용하게 되는데 Logstash에서는 보통 Grok filter를 통해 분류 작업을 수행한다.
[참고 링크]
https://github.com/elastic/logstash/blob/v1.4.2/patterns/grok-patterns
elastic/logstash
Logstash - transport and process your logs, events, or other data - elastic/logstash
github.com
https://grokdebug.herokuapp.com/
Grok Debugger
One per line, the syntax for a grok pattern is %{SYNTAX:SEMANTIC}
grokdebug.herokuapp.com
예를 들어서 다음과 같은 형태의 JSON 파일이 있다고 하자.
{
" key1": value1,
" key2": value2,
...
...
}
Logstash로 인덱싱을 하면 다음과 같은 형태로 데이터가 저장된다.
"message": " key1": value1
"message": " key2": value2
...
...
이때 key의 필드를 'key_field', value의 필드를 'value_field'로 하고 싶다면 Grok 필터를 사용한다.
## logstash_idx.conf
input{
file{
path => "FILE_PATH"
start_position => "beginning"
sincedb_path => "/dev/null"
}
}
filter{
grok{
match => {"message"=> " \"%{DATA:key_field}\": %{NUMBER:value_field}"}
}
mutate{
convert => {
"value_field" => "float"
}
}
}
output{
elasticsearch{
hosts => "localhost:9200"
index => "grok_test_idx"
}
stdout{
codec => rubydebug
}
}
Grok 필터로 만든 필터의 타입은 초기에 무조건 'String'으로 설정된다. 따라서 Logstash에서 따로 타입을 설정하고 싶은 필드가 있다면 'mutate'를 적용해주자.
'Tech 기록지 > Elastic Stack' 카테고리의 다른 글
[ElasticStack-17] File name extract in full file path (0) | 2020.06.15 |
---|---|
[ElasticStack-16] Terms query & Aggregation (sum, avg) (0) | 2020.06.12 |
[ElasticStack-14] Logstash path.data setting (0) | 2020.06.11 |
[ElasticStack-13] ELK operating on background (on Linux) (0) | 2020.06.09 |
[ElasticStack-12] jdk download with wget command on Linux (0) | 2020.06.05 |