LoginSignup
3
3

More than 5 years have passed since last update.

FuentdからAmazonElasticSearch-Serviceにログを投げてKIbanaで見る

Posted at

2015年末に登場した、Aws上で動くElastic SearchにFluentdを連携する方法です

AmazonElasticSearch-Service

・S3のような感覚で使えるフルマネージドのElasticSearch
・VPCの中には立てれない
・アクセス権限設定にひと工夫必要

アクセス権限設定

いくつか方法があるが今回試したのは2つ
1.IAMで認証
署名付きリクエストを投げないとダメ
これ使うと署名付きリクエストを投げれてくれる
https://github.com/atomita/fluent-plugin-aws-elasticsearch-service

2.IPベースで制限
普通のElastcSearchと同じようにノーマルのHTTPでアクセス可能

1,2を組み合わせるとAND条件になるようでうまく動かなかったため2.IPベースで制限を採用
IPアドレスはPublic IPでないといけないので、中継FluentdのIPとKibana用のHTTP ProxyのIPを指定

td-agent.conf

雑にEndPointとインデックス名、テーブル名を指定する。
logstash_format = trueを指定すると、日時でインデックス(MySQLのテーブル相当)
を作ってくれるのでここがポイント

<store>
    type forest
    subtype aws-elasticsearch-service
  <template>
       buffer_type memory
       buffer_chunk_limit 10m
       buffer_queue_limit 10
       flush_interval 1s
       retry_limit 16
       retry_wait 1s
       logstash_format 
       index_name index_name #インデックスの名前
       type_name  type_name #テーブルの名前

       <endpoint>
          url https://xxxxx.ap-northeast-1.es.amazonaws.com #エンドポイントURL 
          region ap-northeast-1 # リージョン
       </endpoint>
  </template>
</store>

日付で検索できるように

ログのタイプスタンプはそのままだと、文字列として認識されるので、TimeStampとして認識するように設定する。
Elastic Searchにはインデックスをまたいで、グローバルに設定できるテンプレートがあるのでそれを使う
ElasticSearchServiceのエンドポイントに対してcurlでJSONを送り設定する。
この設定でkibana上で、インデックスとして認識される

curl -XPUT 'http://xxxxxxxx.ap-northeast-1.es.amazonaws.com/_template/hogehoge' -d'
{
   "template": "hogehoge*",
   "mappings" : {
     "_default_" : {
       "dynamic":  true,
       "dynamic_templates": [
              {
                    "date": {
                      "path_match": "timestamp",
                      "match_mapping_type": "date",
                      "mapping": {
                        "type": "date",
                        "format": "yyyy-MM-dd HH:mm:ss +0900"
                      }
                    }
              }
        ]
    }
  }
}'

Kibanaを見る

エンドポイント//_plugin/kibana/にアクセスするとみれます

まとめ

Elastic Searchは用語が難しいが、APIは綺麗なREST FULLなので、慣れると
SQLのようにcurlで操作できます。

3
3
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
3
3