우선 아래의 depandency를 추가하여 기존 log4j 로그를 json형식으로 쌓이도록 하였음.
net.logstash.log4j jsonevent-layout 1.7
input {
file {
path => "/*"
start_position => "beginning"
type => "log4j-json"
codec => json
}
}
output {
elasticsearch {
index => "log-%{+YYYY-MM-dd}"
}
}
위와 같이 설정을 하게 될 경우 logstash에서 output되는 current_time이 인덱스 명으로 사용이 되어 일 별 인덱스 생성이 가능하였다.
만약 실시간으로 로그를 전송하는 경우가 아니라 주기적으로 로그를 전송하게 된다면 index명에 들어가는 일자가 맞는 것일까?
로그가 실제로 쌓인 시간을 인덱스 날짜로 사용을 할 필요가 생겨 구글링을 통하여 아래와 같이 설정을 하였음
input {
file {
path => "/*"
start_position => "beginning"
type => "log4j-json"
codec => json
}
}
filter {
ruby {
code => "event['index_day'] = Time.at(event['@timestamp'].to_i).strftime('%Y-%m-%d')"
}
}
output {
elasticsearch {
index => "log-%{index_day}"
}
}
필터를 통하여 index_day라는 키에 @timestamp 값을 원하는 포맷으로 변경 한 값을 주어 index명에서 사용을 함으로서
로그에 있는 시간을 기준으로 index 설정이 가능해졌다.
====== 추가 ======
@timestame의 경우 한국 시간으로 표시 되지 않고 09:00 시간을 뺀 시간을 알려주고 있어 index명에서 한국 기준이 아닌 경우가 있어 아래와 같이 수정하여 해결함
code => "event['index_day'] = Time.at(event['@timestamp'].to_i).localtime.strftime('%Y-%m-%d')"
댓글 없음:
댓글 쓰기