Skip to content

Commit

Permalink
adding button example
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffsu committed Sep 12, 2012
1 parent 762211a commit 3047307
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
18 changes: 18 additions & 0 deletions mock/button.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
require 'sinatra'
require 'haml'
require 'uri'
require 'net/http'

get '/' do
if btn = params[:button]
Net::HTTP.post_form(URI.parse('https://localhost:3000/stats/buttons'), { btn => 1 })
end

haml <<END
%button(onclick="location.href='/?button=one'") One
%button(onclick="location.href='/?button=two'") Two
%button(onclick="location.href='/?button=three'") Three
END


end
3 changes: 3 additions & 0 deletions mock/example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ stats:
urls:
strategy: counter

buttons:
strategy: counter

response-times:
strategy: average

Expand Down
11 changes: 11 additions & 0 deletions mock/my-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ var upbeatClient = new upbeat.Client({ redis: { port: 6379, host: '127.0.0.1' }
var urls = upbeatClient.getStats('urls');
var times = upbeatClient.getStats('response-times');
var success = upbeatClient.getStats('success');
var request = require('request');

var app = express();
app.configure(function () {
Expand All @@ -26,6 +27,16 @@ app.configure(function () {
app.use(app.router);
});

app.get('/', function (req, res) {
var btn = req.query.button;
var form = {};
form[btn] = 1;
if (btn) request.post('https://localhost:3000/stats/buttons').form(form);
res.end('<html><ol><li><a href="/?button=1">One</a></li>' +
'<li><a href="/?button=2">Two</a></li>' +
'<li><a href="/?button=3">Three</a></li></ol></html>');
});

app.get('/:speed/:uptime', function (req, res) {
var shortest = (SPEEDS[req.params.speed] || SPEEDS.average) - 100;
var delta = Math.round(Math.random() * 200);
Expand Down
7 changes: 4 additions & 3 deletions www/app.ms
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ module.exports = #(server, config) {
week: []
};

for (var i=12; i>0; i--) {
for (var i=11; i>=0; i--) {
LABELS.min.push(i * 5);
LABELS.hour.push(i * 5);
}

for (var i=24; i>0; i--) LABELS.day.push(i);
for (var i=7; i>0; i--) {
for (var i=23; i>=0; i--) LABELS.day.push(i);
for (var i=6; i>=0; i--) {
LABELS.week.push(i);
for (var j=0; j<5; j++) {
LABELS.week.push('');
Expand Down Expand Up @@ -157,6 +157,7 @@ module.exports = #(server, config) {

app.post('/stats/:stats', #(req, res, next) {
var stats = getResource(req.params);
console.log(req.body);
for (var k in req.body) {
var val = parseInt(req.body[k]);
if (val > 0) stats.inc(k, val);
Expand Down
1 change: 1 addition & 0 deletions www/public/javascripts/charts.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function startChart(par) {
}
}


if (!first) {
return $div.chart({ values: payload.data });
} else {
Expand Down

0 comments on commit 3047307

Please sign in to comment.