iOS用Fluentd Loggerライブラリを公開しました。
まだアルファ段階なので、開発時のみご利用ください。
Fluentd+elasticsearch+Kibana3が動作するVagrant+Chefも入っているので、簡単に使い始められるようになっています。
詳しい使い方はiOSアプリからFluentdにログを送る (Vagrantで簡単にサーバを利用可能) | CAPH TECH : iOSを御覧ください。
iOS用Fluentd Loggerライブラリを公開しました。
まだアルファ段階なので、開発時のみご利用ください。
Fluentd+elasticsearch+Kibana3が動作するVagrant+Chefも入っているので、簡単に使い始められるようになっています。
詳しい使い方はiOSアプリからFluentdにログを送る (Vagrantで簡単にサーバを利用可能) | CAPH TECH : iOSを御覧ください。
VagrantにChefでFluentdとelasticsearchとKibana3をインストールして動かしてみます。
まずこのプロジェクトのファイルを置くディレクトリを作成します。
$ mkdir sandbox $ cd sandbox |
以下の内容でGemfileを作成します。
source "https://rubygems.org" gem "knife-solo" gem "berkshelf" |
インストールします。
$ bundle install --path vendor/bundle |
Chefのリポジトリを作成します。
$ bundle exec knife solo init chef-sandbox $ cd chef-sandbox |
以下の内容でBerksfileを作成します。
source "http://api.berkshelf.com" cookbook 'td-agent', :git => 'https://github.com/treasure-data/chef-td-agent.git' cookbook 'elasticsearch', :git => 'https://github.com/elasticsearch/cookbook-elasticsearch.git' cookbook 'kibana', :git => 'https://github.com/realityforge/chef-kibana.git' cookbook 'timezone-ii', :git => 'https://github.com/L2G/timezone-ii.git' |
cookbookを取得します。
$ bundle exec berks vendor |
独自のCookbookを作成します。
$ bundle exec knife cookbook create base |
インストール時にlibcurl-devが必要になるのとFluentdの設定ファイルを独自のものに変更する為に、cookbooks/base/recipes/default.rbを以下の内容に変更します。
package "libcurl4-openssl-dev" do action :install end include_recipe "td-agent::default" begin t = resources("template[/etc/td-agent/td-agent.conf]") t.source "td-agent.conf.erb" t.cookbook "base" rescue Chef::Exception::ResourceNotFound Chef::Log.warn "could not find template /ect/td-agent/td-agent.conf" end |
独自のFluentdの設定ファイのテンプレートを作成します。cookbooks/base/templates/default/td-agent.conf.erbを以下の内容(必要に応じて変更)で作成します。
<% if node['td_agent']['includes'] %> include conf.d/*.conf <% end %> <% if node['td_agent']['default_config'] %> #### ## Output descriptions: ## # Treasure Data (http://www.treasure-data.com/) provides cloud based data # analytics platform, which easily stores and processes data from td-agent. # FREE plan is also provided. # @see http://docs.fluentd.org/articles/http-to-td # # This section matches events whose tag is td.DATABASE.TABLE <match td.*.*> type tdlog apikey <%= node['td_agent']['api_key'] %> auto_create_table buffer_type file buffer_path /var/log/td-agent/buffer/td </match> ## match tag=debug.** and dump to console <match debug.**> type stdout </match> #### ## Source descriptions: ## ## built-in TCP input ## @see http://docs.fluentd.org/articles/in_forward <source> type forward port 24224 </source> ## built-in UNIX socket input #<source> # type unix #</source> # HTTP input # POST http://localhost:8888/<tag>?json=<json> # POST http://localhost:8888/td.myapp.login?json={"user"%3A"me"} # @see http://docs.fluentd.org/articles/in_http <source> type http port 8888 </source> ## live debugging agent <source> type debug_agent bind 127.0.0.1 port 24230 </source> <% end %> <match myapp.**> index_name adminpack type_name http type elasticsearch include_tag_key true tag_key @log_name host localhost port 9200 logstash_format true flush_interval 5s </match> |
Chefのロールを作成します。
roles/td-agent.rbを以下の内容で作成します。
name "td-agent" description "Base role applied to td-agent nodes." run_list( "recipe[apt]", "recipe[base::default]", "recipe[td-agent]" ) override_attributes "td_agent" => { "plugins" => [ "elasticsearch" ], "platform" => "ubuntu" } |
roles/elasticsearch.rbを以下の内容で作成します。
name "elasticsearch" description "Base role applied to elasticsearch nodes." run_list( "recipe[java]", "recipe[elasticsearch]" ) override_attributes "java" => { "install_flavor" => "openjdk", "jdk_version" => "7" } |
roles/kibana.rbを以下の内容で作成します。
name "kibana" description "Base role applied to kibana nodes." run_list( "recipe[kibana::default]", "recipe[kibana::apache]", ) default_attributes "kibana" => { "version" => "3", } |
Oracle VM VirtualBox – Downloads | Oracle Technology Network | OracleからVirtualBoxをダウンロードしてインストールします。
Download Vagrant – VagrantからVagrantをダウンロードしてインストールします。
Vagrant Boxを作成します。代わりにあとでVagrantfileで指定してもいいです。
$ vagrant box add opscode-ubuntu-12.04 https://opscode-vm-bento.s3.amazonaws.com/vagrant/opscode_ubuntu-12.04_provisionerless.box |
Vagrantに自動的にChefをインストールするためのプラグインvagrant-omnibusをインストールします。
$ vagrant plugin install vagrant-omnibus |
Vagrantfileのひな形を作成します。
$ vagrant init opscode-ubuntu-12.04 |
Vagrantfileの
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| |
という行のあとに
config.omnibus.chef_version = :latest config.vm.provision :chef_solo do |chef| chef.cookbooks_path = ["./cookbooks", "./berks-cookbooks"] chef.roles_path = ["./roles"] chef.add_role("td-agent") chef.add_role("elasticsearch") chef.add_role("kibana") chef.run_list = [ "role[td-agent]", "role[elasticsearch]", "role[kibana]", "recipe[timezone-ii]", ] chef.json = { :tz => "Asia/Tokyo", } end config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "forwarded_port", guest: 9200, host: 9200 config.vm.network "forwarded_port", guest: 8888, host: 8888 |
を挿入します。
$ vagrant up |
でvagrantを実行します。
http://localhost:8080/index.html#/dashboard/file/logstash.json
にアクセスします。以下の様なKibanaの画面が表示されるはずです。
次に
http://localhost:8888/myapp.test?json={%22event%22:%22access%22}
にアクセスします。これは、Fluentdにhttpでログを作成しているので、表示は何も行われません。
再び
http://localhost:8080/index.html#/dashboard/file/logstash.json
にアクセスします。すると、以下の様に一つログが表示されているのが確認できるはずです。ログの反映はタイムラグがあるので、表示されていない場合は数秒置いてリロードしてみてください。
以上で動作確認までできました。