mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-14 01:45:47 +01:00
single proc stats
This commit is contained in:
@@ -22,7 +22,7 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
|
|
||||||
Admin.init = function() {
|
Admin.init = function() {
|
||||||
app.enterRoom('admin');
|
app.enterRoom('admin');
|
||||||
socket.emit('meta.rooms.getAll', Admin.updateRoomUsage);
|
socket.emit('admin.rooms.getAll', Admin.updateRoomUsage);
|
||||||
|
|
||||||
isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
isMobile = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
||||||
|
|
||||||
@@ -439,7 +439,7 @@ define('admin/general/dashboard', ['semver'], function(semver) {
|
|||||||
|
|
||||||
intervals.rooms = setInterval(function() {
|
intervals.rooms = setInterval(function() {
|
||||||
if (app.isFocused && app.isConnected) {
|
if (app.isFocused && app.isConnected) {
|
||||||
socket.emit('meta.rooms.getAll', Admin.updateRoomUsage);
|
socket.emit('admin.rooms.getAll', Admin.updateRoomUsage);
|
||||||
}
|
}
|
||||||
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.roomInterval);
|
}, realtime ? DEFAULTS.realtimeInterval : DEFAULTS.roomInterval);
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var cronJob = require('cron').CronJob,
|
var cronJob = require('cron').CronJob;
|
||||||
db = require('./database');
|
var db = require('./database');
|
||||||
|
|
||||||
|
|
||||||
(function(Analytics) {
|
(function(Analytics) {
|
||||||
|
|
||||||
@@ -61,6 +60,8 @@ var cronJob = require('cron').CronJob,
|
|||||||
db.incrObjectFieldBy('global', 'uniqueIPCount', uniqueIPCount);
|
db.incrObjectFieldBy('global', 'uniqueIPCount', uniqueIPCount);
|
||||||
uniqueIPCount = 0;
|
uniqueIPCount = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Analytics.getUnwrittenPageviews = function() {
|
Analytics.getUnwrittenPageviews = function() {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ var async = require('async'),
|
|||||||
tags: require('./admin/tags'),
|
tags: require('./admin/tags'),
|
||||||
rewards: require('./admin/rewards'),
|
rewards: require('./admin/rewards'),
|
||||||
navigation: require('./admin/navigation'),
|
navigation: require('./admin/navigation'),
|
||||||
|
rooms: require('./admin/rooms'),
|
||||||
themes: {},
|
themes: {},
|
||||||
plugins: {},
|
plugins: {},
|
||||||
widgets: {},
|
widgets: {},
|
||||||
|
|||||||
73
src/socket.io/admin/rooms.js
Normal file
73
src/socket.io/admin/rooms.js
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
var validator = require('validator');
|
||||||
|
var topics = require('../../topics');
|
||||||
|
|
||||||
|
var SocketRooms = {};
|
||||||
|
|
||||||
|
SocketRooms.getAll = function(socket, data, callback) {
|
||||||
|
|
||||||
|
var websockets = require('../index');
|
||||||
|
var io = websockets.server;
|
||||||
|
if (!io) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var roomClients = io.sockets.adapter.rooms;
|
||||||
|
var socketData = {
|
||||||
|
onlineGuestCount: websockets.getOnlineAnonCount(),
|
||||||
|
onlineRegisteredCount: websockets.getOnlineUserCount(),
|
||||||
|
socketCount: websockets.getSocketCount(),
|
||||||
|
users: {
|
||||||
|
categories: roomClients.categories ? Object.keys(roomClients.categories).length : 0,
|
||||||
|
recent: roomClients.recent_topics ? Object.keys(roomClients.recent_topics).length : 0,
|
||||||
|
unread: roomClients.unread_topics ? Object.keys(roomClients.unread_topics).length: 0,
|
||||||
|
popular: roomClients.popular_topics ? Object.keys(roomClients.popular_topics).length: 0,
|
||||||
|
topics: 0,
|
||||||
|
category: 0
|
||||||
|
},
|
||||||
|
topics: {}
|
||||||
|
};
|
||||||
|
|
||||||
|
var topTenTopics = [],
|
||||||
|
tid;
|
||||||
|
|
||||||
|
for (var room in roomClients) {
|
||||||
|
if (roomClients.hasOwnProperty(room)) {
|
||||||
|
tid = room.match(/^topic_(\d+)/);
|
||||||
|
if (tid) {
|
||||||
|
var length = Object.keys(roomClients[room]).length;
|
||||||
|
socketData.users.topics += length;
|
||||||
|
|
||||||
|
topTenTopics.push({tid: tid[1], count: length});
|
||||||
|
} else if (room.match(/^category/)) {
|
||||||
|
socketData.users.category += Object.keys(roomClients[room]).length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
topTenTopics = topTenTopics.sort(function(a, b) {
|
||||||
|
return b.count - a.count;
|
||||||
|
}).slice(0, 10);
|
||||||
|
|
||||||
|
var topTenTids = topTenTopics.map(function(topic) {
|
||||||
|
return topic.tid;
|
||||||
|
});
|
||||||
|
|
||||||
|
topics.getTopicsFields(topTenTids, ['title'], function(err, titles) {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
topTenTopics.forEach(function(topic, index) {
|
||||||
|
socketData.topics[topic.tid] = {
|
||||||
|
value: topic.count || 0,
|
||||||
|
title: validator.escape(titles[index].title)
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
callback(null, socketData);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = SocketRooms;
|
||||||
@@ -217,25 +217,32 @@ Sockets.in = function(room) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Sockets.getSocketCount = function() {
|
Sockets.getSocketCount = function() {
|
||||||
return rooms.socketCount();
|
if (!io) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return io.sockets.sockets.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.getUserSocketCount = function(uid) {
|
Sockets.getUserSocketCount = function(uid) {
|
||||||
return rooms.clients('uid_' + uid).length;
|
if (!io) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return io.sockets.adapter.rooms['uid_' + uid] ? Object.keys(io.sockets.adapter.rooms['uid_' + uid]).length : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.getOnlineUserCount = function() {
|
Sockets.getOnlineUserCount = function() {
|
||||||
var count = 0;
|
if (!io) {
|
||||||
Object.keys(rooms.roomClients()).forEach(function(roomName) {
|
return 0;
|
||||||
if (roomName.startsWith('uid_')) {
|
|
||||||
++ count;
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
return count;
|
return io.sockets.adapter.rooms.online_users ? Object.keys(io.sockets.adapter.rooms.online_users).length : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.getOnlineAnonCount = function () {
|
Sockets.getOnlineAnonCount = function () {
|
||||||
return rooms.clients('online_guests').length;
|
if (!io) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return io.sockets.adapter.rooms.online_guests ? Object.keys(io.sockets.adapter.rooms.online_guests).length : 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Sockets.reqFromSocket = function(socket) {
|
Sockets.reqFromSocket = function(socket) {
|
||||||
|
|||||||
@@ -82,62 +82,6 @@ function leaveCurrentRoom(socket) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SocketMeta.rooms.getAll = function(socket, data, callback) {
|
|
||||||
var roomClients = rooms.roomClients();
|
|
||||||
var socketData = {
|
|
||||||
onlineGuestCount: websockets.getOnlineAnonCount(),
|
|
||||||
onlineRegisteredCount: websockets.getOnlineUserCount(),
|
|
||||||
socketCount: websockets.getSocketCount(),
|
|
||||||
users: {
|
|
||||||
categories: roomClients.categories ? roomClients.categories.length : 0,
|
|
||||||
recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0,
|
|
||||||
unread: roomClients.unread_topics ? roomClients.unread_topics.length: 0,
|
|
||||||
popular: roomClients.popular_topics ? roomClients.popular_topics.length: 0,
|
|
||||||
topics: 0,
|
|
||||||
category: 0
|
|
||||||
},
|
|
||||||
topics: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
var topTenTopics = [],
|
|
||||||
tid;
|
|
||||||
|
|
||||||
for (var room in roomClients) {
|
|
||||||
if (roomClients.hasOwnProperty(room)) {
|
|
||||||
tid = room.match(/^topic_(\d+)/);
|
|
||||||
if (tid) {
|
|
||||||
var length = roomClients[room].length;
|
|
||||||
socketData.users.topics += length;
|
|
||||||
|
|
||||||
topTenTopics.push({tid: tid[1], count: length});
|
|
||||||
} else if (room.match(/^category/)) {
|
|
||||||
socketData.users.category += roomClients[room].length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
topTenTopics = topTenTopics.sort(function(a, b) {
|
|
||||||
return b.count - a.count;
|
|
||||||
}).slice(0, 10);
|
|
||||||
|
|
||||||
var topTenTids = topTenTopics.map(function(topic) {
|
|
||||||
return topic.tid;
|
|
||||||
});
|
|
||||||
|
|
||||||
topics.getTopicsFields(topTenTids, ['title'], function(err, titles) {
|
|
||||||
if (err) {
|
|
||||||
return callback(err);
|
|
||||||
}
|
|
||||||
topTenTopics.forEach(function(topic, index) {
|
|
||||||
socketData.topics[topic.tid] = {
|
|
||||||
value: topic.count || 0,
|
|
||||||
title: validator.escape(titles[index].title)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
callback(null, socketData);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
module.exports = SocketMeta;
|
module.exports = SocketMeta;
|
||||||
|
|||||||
Reference in New Issue
Block a user