LoginSignup
2
1

More than 5 years have passed since last update.

embulkでCloudFrontのログを扱う

Posted at

CloudFrontのログをトレジャーデータに叩き込みたいと思い、最近リリースされたembulkを使ってみました。

embulkのインストール

jarファイルを落としてきて、PATHを通してあげるだけ。

参考:Macでembulkを使う

インプットプラグイン

プラグインのインストール

次のコマンドでembulk-input-s3をインストールします。

embulk gem install embulk-input-s3

設定ファイル

記述する内容は

  • ClohdFrontのログが保存されているS3のバケットの情報
  • CloudFrontのログのスキーマ(これは使い回しで大丈夫なはず)

で、次のような感じ。

cloudfront.yml
in:
  type: s3
  bucket: <バケット名>
  path_prefix: XXXXXXXXXXXXX.2015-03-18-
  endpoint: s3-ap-northeast-1.amazonaws.com
  access_key_id: XXXXXXXXXXXXXXXXXXXX
  secret_access_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
  decoders:
  - {type: gzip}
  parser:
    charset: UTF-8
    newline: CRLF
    type: csv
    delimiter: "\t"
    quote: ''
    escape: ''
    skip_header_lines: 2
    columns:
    - {name: date, type: string}
    - {name: time, type: string}
    - {name: edge_location, type: string}
    - {name: sc_bytes, type: long}
    - {name: c_ip, type: string}
    - {name: cs_method, type: string}
    - {name: cs_host, type: string}
    - {name: cs_uri_stem, type: string}
    - {name: sc_status, type: string}
    - {name: cs_referer, type: string}
    - {name: cs_user_agent, type: string}
    - {name: cs_uri_query, type: string}
    - {name: cs_cookie, type: string}
    - {name: edge_result_type, type: string}
    - {name: edge_result_id, type: string}
    - {name: host_header, type: string}
    - {name: cs_protocol, type: string}
    - {name: cs_bytes, type: long}
    - {name: time_taken, type: double}
exec: {}
out:
  type: stdout

日付dateと時刻timeが別々のカラムに入っているので、タイムスタンプとして利用するのを我慢してstringとしています。
誰か、CloudFrontのログ用のプラグイン書いてくれないかな。。。

※ CloudFrontのログフォーマットについてはこちら

テスト

次のコマンドで読み込みのテストを行うことが出来ます。

embulk preview cloudfront.yml

アウトプットプラグイン

プラグインのインストール

次のコマンドでembulk-output-tdをインストールする。

embulk gem install embulk-output-td

が、

ERROR:  Could not find a valid gem 'embulk-output-td' (>= 0) in any repository

と表示される。。。?

リポジトリ?を見てみると一応あるので、クローンしてきてビルドしてみるが、、、、動かない。

プラグインリストを見ると載っていないので、どうやらまだリリースされていないようです。。。

まとめ

結果、TDに叩きこむことは出来なかったが、embulkの可能性は感じました。
matchingプラグインも開発中のようなので、パラメータによってフィルタリング出来ると活用の幅が広がり便利そうです。
※随時、更新します。

勝手にマルチプロセス化して叩き込んでくれるのはaerospikeと非常に相性が良さそうですが、僕がプラグインを書くのはまだまだ先になりそうです。

2
1
1

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
2
1