HerokuããTreasure Dataã«æ¨æºåºåã§ãã¼ã¿ã¤ã³ãã¼ãã§ããããã«ãªã£ã¦å¤å¹¸æãããã
@fumito_ito å®ã¯æ¬æ¥ããã§ãããHerokuä¸ã®ã¢ããªã«éããstdoutããTDã«ãã¼ã¿ãéããããã«ãªãã¾ãããä¸åº¦addonãremove -> addãã¦é ãã¨ä½¿ããæ§ã«ãªãã¾ãã > bit.ly/U2sSWn
— Kazuki Ohtaãã (@kzk_mover) 1æ 17, 2013
ã¨ããããã§ãå®éã«è©¦ãã¦ã¿ã¾ããã
å
¬å¼ã®ãã¼ã¸ã¯ãã¡ã
How to ?
å
¬å¼ã®ãã¼ã¸ã«ããéããTreasure Data Hadoopã¨heroku-td
CLIãã©ã°ã¤ã³ãã¤ã³ã¹ãã¼ã«ããå¾ã«ä»¥ä¸ã®å½¢å¼ã§æ¨æºåºåããã¨æå®ããDBã®ãã¼ãã«ã«ãã¼ã¿ãæ¿å
¥ããã¾ãã
@[database.table] JSON-In-ONE-LINE
ãã¼ã¿ã®æ¿å ¥ã¯5åæ¯ã«è¡ãããããã§ãã
Node.jsã§ãã£ã¦ã¿ã
ãã£ã¦ã¿ã¾ããã
- ã²ãªå½¢ãä½ãã
$ express td-sample $ cd td-sample $ npm install
git init
ããã®ã¢ããªä½æï¼ã¢ããªã³ç»é²
$ git init $ git add . $ git commit -m "initail commit" $ heroku create $ heroku addons:add treasure-data:nano $ heroku plugins:install https://github.com/treasure-data/heroku-td.git
heroku td
ã§tdã³ãã³ãã使ããã確èª
$ heroku td (show usage)
- Nodeã§Request Headerãæ¨æºåºåããããã«å¤æ´
// app.js // ...ç¥ var tdLogger = function() { return function(req, res, next) { var end = res.end; res.end = function (chunk, encoding) { res.end = end; res.end(chunk, encoding); var line = { headers: req.headers }; var td = '@[' + process.env.TD_DATABASE + '.' + process.env.TD_TABLE + '] '; process.stdout.stream(td + JSON.stringify(line)); }; next(); }; }; // app.configure ã®ä¸é¨ãå¤æ´ app.configure(function(){ app.set('port', process.env.PORT || 3000); app.set('views', __dirname + '/views'); app.set('view engine', 'jade'); app.use(express.favicon()); // app.use(express.logger()); app.use(tdLogger()); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); app.use(express.static(path.join(__dirname, 'public'))); }); // ...ç¥
package.json
ã¨Procfile
ãé©å½ã«ä½ã
# package.json { "name": "application-name", "version": "0.0.1", "private": true, "scripts": { "start": "node app" }, "engines": { "node": "0.8.x", "npm": "1.1.x" }, "dependencies": { "express": "3.0.5", "jade": "*" } }
# Procfile web: node app.js
- Herokuã®è¨å®ã追å
$ heroku config:add TD_DATABASE=heroku $ heroku config:add TD_TABLE=headers
- commit & push
$ git commit -am "change for td-log test" $ git push heroku master $ heroku open
ãã°ãããã¦ä»¥ä¸ã®ã³ãã³ããå®è¡ããã¨Tableã®ã«ã¦ã³ããå¢ãã¦ããã¼ã¿ãæ¿å ¥ããã¦ãããã¨ããããã¾ãã
$ heroku td tables
ãããã®ãã¼ã¿ã¯ãã¡ããHiveã§ã¶ãåããã¨ãã§ãã¾ãã
ç´ æµã§ãã :)