LoginSignup
4
4

More than 5 years have passed since last update.

[Rails 4.1] ローカルのCentOS と Devise でログイン履歴を取る

Posted at

TreasureDataに登録

ローカル

こんな感じ

heroku

Addonをいれます

TreasureData Toolbeltをインストール

ローカルにインストール

CentOS

$ curl -L http://toolbelt.treasuredata.com/sh/install-redhat.sh | sh

Gemfile

gem 'td'
$ bundle install

いっぱい入ります。

Installing httpclient 2.4.0
Installing parallel 0.6.5
Installing rubyzip 0.9.9
Installing td-client 0.8.66
Installing td-logger 0.3.23
Installing td 0.11.5

上記以外でもインストールできます。

ref: http://docs.treasure-data.com/articles/installing-the-cli

Herokuにtd-agentのプラグインをインストール

$ heroku plugins:install https://github.com/treasure-data/heroku-td.git

確認

$ td --version
0.11.5
$ heroku td --version --app app_name
0.11.5

DBとテーブルを作っておく

DB

$ heroku td db:create DBNAME --app APPNAME
Database 'test' is created.
Use 'td table:create test <table_name>' to create a table.

table

$ heroku td table:create DBNAME TABLENAME --app APPNAME
Table 'DBNAME.TABLENAME' is created.

確認

$ heroku td tables --app APPNAME
+-----------------+------------+------+-----------+--------+---------------------------+---------------------------+-------------------------------------------------------------------------------------------------------+
| Database        | Table      | Type | Count     | Size   | Last import               | Last log timestamp        | Schema                                                                                                |
+-----------------+------------+------+-----------+--------+---------------------------+---------------------------+-------------------------------------------------------------------------------------------------------+
| sample_datasets | nasdaq     | log  | 8,807,278 | 0.2 GB |                           |                           | symbol:string, open:double, volume:long, high:double, low:double, close:double                        |
| sample_datasets | www_access | log  | 5,000     | 0.0 GB | 2014-10-04 01:13:20 +0000 | 2014-10-04 01:13:15 +0000 | user:int, host:string, path:string, referer:string, code:long, agent:string, size:long, method:string |
| DBNAME          | APPNAME    | log  | 0         | 0.0 GB |                           |                           |                                                                                                       |
+-----------------+------------+------+-----------+--------+---------------------------+---------------------------+-------------------------------------------------------------------------------------------------------+
3 rows in set

出力

ローカル用

TD.event.post('pay',
                  {:uid=>123, :item_name=>'hoge',
                   :category=>'fuga', :price=>1, :count=>1})

heroku用

ログを取りたいところに p hogehoge な感じで記載。

p "@[test.login] #{{'uid'=>123, 'from'=>'@TreasureData', 'to'=>'@Heroku'}.to_json}"

putsを使いたい場合は

STDOUT.sync = true #これをファイル上部に記載しておく(記載しなくてもうまく行った場合もあった。いろいろ未調査。)
puts hogehoge

references

一番わかりやすかった

HerokuからTreasureDataにアクションログを記録する。

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