Add the message counts per room type to the stats

pull/5625/head
Bradley Hilton 8 years ago
parent 529fd21e5d
commit 9295d680cb
No known key found for this signature in database
GPG Key ID: 0666B2C24C43C358
  1. 5
      packages/rocketchat-i18n/i18n/en.i18n.json
  2. 10
      packages/rocketchat-lib/server/lib/notifyUsersOnMessage.js
  3. 1
      packages/rocketchat-lib/server/models/Messages.coffee
  4. 10
      packages/rocketchat-lib/server/models/Rooms.coffee
  5. 2
      packages/rocketchat-statistics/package.js
  6. 57
      packages/rocketchat-statistics/server/functions/get.coffee
  7. 66
      packages/rocketchat-statistics/server/functions/get.js
  8. 20
      packages/rocketchat-ui-admin/admin/adminInfo.html
  9. 8
      server/startup/migrations/v080.js

@ -1278,7 +1278,12 @@
"Stats_Online_Users": "Online Users",
"Stats_Total_Channels": "Total Channels",
"Stats_Total_Direct_Messages": "Total Direct Message Rooms",
"Stats_Total_Livechat_Rooms": "Total Livechat Rooms",
"Stats_Total_Messages": "Total Messages",
"Stats_Total_Messages_Channel": "Total Messages in Channels",
"Stats_Total_Messages_PrivateGroup": "Total Messages in Private Groups",
"Stats_Total_Messages_Direct": "Total Messages in Direct Messages",
"Stats_Total_Messages_Livechat": "Total Messages in Livechats",
"Stats_Total_Private_Groups": "Total Private Groups",
"Stats_Total_Rooms": "Total Rooms",
"Stats_Total_Users": "Total Users",

@ -1,12 +1,18 @@
import moment from 'moment';
RocketChat.callbacks.add('afterSaveMessage', function(message, room) {
// skips this callback if the message was edited
if (message.editedAt) {
// skips this callback if the message was edited and increments it if the edit was way in the past (aka imported)
if (message.editedAt && Math.abs(moment(message.editedAt).diff()) > 60000) {
//TODO: Review as I am not sure how else to get around this as the incrementing of the msgs count shouldn't be in this callback
RocketChat.models.Rooms.incMsgCountById(message.rid, 1);
return message;
} else if (message.editedAt) {
// skips this callback if the message was edited
return message;
}
if (message.ts && Math.abs(moment(message.ts).diff()) > 60000) {
RocketChat.models.Rooms.incMsgCountById(message.rid, 1);
return message;
}

@ -385,6 +385,7 @@ RocketChat.models.Messages = new class extends RocketChat.models._Base
_.extend record, extraData
record._id = @insertOrUpsert record
RocketChat.models.Rooms.incMsgCountById(room._id, 1)
return record
createUserJoinWithRoomIdAndUser: (roomId, user, extraData) ->

@ -397,6 +397,16 @@ class ModelRooms extends RocketChat.models._Base
return @update query, update
incMsgCountById: (_id, inc=1) ->
query =
_id: _id
update =
$inc:
msgs: inc
return @update query, update
incMsgCountAndSetLastMessageTimestampById: (_id, inc=1, lastMessageTimestamp) ->
query =
_id: _id

@ -16,7 +16,7 @@ Package.onUse(function(api) {
api.addFiles('lib/rocketchat.coffee', [ 'client', 'server' ]);
api.addFiles([
'server/models/Statistics.coffee',
'server/functions/get.coffee',
'server/functions/get.js',
'server/functions/save.coffee',
'server/methods/getStatistics.coffee'
], 'server');

@ -1,57 +0,0 @@
RocketChat.statistics.get = ->
statistics = {}
# Version
statistics.uniqueId = RocketChat.settings.get("uniqueID")
statistics.installedAt = RocketChat.models.Settings.findOne("uniqueID")?.createdAt
statistics.version = RocketChat.Info?.version
statistics.tag = RocketChat.Info?.tag
statistics.branch = RocketChat.Info?.branch
# User statistics
statistics.totalUsers = Meteor.users.find().count()
statistics.activeUsers = Meteor.users.find({ active: true }).count()
statistics.nonActiveUsers = statistics.totalUsers - statistics.activeUsers
statistics.onlineUsers = Meteor.users.find({ statusConnection: 'online' }).count()
statistics.awayUsers = Meteor.users.find({ statusConnection: 'away' }).count()
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers
# Room statistics
statistics.totalRooms = RocketChat.models.Rooms.find().count()
statistics.totalChannels = RocketChat.models.Rooms.findByType('c').count()
statistics.totalPrivateGroups = RocketChat.models.Rooms.findByType('p').count()
statistics.totalDirect = RocketChat.models.Rooms.findByType('d').count()
# Message statistics
statistics.totalMessages = RocketChat.models.Messages.find().count()
statistics.lastLogin = RocketChat.models.Users.getLastLogin()
statistics.lastMessageSentAt = RocketChat.models.Messages.getLastTimestamp()
statistics.lastSeenSubscription = RocketChat.models.Subscriptions.getLastSeen()
migration = Migrations?._getControl()
if migration
statistics.migration = _.pick(migration, 'version', 'locked')
os = Npm.require('os')
statistics.os =
type: os.type()
platform: os.platform()
arch: os.arch()
release: os.release()
uptime: os.uptime()
loadavg: os.loadavg()
totalmem: os.totalmem()
freemem: os.freemem()
cpus: os.cpus()
statistics.process =
nodeVersion: process.version
pid: process.pid
uptime: process.uptime()
statistics.migration = RocketChat.Migrations._getControl()
statistics.instanceCount = InstanceStatus.getCollection().find().count()
return statistics

@ -0,0 +1,66 @@
/* global InstanceStatus */
RocketChat.statistics.get = function _getStatistics() {
const statistics = {};
// Version
statistics.uniqueId = RocketChat.settings.get('uniqueID')
if (RocketChat.models.Settings.findOne('uniqueID')) {
statistics.installedAt = RocketChat.models.Settings.findOne('uniqueID').createdAt;
}
if (RocketChat.Info) {
statistics.version = RocketChat.Info.version;
statistics.tag = RocketChat.Info.tag;
statistics.branch = RocketChat.Info.branch;
}
// User statistics
statistics.totalUsers = Meteor.users.find().count();
statistics.activeUsers = Meteor.users.find({ active: true }).count();
statistics.nonActiveUsers = statistics.totalUsers - statistics.activeUsers;
statistics.onlineUsers = Meteor.users.find({ statusConnection: 'online' }).count();
statistics.awayUsers = Meteor.users.find({ statusConnection: 'away' }).count();
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers;
// Room statistics
statistics.totalRooms = RocketChat.models.Rooms.find().count();
statistics.totalChannels = RocketChat.models.Rooms.findByType('c').count();
statistics.totalPrivateGroups = RocketChat.models.Rooms.findByType('p').count();
statistics.totalDirect = RocketChat.models.Rooms.findByType('d').count();
statistics.totlalLivechat = RocketChat.models.Rooms.findByType('l').count();
// Message statistics
statistics.totalMessages = RocketChat.models.Messages.find().count();
statistics.totalChannelMessages = _.reduce(RocketChat.models.Rooms.findByType('c', { fields: { 'msgs': 1 }}).fetch(), function _countChannelMessages(num, room) { return num + room.msgs; }, 0);
statistics.totalPrivateGroupMessages = _.reduce(RocketChat.models.Rooms.findByType('p', { fields: { 'msgs': 1 }}).fetch(), function _countPrivateGroupMessages(num, room) { return num + room.msgs; }, 0);
statistics.totalDirectMessages = _.reduce(RocketChat.models.Rooms.findByType('d', { fields: { 'msgs': 1 }}).fetch(), function _countDirectMessages(num, room) { return num + room.msgs; }, 0);
statistics.totalLivechatMessages = _.reduce(RocketChat.models.Rooms.findByType('l', { fields: { 'msgs': 1 }}).fetch(), function _countLivechatMessages(num, room) { return num + room.msgs; }, 0);
statistics.lastLogin = RocketChat.models.Users.getLastLogin();
statistics.lastMessageSentAt = RocketChat.models.Messages.getLastTimestamp();
statistics.lastSeenSubscription = RocketChat.models.Subscriptions.getLastSeen();
const os = Npm.require('os');
statistics.os = {
type: os.type(),
platform: os.platform(),
arch: os.arch(),
release: os.release(),
uptime: os.uptime(),
loadavg: os.loadavg(),
totalmem: os.totalmem(),
freemem: os.freemem(),
cpus: os.cpus()
};
statistics.process = {
nodeVersion: process.version,
pid: process.pid,
uptime: process.uptime()
};
statistics.migration = RocketChat.Migrations._getControl();
statistics.instanceCount = InstanceStatus.getCollection().find().count();
return statistics;
};

@ -186,10 +186,30 @@
<th class="content-background-color border-component-color">{{_ "Stats_Total_Direct_Messages"}}</th>
<td class="border-component-color">{{statistics.totalDirect}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Livechat_Rooms"}}</th>
<td class="border-component-color">{{statistics.totalDirect}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Messages"}}</th>
<td class="border-component-color">{{statistics.totalMessages}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Messages_Channel"}}</th>
<td class="border-component-color">{{statistics.totalChannelMessages}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Messages_PrivateGroup"}}</th>
<td class="border-component-color">{{statistics.totalPrivateGroupMessages}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Messages_Direct"}}</th>
<td class="border-component-color">{{statistics.totalDirectMessages}}</td>
</tr>
<tr class="admin-table-row">
<th class="content-background-color border-component-color">{{_ "Stats_Total_Messages_Livechat"}}</th>
<td class="border-component-color">{{statistics.totalLivechatMessages}}</td>
</tr>
</table>
<button type="button" class="button primary refresh">Refresh</button>

@ -0,0 +1,8 @@
RocketChat.Migrations.add({
version: 80,
up: function() {
RocketChat.models.Rooms.find().forEach((room) => {
RocketChat.models.Rooms.incMsgCountById(room._id, RocketChat.models.Messages.find({ rid: room._id, t: { $exists: true }}).count());
});
}
});
Loading…
Cancel
Save