The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Rocket.Chat/packages/rocketchat-statistics/server/functions/get.js

101 lines
3.9 KiB

/* global InstanceStatus, MongoInternals */
import _ from 'underscore';
import os from 'os';
const wizardFields = [
'Organization_Type',
'Organization_Name',
'Industry',
'Size',
'Country',
'Website',
'Site_Name',
'Language',
'Server_Type',
'Allow_Marketing_Emails'
];
RocketChat.statistics.get = function _getStatistics() {
const statistics = {};
[NEW] Setup Wizard (#10523) * welcome * . * stylelint * new ilustration * new layout * . * implements dicts * added all setup wizard settings to wizard * fix some setup wizard css * fix setup wizard js linter errors * remove old setup wizard templaates * setup wizard has just one main tag now * setup wizard registration fields filter is more readable * add register server page to setup wizard * fix setup wizard progress bar on RTL * setup wizard is registering users * Add setup wizard tests, routes and fix batch * fix setup wizard tests * add api test back * comment rocketchat:google-natural-language package and remove logs * add some translation keys for setup wizard * remove old setup wizard template * fix sort code on setup wizard * fix getWizardSetting method * new migration for setupwizard * setup wizard setting migration * fix setupwizard migration * Update versions * fix some setup wizard code logic * fix setup wizard registerServer setting * rever package-lock.json * rever google-natural-language .npm folder * rever meteor packages file and add setup wizard * remove some default values from setup wizard settings * add advocacy option on setup wizard industry setting * change key name to setting to make the filter more readable on setup wizard * change key name to setting to make the filter more readable on setup wizard * add findWizardSettings on models Settings and handle errors of getWizardSettings method * change setting to key to make the filter more readable on setup wizard * fix setup wizard settings filter map * remove serverHasAdminUser method on setup wizard * fix setup wizard tests * fix setup wizard final step workspace link * fix setup wizard tests
8 years ago
// Setup Wizard
statistics.wizard = {};
wizardFields.forEach(field => {
const record = RocketChat.models.Settings.findOne(field);
if (record) {
const wizardField = field.replace(/_/g, '').replace(field[0], field[0].toLowerCase());
statistics.wizard[wizardField] = record.value;
}
});
[NEW] Setup Wizard (#10523) * welcome * . * stylelint * new ilustration * new layout * . * implements dicts * added all setup wizard settings to wizard * fix some setup wizard css * fix setup wizard js linter errors * remove old setup wizard templaates * setup wizard has just one main tag now * setup wizard registration fields filter is more readable * add register server page to setup wizard * fix setup wizard progress bar on RTL * setup wizard is registering users * Add setup wizard tests, routes and fix batch * fix setup wizard tests * add api test back * comment rocketchat:google-natural-language package and remove logs * add some translation keys for setup wizard * remove old setup wizard template * fix sort code on setup wizard * fix getWizardSetting method * new migration for setupwizard * setup wizard setting migration * fix setupwizard migration * Update versions * fix some setup wizard code logic * fix setup wizard registerServer setting * rever package-lock.json * rever google-natural-language .npm folder * rever meteor packages file and add setup wizard * remove some default values from setup wizard settings * add advocacy option on setup wizard industry setting * change key name to setting to make the filter more readable on setup wizard * change key name to setting to make the filter more readable on setup wizard * add findWizardSettings on models Settings and handle errors of getWizardSettings method * change setting to key to make the filter more readable on setup wizard * fix setup wizard settings filter map * remove serverHasAdminUser method on setup wizard * fix setup wizard tests * fix setup wizard final step workspace link * fix setup wizard tests
8 years ago
// 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.totalLivechat = 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();
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.deploy = {
method: process.env.DEPLOY_METHOD || 'tar',
platform: process.env.DEPLOY_PLATFORM || 'selfinstall'
};
statistics.migration = RocketChat.Migrations._getControl();
statistics.instanceCount = InstanceStatus.getCollection().find({ _updatedAt: { $gt: new Date(Date.now() - process.uptime() * 1000 - 2000) }}).count();
if (MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle && MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle.onOplogEntry && RocketChat.settings.get('Force_Disable_OpLog_For_Cache') !== true) {
statistics.oplogEnabled = true;
}
return statistics;
};