summaryrefslogtreecommitdiffstats
path: root/server/statistics.js
blob: 997fd86f3c3868c0992c22414dcb3131d5241796 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { MongoInternals } from 'meteor/mongo';

Meteor.methods({
  getStatistics() {
    const os = require('os');
    const pjson = require('/package.json');
    const statistics = {};
    let wekanVersion = pjson.version;
    wekanVersion = wekanVersion.replace('v', '');
    statistics.version = wekanVersion;
    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(),
    };
    let nodeVersion = process.version;
    nodeVersion = nodeVersion.replace('v', '');
    statistics.process = {
      nodeVersion,
      pid: process.pid,
      uptime: process.uptime(),
    };
    // Remove beginning of Meteor release text METEOR@
    let meteorVersion = Meteor.release;
    meteorVersion = meteorVersion.replace('METEOR@', '');
    statistics.meteor = {
      meteorVersion,
    };
    // Thanks to RocketChat for MongoDB version detection !
    // https://github.com/RocketChat/Rocket.Chat/blob/develop/app/utils/server/functions/getMongoInfo.js
    let mongoVersion;
    let mongoStorageEngine;
    let mongoOplogEnabled;
    try {
      const { mongo } = MongoInternals.defaultRemoteCollectionDriver();
      oplogEnabled = Boolean(
        mongo._oplogHandle && mongo._oplogHandle.onOplogEntry,
      );
      const { version, storageEngine } = Promise.await(
        mongo.db.command({ serverStatus: 1 }),
      );
      mongoVersion = version;
      mongoStorageEngine = storageEngine.name;
      mongoOplogEnabled = oplogEnabled;
    } catch (e) {
      try {
        const { version } = Promise.await(mongo.db.command({ buildinfo: 1 }));
        mongoVersion = version;
        mongoStorageEngine = 'unknown';
      } catch (e) {
        mongoVersion = 'unknown';
        mongoStorageEngine = 'unknown';
      }
    }
    statistics.mongo = {
      mongoVersion,
      mongoStorageEngine,
      mongoOplogEnabled,
    };
    return statistics;
  },
});