0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

logstashで CouchDBに入ったデータのUNIX時間を@timestampに変換

Last updated at Posted at 2021-11-07

検証環境

プラットフォーム:macと、pi4上のubuntu server20.4
logstash: 7.15.1
couchdb: 2.1.1

filter処理

unixをdocから取り出し、@timestampに、docの中のnameとtemperatureをルートに移動。

{ "doc":{ "unix":1609424856,"temperature":11.6 } }
{ "doc":{ "unix":1609431495,"temperature":19.1 } }

処理後

{ "@timestamp":"2021-11-06T03:19:10.787Z" , "temperature":11.6 }
{ "@timestamp":"2021-11-06T03:19:10.798Z" , "temperature":19.1 }

パイプライン定義ファイル unix.conf

input { 
      stdin {
           codec => "json"
      }
}
filter {
  date {
     match        => ['[doc][unix]','UNIX' ] # ms単位の場合は UNIX_MS
     remove_field => '[doc][unix]'
  }
  mutate {
    copy         => {'[doc][temperature]'=>'[temperature]'}
    remove_field => [ '[doc][temperature]' ]
    remove_field => [ '[doc]' ]
  }
}
output {
  file {
    path => "out.json"
  }
}

動作確認は

cat source.json | logstash -f unix.conf

まとめ

mutateは上から下にシーケンス
logshash.ymlは空ファイル
@versionとhost名が追加出力される。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?