mirror of
				https://github.com/NodeBB/NodeBB.git
				synced 2025-10-31 19:15:58 +01:00 
			
		
		
		
	info page
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							| @@ -39,6 +39,7 @@ pidfile | |||||||
|  |  | ||||||
| ## Directory-based project format: | ## Directory-based project format: | ||||||
| .idea/ | .idea/ | ||||||
|  | .vscode/ | ||||||
|  |  | ||||||
| ## File-based project format: | ## File-based project format: | ||||||
| *.ipr | *.ipr | ||||||
|   | |||||||
| @@ -2,24 +2,45 @@ | |||||||
|  |  | ||||||
| var async = require('async'); | var async = require('async'); | ||||||
| var os = require('os'); | var os = require('os'); | ||||||
|  | var winston = require('winston'); | ||||||
| var nconf = require('nconf'); | var nconf = require('nconf'); | ||||||
| var exec = require('child_process').exec; | var exec = require('child_process').exec; | ||||||
|  |  | ||||||
|  | var pubsub = require('../../pubsub'); | ||||||
| var rooms = require('../../socket.io/admin/rooms'); | var rooms = require('../../socket.io/admin/rooms'); | ||||||
|  |  | ||||||
| var infoController = {}; | var infoController = {}; | ||||||
|  |  | ||||||
| infoController.get = function(req, res, next) { | var info = []; | ||||||
|  |  | ||||||
|  | infoController.get = function(req, res, next) { | ||||||
|  | 	info = []; | ||||||
|  | 	pubsub.publish('sync:node:info:start'); | ||||||
|  | 	setTimeout(function() { | ||||||
|  | 		res.render('admin/development/info', {info: info, infoJSON: JSON.stringify(info, null, 4), host: os.hostname(), port: nconf.get('port')}); | ||||||
|  | 	}, 100); | ||||||
|  | }; | ||||||
|  |  | ||||||
|  | pubsub.on('sync:node:info:start', function() { | ||||||
|  | 	getNodeInfo(function(err, data) { | ||||||
|  | 		if (err) { | ||||||
|  | 			return winston.error(err); | ||||||
|  | 		} | ||||||
|  | 		pubsub.publish('sync:node:info:end', data); | ||||||
|  | 	}); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | pubsub.on('sync:node:info:end', function(data) { | ||||||
|  | 	info.push(data); | ||||||
|  | }); | ||||||
|  |  | ||||||
|  | function getNodeInfo(callback) { | ||||||
| 	var data = { | 	var data = { | ||||||
| 		process: { | 		process: { | ||||||
| 			port: nconf.get('port'), | 			port: nconf.get('port'), | ||||||
| 			pid: process.pid, | 			pid: process.pid, | ||||||
| 			title: process.title, | 			title: process.title, | ||||||
| 			arch: process.arch, |  | ||||||
| 			platform: process.platform, |  | ||||||
| 			version: process.version, | 			version: process.version, | ||||||
| 			versions: process.versions, |  | ||||||
| 			memoryUsage: process.memoryUsage(), | 			memoryUsage: process.memoryUsage(), | ||||||
| 			uptime: process.uptime() | 			uptime: process.uptime() | ||||||
| 		}, | 		}, | ||||||
| @@ -28,19 +49,28 @@ infoController.get = function(req, res, next) { | |||||||
| 			type: os.type(), | 			type: os.type(), | ||||||
| 			platform: os.platform(), | 			platform: os.platform(), | ||||||
| 			arch: os.arch(), | 			arch: os.arch(), | ||||||
| 			release: os.release() | 			release: os.release(), | ||||||
|  | 			load: os.loadavg().map(function(load){ return load.toFixed(2); }).join(', ') | ||||||
| 		} | 		} | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	getGitInfo(function(err, gitInfo) { | 	async.parallel({ | ||||||
|  | 		pubsub: function(next) { | ||||||
|  | 			pubsub.publish('sync:stats:start'); | ||||||
|  | 			next(); | ||||||
|  | 		}, | ||||||
|  | 		gitInfo: function(next) { | ||||||
|  | 			getGitInfo(next); | ||||||
|  | 		} | ||||||
|  | 	}, function(err, results) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return callback(err); | ||||||
| 		} | 		} | ||||||
| 		data.git = gitInfo; | 		data.git = results.gitInfo; | ||||||
|  | 		data.stats = rooms.stats[data.os.hostname + ':' + data.process.port]; | ||||||
| 		res.render('admin/development/info', {info: JSON.stringify(data, null, 4), stats: JSON.stringify(rooms.getStats(), null, 4)}); | 		callback(null, data); | ||||||
| 	}); | 	}); | ||||||
| }; | } | ||||||
|  |  | ||||||
| function getGitInfo(callback) { | function getGitInfo(callback) { | ||||||
| 	function get(cmd,  callback) { | 	function get(cmd,  callback) { | ||||||
|   | |||||||
| @@ -13,10 +13,18 @@ var helpers = require('./helpers'); | |||||||
| var usersController = {}; | var usersController = {}; | ||||||
|  |  | ||||||
| usersController.getOnlineUsers = function(req, res, next) { | usersController.getOnlineUsers = function(req, res, next) { | ||||||
| 	usersController.getUsers('users:online', req.uid, req.query.page, function(err, userData) { | 	async.parallel({ | ||||||
|  | 		users: function(next) { | ||||||
|  | 			usersController.getUsers('users:online', req.uid, req.query.page, next); | ||||||
|  | 		}, | ||||||
|  | 		guests: function(next) { | ||||||
|  | 			require('../socket.io/admin/rooms').getTotalGuestCount(next); | ||||||
|  | 		} | ||||||
|  | 	}, function(err, results) { | ||||||
| 		if (err) { | 		if (err) { | ||||||
| 			return next(err); | 			return next(err); | ||||||
| 		} | 		} | ||||||
|  | 		var userData = results.users; | ||||||
| 		var hiddenCount = 0; | 		var hiddenCount = 0; | ||||||
| 		if (!userData.isAdminOrGlobalMod) { | 		if (!userData.isAdminOrGlobalMod) { | ||||||
| 			userData.users = userData.users.filter(function(user) { | 			userData.users = userData.users.filter(function(user) { | ||||||
| @@ -27,7 +35,7 @@ usersController.getOnlineUsers = function(req, res, next) { | |||||||
| 			}); | 			}); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		userData.anonymousUserCount = require('../socket.io').getOnlineAnonCount() + hiddenCount; | 		userData.anonymousUserCount = results.guests + hiddenCount; | ||||||
|  |  | ||||||
| 		render(req, res, userData, next); | 		render(req, res, userData, next); | ||||||
| 	}); | 	}); | ||||||
|   | |||||||
| @@ -8,9 +8,13 @@ var validator = require('validator'); | |||||||
| var topics = require('../../topics'); | var topics = require('../../topics'); | ||||||
| var pubsub = require('../../pubsub'); | var pubsub = require('../../pubsub'); | ||||||
|  |  | ||||||
| var SocketRooms = {}; |  | ||||||
|  |  | ||||||
| var stats = {}; | var stats = {}; | ||||||
|  | var totals = {}; | ||||||
|  | var SocketRooms = { | ||||||
|  | 	stats: stats, | ||||||
|  | 	totals: totals | ||||||
|  | }; | ||||||
|  |  | ||||||
|  |  | ||||||
| pubsub.on('sync:stats:start', function() { | pubsub.on('sync:stats:start', function() { | ||||||
| 	getLocalStats(function(err, stats) { | 	getLocalStats(function(err, stats) { | ||||||
| @@ -25,20 +29,42 @@ pubsub.on('sync:stats:end', function(data) { | |||||||
| 	stats[data.id] = data.stats; | 	stats[data.id] = data.stats; | ||||||
| }); | }); | ||||||
|  |  | ||||||
|  | SocketRooms.getTotalGuestCount = function(callback) { | ||||||
|  | 	var count = 0; | ||||||
|  | 	pubsub.once('sync:stats:guests', function() { | ||||||
|  | 		var io = require('../index').server; | ||||||
|  |  | ||||||
|  | 		var roomClients = io.sockets.adapter.rooms; | ||||||
|  | 		var guestCount = roomClients.online_guests ? roomClients.online_guests.length : 0; | ||||||
|  | 		pubsub.publish('sync:stats:guests:end', guestCount); | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	pubsub.on('sync:stats:guests:end', function(guestCount) { | ||||||
|  | 		count += guestCount; | ||||||
|  | 	}); | ||||||
|  |  | ||||||
|  | 	pubsub.publish('sync:stats:guests'); | ||||||
|  |  | ||||||
|  | 	setTimeout(function() { | ||||||
|  | 		pubsub.removeAllListeners('sync:stats:guests:end'); | ||||||
|  | 		callback(null, count); | ||||||
|  | 	}, 100); | ||||||
|  | } | ||||||
|  |  | ||||||
|  |  | ||||||
| SocketRooms.getAll = function(socket, data, callback) { | SocketRooms.getAll = function(socket, data, callback) { | ||||||
| 	pubsub.publish('sync:stats:start'); | 	pubsub.publish('sync:stats:start'); | ||||||
| 	var totals = { |  | ||||||
| 		onlineGuestCount: 0, | 	totals.onlineGuestCount = 0; | ||||||
| 		onlineRegisteredCount: 0, | 	totals.onlineRegisteredCount = 0; | ||||||
| 		socketCount: 0, | 	totals.socketCount = 0; | ||||||
| 		users: { | 	totals.topics = {}; | ||||||
|  | 	totals.users = { | ||||||
| 		categories: 0, | 		categories: 0, | ||||||
| 		recent: 0, | 		recent: 0, | ||||||
| 		unread: 0, | 		unread: 0, | ||||||
| 		topics: 0, | 		topics: 0, | ||||||
| 		category: 0 | 		category: 0 | ||||||
| 		}, |  | ||||||
| 		topics: {} |  | ||||||
| 	}; | 	}; | ||||||
|  |  | ||||||
| 	for(var instance in stats) { | 	for(var instance in stats) { | ||||||
| @@ -88,22 +114,32 @@ SocketRooms.getAll = function(socket, data, callback) { | |||||||
| 	}); | 	}); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketRooms.getStats = function() { | SocketRooms.getOnlineUserCount = function(io) { | ||||||
| 	return stats; | 	if (!io) { | ||||||
|  | 		return 0; | ||||||
|  | 	} | ||||||
|  | 	var count = 0; | ||||||
|  | 	for (var key in io.sockets.adapter.rooms) { | ||||||
|  | 		if (io.sockets.adapter.rooms.hasOwnProperty(key) && key.startsWith('uid_')) { | ||||||
|  | 			++ count; | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
|  |  | ||||||
|  | 	return count; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| function getLocalStats(callback) { | function getLocalStats(callback) { | ||||||
| 	var websockets = require('../index'); | 	var io = require('../index').server; | ||||||
| 	var io = websockets.server; |  | ||||||
| 	if (!io) { | 	if (!io) { | ||||||
| 		return callback(); | 		return callback(); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	var roomClients = io.sockets.adapter.rooms; | 	var roomClients = io.sockets.adapter.rooms; | ||||||
| 	var socketData = { | 	var socketData = { | ||||||
| 		onlineGuestCount: websockets.getOnlineAnonCount(), | 		onlineGuestCount: roomClients.online_guests ? roomClients.online_guests.length : 0, | ||||||
| 		onlineRegisteredCount: websockets.getOnlineUserCount(), | 		onlineRegisteredCount: SocketRooms.getOnlineUserCount(io), | ||||||
| 		socketCount: websockets.getSocketCount(), | 		socketCount: Object.keys(io.sockets.sockets).length, | ||||||
| 		users: { | 		users: { | ||||||
| 			categories: roomClients.categories ? roomClients.categories.length : 0, | 			categories: roomClients.categories ? roomClients.categories.length : 0, | ||||||
| 			recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0, | 			recent: roomClients.recent_topics ? roomClients.recent_topics.length : 0, | ||||||
|   | |||||||
| @@ -213,14 +213,6 @@ Sockets.in = function(room) { | |||||||
| 	return io.in(room); | 	return io.in(room); | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Sockets.getSocketCount = function() { |  | ||||||
| 	if (!io) { |  | ||||||
| 		return 0; |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	return Object.keys(io.sockets.sockets).length; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.getUserSocketCount = function(uid) { | Sockets.getUserSocketCount = function(uid) { | ||||||
| 	if (!io) { | 	if (!io) { | ||||||
| 		return 0; | 		return 0; | ||||||
| @@ -230,27 +222,6 @@ Sockets.getUserSocketCount = function(uid) { | |||||||
| 	return room ? room.length : 0; | 	return room ? room.length : 0; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Sockets.getOnlineUserCount = function() { |  | ||||||
| 	if (!io) { |  | ||||||
| 		return 0; |  | ||||||
| 	} |  | ||||||
| 	var count = 0; |  | ||||||
| 	for (var key in io.sockets.adapter.rooms) { |  | ||||||
| 		if (io.sockets.adapter.rooms.hasOwnProperty(key) && key.startsWith('uid_')) { |  | ||||||
| 			++ count; |  | ||||||
| 		} |  | ||||||
| 	} |  | ||||||
| 	 |  | ||||||
| 	return count; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.getOnlineAnonCount = function () { |  | ||||||
| 	if (!io) { |  | ||||||
| 		return 0; |  | ||||||
| 	} |  | ||||||
| 	var room = io.sockets.adapter.rooms.online_guests; |  | ||||||
| 	return room ? room.length : 0; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.reqFromSocket = function(socket) { | Sockets.reqFromSocket = function(socket) { | ||||||
| 	var headers = socket.request.headers; | 	var headers = socket.request.headers; | ||||||
| @@ -268,33 +239,5 @@ Sockets.reqFromSocket = function(socket) { | |||||||
| 	}; | 	}; | ||||||
| }; | }; | ||||||
|  |  | ||||||
| Sockets.isUserOnline = function(uid) { |  | ||||||
| 	winston.warn('[deprecated] Sockets.isUserOnline'); |  | ||||||
| 	return false; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.isUsersOnline = function(uids, callback) { |  | ||||||
| 	winston.warn('[deprecated] Sockets.isUsersOnline'); |  | ||||||
| 	callback(null, uids.map(function() { return false; })); |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.getUsersInRoom = function (uid, roomName, start, stop, callback) { |  | ||||||
| 	winston.warn('[deprecated] Sockets.getUsersInRoom'); |  | ||||||
| 	callback(null, { |  | ||||||
| 		users: [], |  | ||||||
| 		room: roomName, |  | ||||||
| 		total: 0, |  | ||||||
| 		hidden: 0 |  | ||||||
| 	}); |  | ||||||
| 	return; |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| Sockets.getUidsInRoom = function(roomName, callback) { |  | ||||||
| 	winston.warn('[deprecated] Sockets.getUidsInRoom'); |  | ||||||
| 	callback = callback || function() {}; |  | ||||||
| 	callback(null, []); |  | ||||||
| }; |  | ||||||
|  |  | ||||||
|  |  | ||||||
| /* Exporting */ |  | ||||||
| module.exports = Sockets; | module.exports = Sockets; | ||||||
|   | |||||||
| @@ -217,10 +217,6 @@ SocketUser.setCategorySort = function(socket, sort, callback) { | |||||||
| 	} | 	} | ||||||
| }; | }; | ||||||
|  |  | ||||||
| SocketUser.getOnlineAnonCount = function(socket, data, callback) { |  | ||||||
| 	callback(null, module.parent.exports.getOnlineAnonCount()); |  | ||||||
| }; |  | ||||||
|  |  | ||||||
| SocketUser.getUnreadCount = function(socket, data, callback) { | SocketUser.getUnreadCount = function(socket, data, callback) { | ||||||
| 	if (!socket.uid) { | 	if (!socket.uid) { | ||||||
| 		return callback(null, 0); | 		return callback(null, 0); | ||||||
|   | |||||||
| @@ -1,4 +1,40 @@ | |||||||
| <div class="info"> | <div class="info"> | ||||||
|  | 	<div class="panel panel-default"> | ||||||
|  | 		<div class="panel-heading"> | ||||||
|  | 			<h3 class="panel-title">Info - You are on <strong>{host}:{port}</strong></h3> | ||||||
|  | 		</div> | ||||||
|  |  | ||||||
|  | 		<div class="panel-body"> | ||||||
|  | 			<table class="table table-striped"> | ||||||
|  | 				<thead> | ||||||
|  | 					<tr> | ||||||
|  | 						<td>host</td> | ||||||
|  | 						<td>pid</td> | ||||||
|  | 						<td>nodejs</td> | ||||||
|  | 						<td>online</td> | ||||||
|  | 						<td>git</td> | ||||||
|  | 						<td>load</td> | ||||||
|  | 						<td>uptime</td> | ||||||
|  | 					</tr> | ||||||
|  | 				</thead> | ||||||
|  | 				<tbody> | ||||||
|  | 				<!-- BEGIN info --> | ||||||
|  | 				<tr> | ||||||
|  | 					<td>{info.os.hostname}:{info.process.port}</td> | ||||||
|  | 					<td>{info.process.pid}</td> | ||||||
|  | 					<td>{info.process.version}</td> | ||||||
|  | 					<td><span title="Registered">{info.stats.onlineRegisteredCount}</span> / <span title="Guest">{info.stats.onlineGuestCount}</span> / <span title="Sockets">{info.stats.socketCount}</span></td> | ||||||
|  | 					<td>{info.git.branch}@<a href="https://github.com/NodeBB/NodeBB/commit/{info.git.hash}" target="_blank">{info.git.hash}</a></td> | ||||||
|  | 					<td>{info.os.load}</td> | ||||||
|  | 					<td>{info.process.uptime}</td> | ||||||
|  | 				</tr> | ||||||
|  | 				<!-- END info --> | ||||||
|  | 				</tbody> | ||||||
|  | 			</table> | ||||||
|  | 			</div> | ||||||
|  | 		</div> | ||||||
|  | 	</div> | ||||||
|  |  | ||||||
| 	<div class="panel panel-default"> | 	<div class="panel panel-default"> | ||||||
| 		<div class="panel-heading"> | 		<div class="panel-heading"> | ||||||
| 			<h3 class="panel-title">Info</h3> | 			<h3 class="panel-title">Info</h3> | ||||||
| @@ -6,19 +42,7 @@ | |||||||
|  |  | ||||||
| 		<div class="panel-body"> | 		<div class="panel-body"> | ||||||
| 			<div class="highlight"> | 			<div class="highlight"> | ||||||
| 				<pre>{info}</pre> | 				<pre>{infoJSON}</pre> | ||||||
| 			</div> |  | ||||||
| 		</div> |  | ||||||
| 	</div> |  | ||||||
|  |  | ||||||
| 	<div class="panel panel-default"> |  | ||||||
| 		<div class="panel-heading"> |  | ||||||
| 			<h3 class="panel-title">Stats</h3> |  | ||||||
| 		</div> |  | ||||||
|  |  | ||||||
| 		<div class="panel-body"> |  | ||||||
| 			<div class="highlight"> |  | ||||||
| 				<pre>{stats}</pre> |  | ||||||
| 			</div> | 			</div> | ||||||
| 		</div> | 		</div> | ||||||
| 	</div> | 	</div> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user