@resolveio/server-lib 12.5.53 → 12.5.54
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.nodemon.json +5 -0
- package/.vscode/settings.json +3 -0
- package/README.md +22 -0
- package/compileDTS.pl +64 -0
- package/gulpfile.js +127 -0
- package/mongodbensurers.js +2 -0
- package/mongostop.js +3 -0
- package/package.json +1 -1
- package/settings.development.json +13 -0
- package/src/client-server-app.ts +7 -0
- package/src/collections/app-status.collection.ts +51 -0
- package/src/collections/counter.collection.ts +54 -0
- package/src/collections/cron-job-history.collection.ts +82 -0
- package/src/collections/cron-job.collection.ts +85 -0
- package/src/collections/email-history.collection.ts +66 -0
- package/src/collections/email-verified.collection.ts +61 -0
- package/src/collections/file.collection.ts +73 -0
- package/src/collections/flag.collection.ts +56 -0
- package/src/collections/log-method-latency.collection.ts +64 -0
- package/src/collections/log-subscription.collection.ts +68 -0
- package/src/collections/log-ts.collection.ts +78 -0
- package/src/collections/log.collection.ts +77 -0
- package/src/collections/logged-in-users.collection.ts +65 -0
- package/src/collections/method-response.collection.ts +66 -0
- package/src/collections/monitor-cpu.collection.ts +63 -0
- package/src/collections/monitor-memory.collection.ts +75 -0
- package/src/collections/monitor-mongo.collection.ts +69 -0
- package/src/collections/notification.collection.ts +51 -0
- package/src/collections/report-builder-dashboard-builder.collection.ts +109 -0
- package/src/collections/report-builder-library.collection.ts +89 -0
- package/src/collections/report-builder-report.collection.ts +149 -0
- package/src/collections/user-group.collection.ts +90 -0
- package/src/collections/user-guide.collection.ts +57 -0
- package/src/collections/user.collection.ts +259 -0
- package/src/cron/cron.ts +188 -0
- package/src/fixtures/cron-jobs.ts +25 -0
- package/src/fixtures/init.ts +10 -0
- package/src/http/auth.ts +732 -0
- package/src/http/health.ts +7 -0
- package/src/http/home.ts +71 -0
- package/src/index.ts +71 -0
- package/src/managers/cron.manager.ts +208 -0
- package/src/managers/method.manager.ts +607 -0
- package/src/managers/mongo.manager.ts +2282 -0
- package/src/managers/monitor.manager.ts +323 -0
- package/src/managers/subscription.manager.ts +1196 -0
- package/{managers/subscription.performance.js → src/managers/subscription.performance.ts} +68 -33
- package/src/methods/accounts.ts +202 -0
- package/src/methods/aws.ts +507 -0
- package/src/methods/collections.ts +512 -0
- package/src/methods/counters.ts +75 -0
- package/src/methods/cron-jobs.ts +1454 -0
- package/src/methods/flags.ts +7 -0
- package/src/methods/logs.ts +327 -0
- package/src/methods/monitor.ts +548 -0
- package/src/methods/pdf.ts +615 -0
- package/src/methods/report-builder.ts +876 -0
- package/src/methods/support.ts +146 -0
- package/{models/app-status.model.d.ts → src/models/app-status.model.ts} +3 -2
- package/{models/billing-logged-in-users.model.d.ts → src/models/billing-logged-in-users.model.ts} +5 -4
- package/src/models/collection-document.model.ts +22 -0
- package/{models/counter.model.d.ts → src/models/counter.model.ts} +4 -3
- package/src/models/cron-job-history.model.ts +13 -0
- package/src/models/cron-job.model.ts +14 -0
- package/src/models/dialog.model.ts +25 -0
- package/{models/email-history.model.d.ts → src/models/email-history.model.ts} +8 -7
- package/{models/email-verified.model.d.ts → src/models/email-verified.model.ts} +6 -5
- package/{models/file.model.d.ts → src/models/file.model.ts} +8 -7
- package/{models/flag.model.d.ts → src/models/flag.model.ts} +4 -3
- package/{models/log-method-latency.model.d.ts → src/models/log-method-latency.model.ts} +5 -4
- package/{models/log-subscription.model.d.ts → src/models/log-subscription.model.ts} +8 -6
- package/{models/log.model.d.ts → src/models/log.model.ts} +12 -10
- package/{models/logged-in-users.model.d.ts → src/models/logged-in-users.model.ts} +6 -5
- package/{models/method-response.model.d.ts → src/models/method-response.model.ts} +7 -6
- package/src/models/method.model.ts +11 -0
- package/{models/monitor-cpu.model.d.ts → src/models/monitor-cpu.model.ts} +9 -7
- package/src/models/monitor-memory.model.ts +17 -0
- package/src/models/monitor-mongo.model.ts +15 -0
- package/{models/notification.model.d.ts → src/models/notification.model.ts} +3 -2
- package/src/models/pagination.model.ts +30 -0
- package/src/models/permission.model.ts +14 -0
- package/src/models/report-builder-dashboard-builder.model.ts +29 -0
- package/src/models/report-builder-library.model.ts +20 -0
- package/src/models/report-builder-report.model.ts +110 -0
- package/src/models/report-builder.model.ts +68 -0
- package/src/models/select-data-label.model.ts +9 -0
- package/src/models/server-response.model.ts +5 -0
- package/src/models/subscription.model.ts +64 -0
- package/src/models/support-ticket.model.ts +81 -0
- package/src/models/user-group.model.ts +23 -0
- package/{models/user-guide.model.d.ts → src/models/user-guide.model.ts} +5 -4
- package/src/models/user.model.ts +79 -0
- package/{public_api.d.ts → src/public_api.ts} +1 -1
- package/src/publications/app-status.ts +13 -0
- package/src/publications/cron-jobs.ts +30 -0
- package/src/publications/files.ts +34 -0
- package/src/publications/flags.ts +20 -0
- package/src/publications/logs.ts +164 -0
- package/src/publications/method-responses.ts +13 -0
- package/src/publications/notifications.ts +13 -0
- package/src/publications/report-builder-dashboard-builders.ts +39 -0
- package/src/publications/report-builder-libraries.ts +41 -0
- package/src/publications/report-builder-reports.ts +48 -0
- package/src/publications/super-admin.ts +13 -0
- package/src/publications/user-groups.ts +12 -0
- package/src/publications/user-guides.ts +12 -0
- package/src/server-app.ts +769 -0
- package/src/util/common.ts +519 -0
- package/src/util/schema-report-builder.ts +413 -0
- package/tsconfig.json +30 -0
- package/tslint.json +143 -0
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -48
- package/client-server-app.js.map +0 -1
- package/collections/app-status.collection.d.ts +0 -3
- package/collections/app-status.collection.js +0 -51
- package/collections/app-status.collection.js.map +0 -1
- package/collections/counter.collection.d.ts +0 -3
- package/collections/counter.collection.js +0 -54
- package/collections/counter.collection.js.map +0 -1
- package/collections/cron-job-history.collection.d.ts +0 -3
- package/collections/cron-job-history.collection.js +0 -82
- package/collections/cron-job-history.collection.js.map +0 -1
- package/collections/cron-job.collection.d.ts +0 -3
- package/collections/cron-job.collection.js +0 -85
- package/collections/cron-job.collection.js.map +0 -1
- package/collections/email-history.collection.d.ts +0 -3
- package/collections/email-history.collection.js +0 -66
- package/collections/email-history.collection.js.map +0 -1
- package/collections/email-verified.collection.d.ts +0 -3
- package/collections/email-verified.collection.js +0 -61
- package/collections/email-verified.collection.js.map +0 -1
- package/collections/file.collection.d.ts +0 -3
- package/collections/file.collection.js +0 -73
- package/collections/file.collection.js.map +0 -1
- package/collections/flag.collection.d.ts +0 -3
- package/collections/flag.collection.js +0 -56
- package/collections/flag.collection.js.map +0 -1
- package/collections/log-method-latency.collection.d.ts +0 -3
- package/collections/log-method-latency.collection.js +0 -64
- package/collections/log-method-latency.collection.js.map +0 -1
- package/collections/log-subscription.collection.d.ts +0 -3
- package/collections/log-subscription.collection.js +0 -68
- package/collections/log-subscription.collection.js.map +0 -1
- package/collections/log-ts.collection.d.ts +0 -3
- package/collections/log-ts.collection.js +0 -78
- package/collections/log-ts.collection.js.map +0 -1
- package/collections/log.collection.d.ts +0 -3
- package/collections/log.collection.js +0 -77
- package/collections/log.collection.js.map +0 -1
- package/collections/logged-in-users.collection.d.ts +0 -3
- package/collections/logged-in-users.collection.js +0 -65
- package/collections/logged-in-users.collection.js.map +0 -1
- package/collections/method-response.collection.d.ts +0 -3
- package/collections/method-response.collection.js +0 -66
- package/collections/method-response.collection.js.map +0 -1
- package/collections/monitor-cpu.collection.d.ts +0 -3
- package/collections/monitor-cpu.collection.js +0 -63
- package/collections/monitor-cpu.collection.js.map +0 -1
- package/collections/monitor-memory.collection.d.ts +0 -3
- package/collections/monitor-memory.collection.js +0 -75
- package/collections/monitor-memory.collection.js.map +0 -1
- package/collections/monitor-mongo.collection.d.ts +0 -3
- package/collections/monitor-mongo.collection.js +0 -69
- package/collections/monitor-mongo.collection.js.map +0 -1
- package/collections/notification.collection.d.ts +0 -3
- package/collections/notification.collection.js +0 -51
- package/collections/notification.collection.js.map +0 -1
- package/collections/report-builder-dashboard-builder.collection.d.ts +0 -3
- package/collections/report-builder-dashboard-builder.collection.js +0 -109
- package/collections/report-builder-dashboard-builder.collection.js.map +0 -1
- package/collections/report-builder-library.collection.d.ts +0 -3
- package/collections/report-builder-library.collection.js +0 -87
- package/collections/report-builder-library.collection.js.map +0 -1
- package/collections/report-builder-report.collection.d.ts +0 -4
- package/collections/report-builder-report.collection.js +0 -149
- package/collections/report-builder-report.collection.js.map +0 -1
- package/collections/user-group.collection.d.ts +0 -4
- package/collections/user-group.collection.js +0 -90
- package/collections/user-group.collection.js.map +0 -1
- package/collections/user-guide.collection.d.ts +0 -3
- package/collections/user-guide.collection.js +0 -57
- package/collections/user-guide.collection.js.map +0 -1
- package/collections/user.collection.d.ts +0 -4
- package/collections/user.collection.js +0 -259
- package/collections/user.collection.js.map +0 -1
- package/cron/cron.d.ts +0 -5
- package/cron/cron.js +0 -162
- package/cron/cron.js.map +0 -1
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -73
- package/fixtures/cron-jobs.js.map +0 -1
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -59
- package/fixtures/init.js.map +0 -1
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -763
- package/http/auth.js.map +0 -1
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -12
- package/http/health.js.map +0 -1
- package/http/home.d.ts +0 -2
- package/http/home.js +0 -66
- package/http/home.js.map +0 -1
- package/index.d.ts +0 -23
- package/index.js +0 -127
- package/index.js.map +0 -1
- package/managers/cron.manager.d.ts +0 -17
- package/managers/cron.manager.js +0 -242
- package/managers/cron.manager.js.map +0 -1
- package/managers/method.manager.d.ts +0 -38
- package/managers/method.manager.js +0 -595
- package/managers/method.manager.js.map +0 -1
- package/managers/mongo.manager.d.ts +0 -178
- package/managers/mongo.manager.js +0 -2221
- package/managers/mongo.manager.js.map +0 -1
- package/managers/monitor.manager.d.ts +0 -59
- package/managers/monitor.manager.js +0 -351
- package/managers/monitor.manager.js.map +0 -1
- package/managers/subscription.manager.d.ts +0 -50
- package/managers/subscription.manager.js +0 -1091
- package/managers/subscription.manager.js.map +0 -1
- package/managers/subscription.performance.d.ts +0 -1
- package/managers/subscription.performance.js.map +0 -1
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -274
- package/methods/accounts.js.map +0 -1
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -617
- package/methods/aws.js.map +0 -1
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -499
- package/methods/collections.js.map +0 -1
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -122
- package/methods/counters.js.map +0 -1
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -1315
- package/methods/cron-jobs.js.map +0 -1
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -9
- package/methods/flags.js.map +0 -1
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -371
- package/methods/logs.js.map +0 -1
- package/methods/monitor.d.ts +0 -2
- package/methods/monitor.js +0 -565
- package/methods/monitor.js.map +0 -1
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -468
- package/methods/pdf.js.map +0 -1
- package/methods/report-builder.d.ts +0 -2
- package/methods/report-builder.js +0 -858
- package/methods/report-builder.js.map +0 -1
- package/methods/support.d.ts +0 -2
- package/methods/support.js +0 -246
- package/methods/support.js.map +0 -1
- package/models/app-status.model.js +0 -4
- package/models/app-status.model.js.map +0 -1
- package/models/billing-logged-in-users.model.js +0 -4
- package/models/billing-logged-in-users.model.js.map +0 -1
- package/models/collection-document.model.d.ts +0 -19
- package/models/collection-document.model.js +0 -4
- package/models/collection-document.model.js.map +0 -1
- package/models/counter.model.js +0 -4
- package/models/counter.model.js.map +0 -1
- package/models/cron-job-history.model.d.ts +0 -12
- package/models/cron-job-history.model.js +0 -4
- package/models/cron-job-history.model.js.map +0 -1
- package/models/cron-job.model.d.ts +0 -13
- package/models/cron-job.model.js +0 -4
- package/models/cron-job.model.js.map +0 -1
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -4
- package/models/dialog.model.js.map +0 -1
- package/models/email-history.model.js +0 -4
- package/models/email-history.model.js.map +0 -1
- package/models/email-verified.model.js +0 -4
- package/models/email-verified.model.js.map +0 -1
- package/models/file.model.js +0 -4
- package/models/file.model.js.map +0 -1
- package/models/flag.model.js +0 -4
- package/models/flag.model.js.map +0 -1
- package/models/log-method-latency.model.js +0 -4
- package/models/log-method-latency.model.js.map +0 -1
- package/models/log-subscription.model.js +0 -4
- package/models/log-subscription.model.js.map +0 -1
- package/models/log.model.js +0 -4
- package/models/log.model.js.map +0 -1
- package/models/logged-in-users.model.js +0 -4
- package/models/logged-in-users.model.js.map +0 -1
- package/models/method-response.model.js +0 -4
- package/models/method-response.model.js.map +0 -1
- package/models/method.model.d.ts +0 -9
- package/models/method.model.js +0 -4
- package/models/method.model.js.map +0 -1
- package/models/monitor-cpu.model.js +0 -4
- package/models/monitor-cpu.model.js.map +0 -1
- package/models/monitor-memory.model.d.ts +0 -15
- package/models/monitor-memory.model.js +0 -4
- package/models/monitor-memory.model.js.map +0 -1
- package/models/monitor-mongo.model.d.ts +0 -13
- package/models/monitor-mongo.model.js +0 -4
- package/models/monitor-mongo.model.js.map +0 -1
- package/models/notification.model.js +0 -4
- package/models/notification.model.js.map +0 -1
- package/models/pagination.model.d.ts +0 -10
- package/models/pagination.model.js +0 -24
- package/models/pagination.model.js.map +0 -1
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -4
- package/models/permission.model.js.map +0 -1
- package/models/report-builder-dashboard-builder.model.d.ts +0 -25
- package/models/report-builder-dashboard-builder.model.js +0 -4
- package/models/report-builder-dashboard-builder.model.js.map +0 -1
- package/models/report-builder-library.model.d.ts +0 -17
- package/models/report-builder-library.model.js +0 -4
- package/models/report-builder-library.model.js.map +0 -1
- package/models/report-builder-report.model.d.ts +0 -98
- package/models/report-builder-report.model.js +0 -4
- package/models/report-builder-report.model.js.map +0 -1
- package/models/report-builder.model.d.ts +0 -61
- package/models/report-builder.model.js +0 -4
- package/models/report-builder.model.js.map +0 -1
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -4
- package/models/select-data-label.model.js.map +0 -1
- package/models/server-response.model.d.ts +0 -5
- package/models/server-response.model.js +0 -4
- package/models/server-response.model.js.map +0 -1
- package/models/subscription.model.d.ts +0 -23
- package/models/subscription.model.js +0 -4
- package/models/subscription.model.js.map +0 -1
- package/models/support-ticket.model.d.ts +0 -72
- package/models/support-ticket.model.js +0 -4
- package/models/support-ticket.model.js.map +0 -1
- package/models/user-group.model.d.ts +0 -19
- package/models/user-group.model.js +0 -4
- package/models/user-group.model.js.map +0 -1
- package/models/user-guide.model.js +0 -4
- package/models/user-guide.model.js.map +0 -1
- package/models/user.model.d.ts +0 -70
- package/models/user.model.js +0 -4
- package/models/user.model.js.map +0 -1
- package/public_api.js +0 -75
- package/public_api.js.map +0 -1
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -17
- package/publications/app-status.js.map +0 -1
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -33
- package/publications/cron-jobs.js.map +0 -1
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -37
- package/publications/files.js.map +0 -1
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -23
- package/publications/flags.js.map +0 -1
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -165
- package/publications/logs.js.map +0 -1
- package/publications/method-responses.d.ts +0 -2
- package/publications/method-responses.js +0 -17
- package/publications/method-responses.js.map +0 -1
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -17
- package/publications/notifications.js.map +0 -1
- package/publications/report-builder-dashboard-builders.d.ts +0 -2
- package/publications/report-builder-dashboard-builders.js +0 -43
- package/publications/report-builder-dashboard-builders.js.map +0 -1
- package/publications/report-builder-libraries.d.ts +0 -2
- package/publications/report-builder-libraries.js +0 -90
- package/publications/report-builder-libraries.js.map +0 -1
- package/publications/report-builder-reports.d.ts +0 -2
- package/publications/report-builder-reports.js +0 -51
- package/publications/report-builder-reports.js.map +0 -1
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -17
- package/publications/super-admin.js.map +0 -1
- package/publications/user-groups.d.ts +0 -1
- package/publications/user-groups.js +0 -17
- package/publications/user-groups.js.map +0 -1
- package/publications/user-guides.d.ts +0 -1
- package/publications/user-guides.js +0 -17
- package/publications/user-guides.js.map +0 -1
- package/server-app.d.ts +0 -52
- package/server-app.js +0 -739
- package/server-app.js.map +0 -1
- package/util/common.d.ts +0 -24
- package/util/common.js +0 -511
- package/util/common.js.map +0 -1
- package/util/schema-report-builder.d.ts +0 -6
- package/util/schema-report-builder.js +0 -453
- package/util/schema-report-builder.js.map +0 -1
- /package/{private → src/private}/email-templates/enrollment.html +0 -0
- /package/{private → src/private}/email-templates/forgot-password.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-modified.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket.html +0 -0
- /package/{private → src/private}/images/ResolveIO.png +0 -0
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import ResolveIOMainServer from '../server-app';
|
|
2
|
+
import axios from 'axios';
|
|
3
|
+
import { MonitorCPUs } from '../collections/monitor-cpu.collection';
|
|
4
|
+
import { MonitorMemorys } from '../collections/monitor-memory.collection';
|
|
5
|
+
import { MonitorMongos } from '../collections/monitor-mongo.collection';
|
|
6
|
+
import { ResolveIOServer } from '../index';
|
|
7
|
+
import { deepCopy } from '../util/common';
|
|
8
|
+
import { objectIdHexString } from './mongo.manager';
|
|
9
|
+
const os = require('os');
|
|
10
|
+
|
|
11
|
+
export class MonitorManager {
|
|
12
|
+
private _mainServer: ResolveIOMainServer;
|
|
13
|
+
private _serverConfig;
|
|
14
|
+
private _instanceHostname = '';
|
|
15
|
+
private _monitorData = [];
|
|
16
|
+
|
|
17
|
+
constructor(mainServer, serverConfig) {
|
|
18
|
+
this._mainServer = mainServer;
|
|
19
|
+
this._serverConfig = serverConfig;
|
|
20
|
+
this._instanceHostname = os.hostname().replace(/\./g, '-');
|
|
21
|
+
|
|
22
|
+
this.setupIntervals();
|
|
23
|
+
this.setupEventLoop();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//Create function to get CPU information
|
|
27
|
+
cpuAverage() {
|
|
28
|
+
//Initialise sum of idle and time of cores and fetch CPU info
|
|
29
|
+
var totalIdle = 0, totalTick = 0;
|
|
30
|
+
var cpus = os.cpus();
|
|
31
|
+
|
|
32
|
+
//Loop through CPU cores
|
|
33
|
+
for(var i = 0, len = cpus.length; i < len; i++) {
|
|
34
|
+
//Select CPU core
|
|
35
|
+
var cpu = cpus[i];
|
|
36
|
+
|
|
37
|
+
//Total up the time in the cores tick
|
|
38
|
+
for(let type in cpu.times) {
|
|
39
|
+
totalTick += cpu.times[type];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
//Total up the idle time of the core
|
|
43
|
+
totalIdle += cpu.times.idle;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
//Return the average Idle and Tick times
|
|
47
|
+
return {idle: totalIdle / cpus.length, total: totalTick / cpus.length};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async setupIntervals() {
|
|
51
|
+
if (this._serverConfig['ROOT_URL'] !== 'https://resolveio.com' && this._serverConfig['ROOT_URL'] !== 'http://localhost:4200') {
|
|
52
|
+
try {
|
|
53
|
+
let instanceId = await axios.get('http://169.254.169.254/latest/meta-data/instance-id');
|
|
54
|
+
|
|
55
|
+
setInterval(async () => {
|
|
56
|
+
try {
|
|
57
|
+
await axios.post('https://backend.resolveio.com/api/health', {
|
|
58
|
+
type: 'application',
|
|
59
|
+
id_aws_instance: instanceId.data,
|
|
60
|
+
version: typeof process.env.APP_VERSION === 'number' ? (<any>process.env.APP_VERSION).toString() : process.env.APP_VERSION,
|
|
61
|
+
version_key: process.env.APP_VERSION_KEY
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
catch(e) {}
|
|
65
|
+
}, 10000);
|
|
66
|
+
}
|
|
67
|
+
catch(errHealth) {}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
let lastCPU = this.cpuAverage();
|
|
71
|
+
|
|
72
|
+
setInterval(() => {
|
|
73
|
+
let now = new Date();
|
|
74
|
+
|
|
75
|
+
//Grab second Measure
|
|
76
|
+
var endMeasure = this.cpuAverage();
|
|
77
|
+
|
|
78
|
+
//Calculate the difference in idle and total time between the measures
|
|
79
|
+
var idleDifference = endMeasure.idle - lastCPU.idle;
|
|
80
|
+
var totalDifference = endMeasure.total - lastCPU.total;
|
|
81
|
+
|
|
82
|
+
//Calculate the average percentage CPU usage
|
|
83
|
+
var percentageCPU = 1 - idleDifference / totalDifference;
|
|
84
|
+
|
|
85
|
+
if (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {
|
|
86
|
+
MonitorCPUs.create({
|
|
87
|
+
_id: objectIdHexString(),
|
|
88
|
+
metadata: {
|
|
89
|
+
instance: this._instanceHostname,
|
|
90
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
91
|
+
},
|
|
92
|
+
date: now,
|
|
93
|
+
app: percentageCPU,
|
|
94
|
+
system: os.loadavg()[0]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
this._monitorData.push({
|
|
99
|
+
metadata: {
|
|
100
|
+
instance: this._instanceHostname,
|
|
101
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
102
|
+
},
|
|
103
|
+
date: now,
|
|
104
|
+
app: percentageCPU,
|
|
105
|
+
system: os.loadavg()[0],
|
|
106
|
+
type: 'cpu'
|
|
107
|
+
})
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
lastCPU = endMeasure;
|
|
111
|
+
|
|
112
|
+
const memUsage = process.memoryUsage();
|
|
113
|
+
|
|
114
|
+
if (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {
|
|
115
|
+
MonitorMemorys.create({
|
|
116
|
+
_id: objectIdHexString(),
|
|
117
|
+
metadata: {
|
|
118
|
+
instance: this._instanceHostname,
|
|
119
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
120
|
+
},
|
|
121
|
+
date: now,
|
|
122
|
+
physical_total: memUsage.heapTotal,
|
|
123
|
+
physical_used: memUsage.heapUsed,
|
|
124
|
+
physical_free: os.freemem(),
|
|
125
|
+
virtual: memUsage.rss,
|
|
126
|
+
private: memUsage.external,
|
|
127
|
+
physical: os.totalmem()
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
this._monitorData.push({
|
|
132
|
+
metadata: {
|
|
133
|
+
instance: this._instanceHostname,
|
|
134
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
135
|
+
},
|
|
136
|
+
date: now,
|
|
137
|
+
physical_total: memUsage.heapTotal,
|
|
138
|
+
physical_used: memUsage.heapUsed,
|
|
139
|
+
physical_free: os.freemem(),
|
|
140
|
+
virtual: memUsage.rss,
|
|
141
|
+
private: memUsage.external,
|
|
142
|
+
physical: os.totalmem(),
|
|
143
|
+
type: 'memory'
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
}, 3000);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
addMongoTracker(data: MongoMonitorModel) {
|
|
152
|
+
if (this._serverConfig['ROOT_URL'] === 'https://resolveio.com' || this._serverConfig['ROOT_URL'] === 'http://localhost:4200') {
|
|
153
|
+
if (!data.collection.startsWith('monitor-')) {
|
|
154
|
+
MonitorMongos.create({
|
|
155
|
+
_id: objectIdHexString(),
|
|
156
|
+
metadata: {
|
|
157
|
+
instance: this._instanceHostname,
|
|
158
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
159
|
+
},
|
|
160
|
+
date: new Date(data.date),
|
|
161
|
+
method: data.method,
|
|
162
|
+
doc_collection: data.collection,
|
|
163
|
+
duration: data.duration,
|
|
164
|
+
query: Buffer.byteLength(data.query, 'utf8') < 15800000 ? data.query : 'Too Big'
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
if (this._instanceHostname) {
|
|
170
|
+
if (this._serverConfig['ROOT_URL'] !== 'https://airdropxrp.io' && this._serverConfig['ROOT_URL'] !== 'https://xrptradereport.com') {
|
|
171
|
+
this._monitorData.push({
|
|
172
|
+
metadata: {
|
|
173
|
+
instance: this._instanceHostname,
|
|
174
|
+
client: this._serverConfig['CLIENT_NAME']
|
|
175
|
+
},
|
|
176
|
+
date: new Date(data.date),
|
|
177
|
+
method: data.method,
|
|
178
|
+
doc_collection: data.collection,
|
|
179
|
+
duration: data.duration,
|
|
180
|
+
query: Buffer.byteLength(data.query, 'utf8') < 15800000 ? data.query : 'Too Big',
|
|
181
|
+
type: 'mongo'
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
setupEventLoop() {
|
|
189
|
+
setInterval(async () => {
|
|
190
|
+
if (this._monitorData.length) {
|
|
191
|
+
let monitorData = this._monitorData.splice(0, Math.min(10, this._monitorData.length));
|
|
192
|
+
|
|
193
|
+
try {
|
|
194
|
+
await axios.post('https://backend.resolveio.com/api/monitor', monitorData);
|
|
195
|
+
}
|
|
196
|
+
catch (e) {}
|
|
197
|
+
}
|
|
198
|
+
}, 1000);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
export interface MongoMonitorModel {
|
|
203
|
+
date: Date,
|
|
204
|
+
method: string,
|
|
205
|
+
collection: string,
|
|
206
|
+
duration: number,
|
|
207
|
+
query: string
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export class MonitorMongo {
|
|
211
|
+
private _startTime = 0;
|
|
212
|
+
private _method = '';
|
|
213
|
+
private _collection = '';
|
|
214
|
+
private _query = '';
|
|
215
|
+
|
|
216
|
+
constructor(method: string, collection: string, query: string) {
|
|
217
|
+
this._startTime = Date.now();
|
|
218
|
+
this._method = method;
|
|
219
|
+
this._collection = collection;
|
|
220
|
+
this._query = query;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public finish() {
|
|
224
|
+
let endTime = Date.now();
|
|
225
|
+
|
|
226
|
+
let mongoMonitor: MongoMonitorModel = {
|
|
227
|
+
date: new Date(endTime),
|
|
228
|
+
method: this._method,
|
|
229
|
+
collection: this._collection,
|
|
230
|
+
query: this._query,
|
|
231
|
+
duration: endTime - this._startTime
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
ResolveIOServer.getMainServer().getMonitorManager().addMongoTracker(mongoMonitor);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export class MonitorManagerFunction {
|
|
239
|
+
private _functionCnt = 0;
|
|
240
|
+
private _functions: MonitorFunction[] = [];
|
|
241
|
+
private _functionLastCompletedWS: {
|
|
242
|
+
[id_socket: string]: MonitorFunction;
|
|
243
|
+
} = {};
|
|
244
|
+
private _functionLastCompleted: MonitorFunction;
|
|
245
|
+
|
|
246
|
+
constructor() {}
|
|
247
|
+
|
|
248
|
+
startMonitorFunction(functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any) {
|
|
249
|
+
let newMonitorFunction = new MonitorFunction(this._functionCnt++, functionType, functionName, user, id_socket, data);
|
|
250
|
+
this._functions.push(newMonitorFunction);
|
|
251
|
+
return newMonitorFunction.id;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
finishMonitorFunction(id: number) {
|
|
255
|
+
let monitor = this._functions.filter(a => a.id === id)[0];
|
|
256
|
+
if (monitor) {
|
|
257
|
+
monitor.finish();
|
|
258
|
+
this._functionLastCompleted = monitor;
|
|
259
|
+
this._functionLastCompletedWS[monitor.id_socket] = monitor;
|
|
260
|
+
this._functions.splice(this._functions.map(a => a.id).indexOf(id), 1);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
getActiveMonitorFunctions() {
|
|
265
|
+
return this._functions;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
getLastCompletedMonitorFunction() {
|
|
269
|
+
return this._functionLastCompleted;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
getLastCompletedMonitorFunctionWS() {
|
|
273
|
+
return this._functionLastCompletedWS;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export type MonitorFunctionType = 'Cron Method' | 'Internal Method' | 'Method' | 'User Specific Publication' | 'Publication';
|
|
278
|
+
export class MonitorFunction {
|
|
279
|
+
private _timer: NodeJS.Timeout = null;
|
|
280
|
+
private _maxDiff = 0;
|
|
281
|
+
private _functionType: MonitorFunctionType;
|
|
282
|
+
private _functionName: string;
|
|
283
|
+
private _user: string;
|
|
284
|
+
private _data: any;
|
|
285
|
+
public startTime: Date = null;
|
|
286
|
+
public endTime: Date = null;
|
|
287
|
+
public lastTime: Date = null;
|
|
288
|
+
public id_socket = '';
|
|
289
|
+
public id = 0;
|
|
290
|
+
|
|
291
|
+
constructor(id: number, functionType: MonitorFunctionType, functionName: string, user: string, id_socket: string, data: any) {
|
|
292
|
+
this.id = id;
|
|
293
|
+
this.startTime = new Date();
|
|
294
|
+
this._functionType = functionType;
|
|
295
|
+
this._functionName = functionName;
|
|
296
|
+
this._user = user;
|
|
297
|
+
this.id_socket = id_socket;
|
|
298
|
+
this._data = data;
|
|
299
|
+
this.lastTime = new Date();
|
|
300
|
+
|
|
301
|
+
this._timer = setInterval(() => {
|
|
302
|
+
let diff = Date.now() - this.lastTime.getTime();
|
|
303
|
+
if (diff > this._maxDiff) {
|
|
304
|
+
this._maxDiff = diff;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
this.lastTime = new Date();
|
|
308
|
+
}, 1000);
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
public finish() {
|
|
312
|
+
if (this._timer) {
|
|
313
|
+
clearInterval(this._timer);
|
|
314
|
+
this._timer = null;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
this.endTime = new Date();
|
|
318
|
+
|
|
319
|
+
if (this._maxDiff >= 5000) {
|
|
320
|
+
ResolveIOServer.getMainServer().getMethodManager().sendEmail('dev@resolveio.com', ResolveIOServer.getMainServer().getServerConfig()['CLIENT_NAME'] + ' - Slow ' + this._functionType + ' Detected', '', (this._user ? 'User: ' + this._user + '\n' : '') + this._functionType + ': ' + this._functionName + '\n' + 'During this function the event loop did not run for ' + this._maxDiff + ' ms (' + this._maxDiff / 1000 + ' sec)' + (this._data ? '\n\nData: ' + JSON.stringify(this._data, null, 2) : ''));
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|