[NEW] Statistics about language usage (#20832)

Co-authored-by: Diego Sampaio <chinello@gmail.com>
pull/20853/head
Gabriel Thomé 5 years ago committed by GitHub
parent 2d65486158
commit 5e05e6ab81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/cloud/server/functions/buildRegistrationData.js
  2. 20
      app/metrics/server/lib/collectMetrics.js
  3. 2
      app/models/server/models/Statistics.js
  4. 1
      app/models/server/models/Users.js
  5. 21
      app/models/server/raw/Users.js
  6. 21
      app/statistics/server/lib/statistics.js
  7. 1
      server/startup/migrations/index.js
  8. 9
      server/startup/migrations/v218.js

@ -1,10 +1,10 @@
import { settings } from '../../../settings';
import { Users } from '../../../models';
import { settings } from '../../../settings/server';
import { Users, Statistics } from '../../../models/server';
import { statistics } from '../../../statistics';
import { LICENSE_VERSION } from '../license';
export function buildWorkspaceRegistrationData() {
const stats = statistics.get();
const stats = Statistics.findLast() || statistics.get();
const address = settings.get('Site_Url');
const siteName = settings.get('Site_Name');

@ -31,6 +31,16 @@ const setPrometheusData = async () => {
metrics.ddpAuthenticatedSessions.set(authenticatedSessions.length);
metrics.ddpConnectedUsers.set(_.unique(authenticatedSessions.map((s) => s.userId)).length);
// Apps metrics
const { totalInstalled, totalActive, totalFailed } = getAppsStatistics();
metrics.totalAppsInstalled.set(totalInstalled || 0);
metrics.totalAppsEnabled.set(totalActive || 0);
metrics.totalAppsFailed.set(totalFailed || 0);
const oplogQueue = getOplogInfo().mongo._oplogHandle?._entryQueue?.length || 0;
metrics.oplogQueue.set(oplogQueue);
const statistics = Statistics.findLast();
if (!statistics) {
return;
@ -63,16 +73,6 @@ const setPrometheusData = async () => {
metrics.totalDirectMessages.set(statistics.totalDirectMessages);
metrics.totalLivechatMessages.set(statistics.totalLivechatMessages);
// Apps metrics
const { totalInstalled, totalActive, totalFailed } = getAppsStatistics();
metrics.totalAppsInstalled.set(totalInstalled || 0);
metrics.totalAppsEnabled.set(totalActive || 0);
metrics.totalAppsFailed.set(totalFailed || 0);
const oplogQueue = getOplogInfo().mongo._oplogHandle?._entryQueue?.length || 0;
metrics.oplogQueue.set(oplogQueue);
metrics.pushQueue.set(statistics.pushQueue || 0);
};

@ -4,7 +4,7 @@ export class Statistics extends Base {
constructor() {
super('statistics');
this.tryEnsureIndex({ createdAt: 1 });
this.tryEnsureIndex({ createdAt: -1 });
}
// FIND ONE

@ -53,6 +53,7 @@ export class Users extends Base {
this.tryEnsureIndex({ 'services.saml.inResponseTo': 1 });
this.tryEnsureIndex({ openBusinessHours: 1 }, { sparse: true });
this.tryEnsureIndex({ statusLivechat: 1 }, { sparse: true });
this.tryEnsureIndex({ language: 1 }, { sparse: true });
}
getLoginTokensByUserId(userId) {

@ -388,6 +388,27 @@ export class UsersRaw extends BaseRaw {
return this.col.aggregate(params).toArray();
}
getUserLanguages() {
const pipeline = [
{
$match: {
language: {
$exists: true,
$ne: '',
},
},
},
{
$group: {
_id: '$language',
total: { $sum: 1 },
},
},
];
return this.col.aggregate(pipeline).toArray();
}
updateStatusText(_id, statusText) {
const update = {
$set: {

@ -20,7 +20,7 @@ import { settings } from '../../../settings/server';
import { Info, getMongoInfo } from '../../../utils/server';
import { Migrations } from '../../../migrations/server';
import { getStatistics as federationGetStatistics } from '../../../federation/server/functions/dashboard';
import { NotificationQueue } from '../../../models/server/raw';
import { NotificationQueue, Users as UsersRaw } from '../../../models/server/raw';
import { readSecondaryPreferred } from '../../../../server/database/readSecondaryPreferred';
import { getAppsStatistics } from './getAppsStatistics';
import { getStatistics as getEnterpriseStatistics } from '../../../../ee/app/license/server';
@ -35,6 +35,24 @@ const wizardFields = [
'Register_Server',
];
const getUserLanguages = (totalUsers) => {
const result = Promise.await(UsersRaw.getUserLanguages());
const languages = {
none: totalUsers,
};
result.forEach(({ _id, total }) => {
if (!_id) {
return;
}
languages[_id] = total;
languages.none -= total;
});
return languages;
};
export const statistics = {
get: function _getStatistics() {
const readPreference = readSecondaryPreferred(Uploads.model.rawDatabase());
@ -74,6 +92,7 @@ export const statistics = {
statistics.busyUsers = Meteor.users.find({ status: 'busy' }).count();
statistics.totalConnectedUsers = statistics.onlineUsers + statistics.awayUsers;
statistics.offlineUsers = statistics.totalUsers - statistics.onlineUsers - statistics.awayUsers - statistics.busyUsers;
statistics.userLanguages = getUserLanguages(statistics.totalUsers);
// Room statistics
statistics.totalRooms = Rooms.find().count();

@ -214,4 +214,5 @@ import './v214';
import './v215';
import './v216';
import './v217';
import './v218';
import './xrun';

@ -0,0 +1,9 @@
import { Migrations } from '../../../app/migrations/server';
import { Statistics } from '../../../app/models/server';
Migrations.add({
version: 218,
up() {
Statistics.tryDropIndex({ createdAt: 1 });
},
});
Loading…
Cancel
Save