Created
October 31, 2012 10:13
-
-
Save hitode909/3986251 to your computer and use it in GitHub Desktop.
webtailでアクセスログ聞くやつ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (!context.setup) { | |
context.setup = true; | |
var app = { | |
counts: { | |
GET: 0, | |
POST: 0, | |
}, | |
$log: $('<pre>').appendTo($(document.body)), | |
urls: [], | |
errors: [], | |
flush: function() { | |
$(document.body).empty(); | |
}, | |
print: function(lines, color) { | |
$(document.body).append( | |
$('<pre>').text(lines.join("\n")).css('background', color) | |
); | |
}, | |
}; | |
context.app = app; | |
$.getScript('http://mohayonao.github.com/timbre/timbre.min.js', function(res) { | |
var base = 100; | |
app.get = T("sin" , T("glide", 150, base)); | |
app.post = T("tri", T("glide", 150, base)); | |
app.post.off(); | |
app.error_env = T("perc", 500); | |
app.error = T("pink"); | |
app.error.off(); | |
app.sound = T('*', T("+", app.get, app.post, T("*", app.error, 0.5)), 0.5); | |
app.sound.play(); | |
var timer = T("interval", 1000 * 5, function() { | |
app.get.freq.value = (app.counts.GET||0)*5 + base; | |
app.post.freq.value = (app.counts.POST||0)*5 + base; | |
var lines = []; | |
lines.push("GET: " + (app.counts.GET || 0)); | |
lines.push("POST: " + (app.counts.POST || 0)); | |
if (app.errors.length > 0) { | |
app.error.on(); | |
} else { | |
app.error.off(); | |
} | |
if (app.counts.POST) { | |
app.post.on(); | |
} else { | |
app.post.off(); | |
} | |
app.flush(); | |
app.print(lines.concat(app.urls.sort()), 'black'); | |
if (app.errors.length > 0) { | |
app.print(app.errors.sort(), 'red'); | |
} | |
app.counts = {}; | |
app.urls = []; | |
app.errors = []; | |
}); | |
timer.on(); | |
}); | |
Webtail.onmessages.shift(); | |
} | |
var matched = message.data.match(/req:(\S+)\s(\S+)/); | |
if (matched) { | |
var app = context.app; | |
var method = matched[1]; | |
var url = matched[2]; | |
if (!app.counts[method]) { | |
app.counts[method] = 0; | |
} | |
app.counts[method]++; | |
if (method == 'POST') { | |
app.urls.push(url); | |
} | |
if (message.data.match(/status:500/)) { | |
app.errors.push(url); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment