HerokuからTreasure Dataを使う方法

アクセスログなどTreasure Data側に格納して、必要な時にGoogle SpreadSheetに出力してデータ分析を行うことがある。今いる会社でもそうしている。

HerokuではAdd OnでTreasure Data連携ができる。
手順は以下の通り

  • gemを入れる


gem install td

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

  • api keyを確認する。

td apikey show

  • api keyなどを設定ファイルに記述する

config/treasure_data.ymlを書いておく


1 #
2 # This file configures the Treasure Data, Hadoop-based cloud data warehouse.
3 # For more information, visit http://www.treasure-data.com/.
4 #
5 production:
6 # Treasure Data API Key
7 # TREASURE_DATA_API_KEY is automatically defined when you add treasure-data
8 # heroku addon.
9 apikey: "12*******************"
10
11 # Database name
12 # Set this to be the name of your database as you'd like it show up in
13 # `heroku td dbs` command.
14 database: production
15
16
17 # Debug Mode
18 # Less verbose for production environment.
19 debug_mode: false
20
21 development:
22 # Treasure Data API Key
23 # `heroku td apikey:show` will retrieve the apikey through Heroku API.
24 apikey: "321****************************"
25
26 # Database name
27 # Set this to be the name of your database as you'd like it show up in
28 # `heroku td dbs` command.
29 database: development
30
31
32 # Debug Mode
33 # More verbose tracing is enabled for development environment.
34 debug_mode: true
35
36 # For test

これで設定は終わり。
後は、ApplicationControllerなどにbefore_filterで定義しておけば良いかと。。。