Permalink
Browse files

Ping list is now updated in real time

  • Loading branch information...
fzaninotto committed Apr 20, 2012
1 parent 6b88ea7 commit 1e36ecba481a53dc6743f6eaa8f251369a3066dc
Showing with 24 additions and 11 deletions.
  1. +1 −0 CHANGELOG.md
  2. +14 −0 app.js
  3. +9 −11 app/dashboard/views/_pings.ejs
View
@@ -4,6 +4,7 @@ Uptime Changelog
To be released, v1.2
--------------------
+* Ping list is now updated in real time
* Added 'Save and add' button in new check form to facilitate batch check creation
* Changed the CheckEvent format for better extensibility (use the fixtures/fixEvents.js fix to migrate existing events)
* Fix polling interval to mimic the behavior of a cron
View
14 app.js
@@ -10,6 +10,7 @@ var path = require('path');
var monitor = require('./lib/monitor');
var analyzer = require('./lib/analyzer');
var CheckEvent = require('./models/checkEvent');
+var Ping = require('./models/ping');
// configure mongodb
mongoose.connect('mongodb://' + config.mongodb.user + ':' + config.mongodb.password + '@' + config.mongodb.server +'/' + config.mongodb.database);
@@ -75,6 +76,19 @@ CheckEvent.on('postInsert', function(event) {
io.sockets.emit('CheckEvent', event.toJSON());
});
+io.sockets.on('connection', function(socket) {
+ socket.on('set check', function(check) {
+ socket.set('check', check);
+ });
+ Ping.on('postInsert', function(ping) {
+ socket.get('check', function(err, check) {
+ if (ping.check == check) {
+ socket.emit('ping', ping);
+ }
+ });
+ });
+});
+
// load plugins
path.exists('./plugins/index.js', function(exists) {
if (exists) {
@@ -4,9 +4,6 @@
<a class="old btn" href="#">&lt;</a>
<a class="recent btn" href="#">&gt;</a>
</div>
- <div class="btn-group pull-right">
- <a class="btn" data-toggle="button" id="autoupdate" href="#">Auto-update</a>
- </div>
</div>
<table class="table">
<thead>
@@ -47,14 +44,15 @@ $(document).ready(function() {
$('#pings tbody').html(lines.join(''));
});
};
- interval = window.setInterval(updatePings, 10000);
- $('#autoupdate').button('toggle').click(function(e) {
- if (interval) {
- window.clearInterval(interval);
- } else {
- interval = window.setInterval(updatePings, 10000);
- }
- e.preventDefault();
+ socket.on('connect', function() {
+ socket.emit('set check', '<%= check._id %>');
+ socket.on('ping', function(ping) {
+ if (page.ping == 1) {
+ var line = $(ejs.render(ping_template, { ping: ping }));
+ $('#pings tbody').prepend(line);
+ line.fadeOut().fadeIn();
+ }
+ });
});
handlePagination('ping', '#pings', updatePings);
});

0 comments on commit 1e36ecb

Please sign in to comment.