added unique visitor count to admin dashboard

v1.18.x
Baris Soner Usakli 11 years ago
parent 7081c7dcc4
commit e75c303b89

@ -35,6 +35,17 @@ define(function() {
$('.restart').on('click', function() {
socket.emit('admin.restart');
});
socket.emit('admin.getVisitorCount', function(err, data) {
if(err) {
return app.alertError(err.message);
}
var uniqueVisitors = $('#unique-visitors');
for(var key in data) {
uniqueVisitors.find('#' + key).text(data[key]);
}
});
};
Admin.updateRoomUsage = function(err, data) {

@ -36,4 +36,29 @@
</div>
</div>
</div>
<div class="col-sm-6">
<div class="panel panel-default">
<div class="panel-heading">Unique Visitors</div>
<div class="panel-body">
<div id="unique-visitors">
<div class="text-center pull-left">
<div id="day"></div>
<div>Day</div>
</div>
<div class="text-center pull-left">
<div id="week"></div>
<div>Week</div>
</div>
<div class="text-center pull-left">
<div id="month"></div>
<div>Month</div>
</div>
<div class="text-center pull-left">
<div id="alltime"></div>
<div>All Time</div>
</div>
</div>
</div>
</div>
</div>
</div>

@ -30,8 +30,7 @@ var path = require('path'),
user.updateLastOnlineTime(req.user.uid);
}
// Log IP address
db.sortedSetAdd('ip:recent', +new Date(), req.ip || 'Unknown');
db.sortedSetAdd('ip:recent', Date.now(), req.ip || 'Unknown');
next();
});

@ -9,6 +9,7 @@ var groups = require('../groups'),
categories = require('../categories'),
CategoryTools = require('../categoryTools'),
logger = require('../logger'),
db = require('../database'),
admin = {
user: require('../admin/user'),
categories: require('../admin/categories')
@ -35,6 +36,30 @@ SocketAdmin.restart = function(socket, data, callback) {
meta.restart();
};
SocketAdmin.getVisitorCount = function(socket, data, callback) {
var terms = {
day: 86400000,
week: 604800000,
month: 2592000000
};
var now = Date.now();
async.parallel({
day: function(next) {
db.sortedSetCount('ip:recent', now - terms.day, now, next);
},
week: function(next) {
db.sortedSetCount('ip:recent', now - terms.week, now, next);
},
month: function(next) {
db.sortedSetCount('ip:recent', now - terms.month, now, next);
},
alltime: function(next) {
db.sortedSetCount('ip:recent', 0, now, next);
}
}, callback);
}
/* Topics */
SocketAdmin.topics = {};

Loading…
Cancel
Save