2014-12 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
masutaka.netのnginxアクセスログはmongodbとGrowthForecastに送ってます。
- [2013-07-14-1] nginxのアクセスログをFluentd経由でMongoDBに保存してみた
- [2013-08-15-1] nginxのアクセスログをFluentd経由でGrowthForecastのグラフにしてみた
今回、elasticsearchとBigQueryにも送り始めました。個人での必要性は
全くなく、単にelasticsearchとBigQueryを知っておきたかったからです。
http://kibana.masutaka.net/ からkibana経由で検索出来るようにしてい
ます(要Basic認証)。kibanaは評判が良かったので期待してたんですが、
使いづらいです。学習が必要そうです。。
elasticsearchはopenjdk-7-jdkのインストールと、公式のインストール方
法をそのままChefのレシピにしました。
kibanaは/var/www以下に公式のtar ballを展開して、nginxの静的コンテ
ンツの設定を追加しました。
特になく、jdk, elasticsearch, kibana, nginxのレシピを良い感じに組
み立てるのに時間を使いました。
SQLなのでelasticsearchより取っ付きやすいのが良いです。
あ、Row=4はアカンやつや
fluent-plugin-bigqueryのREADME.mdを読みつつ、以下の記事そのままで
できました。ありがとうございます。
FluentdでGoogle BigQueryにログを挿入してクエリを実行する - Qiita
projectはウェブ上から作り、dataset(db)とtableはGoogle Cloud SDK付
属のbqコマンドで作りました。google-cloud-sdkはbrew caskでインストー
ルできます。
$ bq mk masutakanet:nginx
$ bq mk -t masutakanet:nginx.access bigquery-nginx.json
td-agent.confはこのようになりました。
<match nginx.access.masutaka.net> type copy <store> type mongo (省略) </store> <store> type elasticsearch (省略) </store> <store> type growthforecast (省略) </store> <store> type bigquery method insert auth_method private_key email XXXXXXXX@developer.gserviceaccount.com private_key_path /etc/td-agent/conf.d/masutakanet-YYYYYYYY.p12 project masutakanet dataset nginx table access time_format %s time_field time schema_path /etc/td-agent/conf.d/bigquery-nginx.json </store> </match>
bigquery-nginx.jsonはこんな感じ。nginxのアクセスログと対応させます。
[ { "name": "time", "type": "INTEGER" }, { "name": "host", "type": "STRING" }, { "name": "forwardedfor", "type": "STRING" }, { "name": "req", "type": "STRING" }, { "name": "status", "type": "INTEGER" }, { "name": "size", "type": "INTEGER" }, { "name": "referer", "type": "STRING" }, { "name": "ua", "type": "STRING" }, { "name": "reqtime", "type": "FLOAT" }, { "name": "vhost", "type": "STRING" } ]
Google Cloud Platformに慣れなくてハマりました。
今までのmongodbのレコードをmongobqでBigQueryに送りたかったのですが、
以下のエラーが出てしまい断念しました。またトライするかも。
$ mongobq --database fluent --collection nginx --project masutakanet \
--dataset nginx --table access --keyfile masutakanet-ZZZZZZZZ.json \
--schema bigquery-nginx.json --bucket masutaka-mongobq --autoclean
Import 'nginx' collection into 'masutakanet:nginx.access'
Connecting to mongodb://localhost:27017/fluent
Check bucket 'masutaka-mongobq' ... Error: Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.
at handleResp (/home/masutaka/.nvm/v0.10.33/lib/node_modules/mongobq/node_modules/gcloud/lib/common/util.js:176:14)
at Request._callback (/home/masutaka/.nvm/v0.10.33/lib/node_modules/mongobq/node_modules/gcloud/lib/common/util.js:382:11)
at Request.self.callback (/home/masutaka/.nvm/v0.10.33/lib/node_modules/mongobq/node_modules/gcloud/node_modules/request/request.js:373:22)
at Request.emit (events.js:98:17)
at Request.<anonymous> (/home/masutaka/.nvm/v0.10.33/lib/node_modules/mongobq/node_modules/gcloud/node_modules/request/request.js:1318:14)
at Request.emit (events.js:117:20)
at IncomingMessage.<anonymous> (/home/masutaka/.nvm/v0.10.33/lib/node_modules/mongobq/node_modules/gcloud/node_modules/request/request.js:1266:12)
at IncomingMessage.emit (events.js:117:20)
at _stream_readable.js:943:16
at process._tickCallback (node.js:419:13)
追記(2014-12-25):
fluent-plugin-bigquery v0.2.6がリリースされたので、「ハマりどころ」
からretriable gem v1.4.1を先にインストールする云々のworkaroundを削
除しました。
2014-12 / 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31