Added monitoring counter
MODIFY
src/monitoring/MonitoringServer.ts
src/monitoring/MonitoringServer.ts
-import client, { Metric } from 'prom-client';
+import client from 'prom-client';
export default abstract class MonitoringServer {
public abstract start(): void;
public abstract getGauge(name: string): client.Gauge | undefined;
- public abstract getCounter(name: string): client.Counter | undefined;
+ public abstract createGaugeMetric(metricname : string, metrichelp : string) : client.Gauge;
}

MODIFY
src/monitoring/prometheus/PrometheusMonitoringServer.ts
src/monitoring/prometheus/PrometheusMonitoringServer.ts
import { Application, NextFunction, Request, Response } from 'express';
import { ServerAction, ServerType } from '../../types/Server';
+import client, { Counter, DefaultMetricsCollectorConfiguration, Gauge, Metric } from 'prom-client';
-import ExpressUtils from '../../server/ExpressUtils';
import Constants from '../../utils/Constants';
+import ExpressUtils from '../../server/ExpressUtils';
import Logging from '../../utils/Logging';
import MonitoringConfiguration from '../../types/configuration/MonitoringConfiguration';
import MonitoringServer from '../MonitoringServer';
import { ServerUtils } from '../../server/ServerUtils';
-import client, { Counter, DefaultMetricsCollectorConfiguration, Gauge, Metric } from 'prom-client';
-const MODULE_NAME = 'PrometheusMonitoringServer';
import global from '../../types/GlobalType';
+const MODULE_NAME = 'PrometheusMonitoringServer';
+
export default class PrometheusMonitoringServer extends MonitoringServer {
private monitoringConfig: MonitoringConfiguration;
private expressApplication: Application;
private mapGauge = new Map<string, Gauge>();
- private mapCounter = new Map<string, Counter>();
private clientRegistry = new client.Registry();
public constructor(monitoringConfig: MonitoringConfiguration) {
@@ -35,8 +35,6 @@ export default class PrometheusMonitoringServer extends MonitoringServer {
this.createGaugeMetric(Constants.MONGODB_CONNECTION_READY, 'The number of connection that are ready');
this.createGaugeMetric(Constants.MONGODB_CONNECTION_CREATED, 'The number of connection created');
this.createGaugeMetric(Constants.MONGODB_CONNECTION_CLOSED, 'The number of connection closed');
-
-
// Create HTTP Server
this.expressApplication = ExpressUtils.initApplication();
// Handle requests
@@ -61,25 +59,20 @@ export default class PrometheusMonitoringServer extends MonitoringServer {
return this.mapGauge.get(name) ;
}
-
- public getCounter(name: string): client.Counter | undefined {
- return this.mapCounter.get(name) ;
- }
-
public start(): void {
global.monitoringServer = this;
ServerUtils.startHttpServer(this.monitoringConfig,
ServerUtils.createHttpServer(this.monitoringConfig, this.expressApplication), MODULE_NAME, ServerType.MONITORING_SERVER);
}
- private createGaugeMetric(metricname : string, metrichelp : string) : void {
+ public createGaugeMetric(metricname : string, metrichelp : string) : Gauge {
const gaugeMetric : client.Gauge = new client.Gauge({
name: metricname,
help: metrichelp
});
this.mapGauge.set(metricname, gaugeMetric);
this.clientRegistry.registerMetric(gaugeMetric);
-
- }
+ return gaugeMetric;
}
+}

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
@@ -293,9 +293,6 @@ export default class MongoDBStorage {
global.monitoringServer.getGauge(Constants.MONGODB_CONNECTION_READY).set(connections.size);
}
);
- mongoDBClient.on('connectionPoolClosed',
- (event) => global.monitoringServer.getCounter(Constants.MONGODB_CONNECTION_POOL_CLOSED).inc(1)
- );
this.database = this.mongoDBClient.db();
// Keep a global reference
global.database = this;

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
@@ -2,8 +2,10 @@ import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Log, LogLevel } from '../types/Log';
import { NextFunction, Request, Response } from 'express';
import PerformanceRecord, { PerformanceRecordGroup, PerformanceTracingData } from '../types/Performance';
+import client, { Counter, DefaultMetricsCollectorConfiguration, Gauge, Metric } from 'prom-client';
+import global, { ActionsResponse } from '../types/GlobalType';
-import { ActionsResponse } from '../types/GlobalType';
+import { Action } from '../types/Authorization';
import AppAuthError from '../exception/AppAuthError';
import AppError from '../exception/AppError';
import BackendError from '../exception/BackendError';
@@ -24,6 +26,7 @@ import User from '../types/User';
import UserToken from '../types/UserToken';
import Utils from './Utils';
import chalk from 'chalk';
+import { duration } from 'moment';
import sizeof from 'object-sizeof';
const MODULE_NAME = 'Logging';
@@ -97,6 +100,25 @@ export default class Logging {
Logging.logConsoleWarning('====================================');
}
}
+
+ const gaugeDurationMetricName = 'mongodb' + '_' + tenant.subdomain + '_DurationMs_' + `${module}_${method}`;
+ let gaugeDurationMetric:client.Gauge = global.monitoringServer.getGauge(gaugeDurationMetricName);
+ if (!gaugeDurationMetric) {
+ gaugeDurationMetric = global.monitoringServer.createGaugeMetric(gaugeDurationMetricName, 'Db perf gauge duration ms');
+ }
+ gaugeDurationMetric.set(executionDurationMillis);
+ const gaugeRequestSizeMetricName = 'mongodb' + '_' + tenant.subdomain + '_RequestSize_' + `${module}_${method}`;
+ let gaugeRequestSizeMetric :client.Gauge = global.monitoringServer.getGauge(gaugeRequestSizeMetricName);
+ if (!gaugeRequestSizeMetric) {
+ gaugeRequestSizeMetric = global.monitoringServer.createGaugeMetric(gaugeRequestSizeMetricName, 'Db perf gauge request size');
+ }
+ gaugeRequestSizeMetric.set(sizeOfRequestDataKB);
+ const gaugeResponsetSizeMetricName = 'mongodb' + '_' + tenant.subdomain + '_ResponseSize_' + `${module}_${method}`;
+ let gaugeResponsetSizeMetric :client.Gauge = global.monitoringServer.getGauge(gaugeResponsetSizeMetricName);
+ if (!gaugeResponsetSizeMetric) {
+ gaugeResponsetSizeMetric = global.monitoringServer.createGaugeMetric(gaugeResponsetSizeMetricName, 'Db perf gauge response size');
+ }
+ gaugeResponsetSizeMetric.set(sizeOfResponseDataKB);
await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantSubdomain: tenant.subdomain,

Added monitoring counter