Skip to content

Instantly share code, notes, and snippets.

@carrotsword
Last active August 10, 2018 15:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carrotsword/1824c1fe79d1cc3270ba17e615388faa to your computer and use it in GitHub Desktop.
Save carrotsword/1824c1fe79d1cc3270ba17e615388faa to your computer and use it in GitHub Desktop.
Logstash で IMのログをelasticsearchに転送してみた

設定の内容

input
  • 既存のファイルにある内容を取り込みたいので start_position => "beginning" としている
    • 多分これだけではだめで、 ignore_older => 8640000 で取り込みたいファイルが対象になるように設定してやる必要がある。
      • デフォルトは ignore_older => 86400 で 24Hらしい
  • やり直したりする場合は sincedb_path で指定した先にできるファイルを毎度削除しないといけない。らしい。
filter
  • tsvを読み込みたい場合はcsv pluginを使用してseparator => " "と指定する。
    • separator => "\t" じゃだめ
  • logの出力日時を日付型にパースして@timestampに設定するようにしている。
output
  • elasticsearch はデフォルトのままでローカルホストに起動している。この場合設定は何も書かなくてよい。

実行

logstash -f logstash.conf
input {
file {
path => ["path/to/imart/WEB-INF/log/platform/request*.log"]
sincedb_path => "path/to/logstash-2.3.0/sincedb/sincedb"
ignore_older => 8640000
start_position => "beginning"
type => "iac_request_log"
}
}
filter {
csv{
separator => " "
columns => ["timestamp", "thread", "seq", "level", "logger", "tenant", "log-id", "hifen", "session-id", "remotehost","method", "url", "query-string", "referer", "page-time","accept-time", "req-id"]
autogenerate_column_names => false
}
date {
match => ["timestamp", "'['yyyy-MM-dd HH:mm:ss.SSS']'"]
remove_field => "timestamp"
}
date {
match => ["accept-time", "yyyy-MM-dd HH:mm:ss,SSS"]
target => "accept-time"
}
mutate {
convert => {
"seq" => "integer"
"page-time" =>"integer"
}
}
}
output {
elasticsearch {
}
stdout {
codec => rubydebug
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment