Log the type of server in Source field, disabled perf logs in prod
MODIFY
src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts
src/scheduler/tasks/LoggingDatabaseTableCleanupTask.ts
@@ -79,7 +79,7 @@ export default class LoggingDatabaseTableCleanupTask extends SchedulerTask {
try {
const lastLogMDB = global.database.getCollection(tenant.id, 'performances').find({})
.sort({ timestamp: -1 })
- .skip(20 * 1000 * 1000)
+ .skip(10 * 1000 * 1000)
.limit(1)
.project({ timestamp: 1 });
const lastLog = await lastLogMDB.toArray();

MODIFY
src/start.ts
src/start.ts
@@ -121,8 +121,12 @@ export default class Bootstrap {
// Update Charging Station Templates
// -------------------------------------------------------------------------
await Utils.updateChargingStationTemplatesFromFile();
+ // Keep server names
+ if (serverStarted.length === 1) {
+ global.serverName = serverStarted[0];
+ }
// Log
- const successMsg = `${serverStarted.join(', ')} server(s) has(ve) been started successfuly`;
+ const successMsg = `${serverStarted.join(', ')} server has been started successfuly`;
await Logging.logInfo({
tenantID: Constants.DEFAULT_TENANT,
action: ServerAction.BOOTSTRAP_STARTUP,
@@ -159,7 +163,7 @@ export default class Bootstrap {
// Start database Socket IO notifications
await this.centralRestServer.startSocketIO();
}
- serverStarted.push('REST');
+ serverStarted.push('Rest');
}
// -------------------------------------------------------------------------
// Listen to DB changes
@@ -183,14 +187,14 @@ export default class Bootstrap {
Bootstrap.SoapCentralSystemServer = new SoapCentralSystemServer(centralSystemConfig, Bootstrap.chargingStationConfig);
// Start
await Bootstrap.SoapCentralSystemServer.start();
- serverStarted.push('OCPP/Soap');
+ serverStarted.push('Soap');
break;
case CentralSystemImplementation.JSON:
// Create implementation
Bootstrap.JsonCentralSystemServer = new JsonCentralSystemServer(centralSystemConfig, Bootstrap.chargingStationConfig);
// Start
await Bootstrap.JsonCentralSystemServer.start();
- serverStarted.push('OCPP/Json');
+ serverStarted.push('Json');
break;
// Not Found
default:
@@ -207,7 +211,7 @@ export default class Bootstrap {
Bootstrap.ocpiServer = new OCPIServer(Bootstrap.ocpiConfig);
// Start server instance
await Bootstrap.ocpiServer.start();
- serverStarted.push('OCPI');
+ serverStarted.push('Ocpi');
}
// -------------------------------------------------------------------------
// OICP Server
@@ -217,7 +221,7 @@ export default class Bootstrap {
Bootstrap.oicpServer = new OICPServer(Bootstrap.oicpConfig);
// Start server instance
await Bootstrap.oicpServer.start();
- serverStarted.push('OICP');
+ serverStarted.push('Oicp');
}
// -------------------------------------------------------------------------
// OData Server

MODIFY
src/storage/mongodb/PerformanceStorage.ts
src/storage/mongodb/PerformanceStorage.ts
@@ -14,14 +14,6 @@ export default class PerformanceStorage {
DatabaseUtils.convertToObjectID(performanceRecord.tenantID) : Constants.DEFAULT_TENANT,
timestamp: Utils.convertToDate(performanceRecord.timestamp),
host: performanceRecord.host,
- numberOfCPU: performanceRecord.numberOfCPU,
- modelOfCPU: performanceRecord.modelOfCPU,
- memoryTotalGb: performanceRecord.memoryTotalGb,
- memoryFreeGb: performanceRecord.memoryFreeGb,
- loadAverageLastMin: performanceRecord.loadAverageLastMin,
- process: performanceRecord.process,
- processMemoryUsage: performanceRecord.processMemoryUsage,
- processCPUUsage: performanceRecord.processCPUUsage,
source: performanceRecord.source,
module: performanceRecord.module,
method: performanceRecord.method,
@@ -36,10 +28,6 @@ export default class PerformanceStorage {
if (performanceRecord.parentID) {
performanceRecordMDB.parentID = DatabaseUtils.convertToObjectID(performanceRecord.parentID);
}
- // Add nbr charging stations only if provided
- if (Utils.convertToInt(performanceRecord.numberOfChargingStations) > 0) {
- performanceRecordMDB.numberOfChargingStations = Utils.convertToInt(performanceRecord.numberOfChargingStations);
- }
// Add duration only if provided
if (Utils.convertToInt(performanceRecord.durationMs) > 0) {
performanceRecordMDB.durationMs = Utils.convertToInt(performanceRecord.durationMs);

MODIFY
src/types/GlobalType.ts
src/types/GlobalType.ts
@@ -55,6 +55,7 @@ interface TSGlobal extends Global {
appRoot: string;
centralSystemJsonServer: JsonCentralSystemServer;
centralSystemSoapServer: SoapCentralSystemServer;
+ serverName: string;
}

MODIFY
src/types/Performance.ts
src/types/Performance.ts
@@ -7,15 +7,6 @@ export default interface PerformanceRecord {
durationMs?: number;
sizeKb?: number;
host: string;
- process: string;
- processMemoryUsage: NodeJS.MemoryUsage;
- processCPUUsage: NodeJS.CpuUsage;
- numberOfCPU: number;
- modelOfCPU: string;
- memoryTotalGb: number;
- memoryFreeGb: number;
- loadAverageLastMin: number;
- numberOfChargingStations?: number;
source: string;
module: string;
method: string;

MODIFY
src/utils/Constants.ts
src/utils/Constants.ts
@@ -249,7 +249,6 @@ export default class Constants {
public static readonly ROAMING_AUTHORIZATION_TIMEOUT_MINS = 2;
- public static readonly OICP_SERVER = 'OICP Server';
public static readonly MODULE_AXIOS = 'Axios';
public static readonly MODULE_JSON_OCPP_SERVER_16 = 'OcppJ-16';
@@ -257,12 +256,13 @@ export default class Constants {
public static readonly MODULE_SOAP_OCPP_SERVER_15 = 'OcppS-15';
public static readonly MODULE_SOAP_OCPP_SERVER_16 = 'OcppS-16';
- // OICP constants
+ public static readonly OICP_SERVER = 'OICPServer';
public static readonly OICP_PROGRESS_NOTIFICATION_MAX_INTERVAL = 300; // Hubject restriction: "Progress Notification can be sent only at interval of at least 300 seconds." (5 Minutes)
public static readonly OICP_VIRTUAL_USER_EMAIL = 'virtual@oicp.com';
+
public static readonly OCPP_SERVER = 'OCPPServer';
public static readonly DATABASE_SERVER = 'DatabaseServer';
- public static readonly REST_SERVER = 'REST Server';
+ public static readonly REST_SERVER = 'RestServer';
public static readonly AXIOS_CLIENT = 'AxiosClient';
public static readonly WITH_CHARGING_STATIONS = true; // Not used

MODIFY
src/utils/Logging.ts
src/utils/Logging.ts
import { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios';
import { Log, LogLevel, LogType } from '../types/Log';
import { NextFunction, Request, Response } from 'express';
+import global, { ActionsResponse } from '../types/GlobalType';
-import { ActionsResponse } from '../types/GlobalType';
import AppAuthError from '../exception/AppAuthError';
import AppError from '../exception/AppError';
import BackendError from '../exception/BackendError';
@@ -95,7 +95,7 @@ export default class Logging {
console.warn(chalk.yellow('===================================='));
}
}
- await PerformanceStorage.savePerformanceRecord(
+ Utils.isDevelopmentEnv() && await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantID,
group: PerformanceRecordGroup.MONGO_DB,
@@ -366,7 +366,7 @@ export default class Logging {
headers: res.getHeaders(),
}
});
- void PerformanceStorage.savePerformanceRecord(
+ Utils.isDevelopmentEnv() && void PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantID,
group: Utils.getPerformanceRecordGroupFromURL(req.url),
@@ -467,7 +467,7 @@ export default class Logging {
response: Utils.cloneObject(response.data)
}
});
- await PerformanceStorage.savePerformanceRecord(
+ Utils.isDevelopmentEnv() && await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantID,
group: Utils.getPerformanceRecordGroupFromURL(response.config.url),
@@ -835,6 +835,11 @@ export default class Logging {
if (!log.tenantID || log.tenantID === '') {
log.tenantID = Constants.DEFAULT_TENANT;
}
+ if (global.serverName &&
+ global.serverName !== Constants.CENTRAL_SERVER &&
+ log.source === Constants.CENTRAL_SERVER) {
+ log.source = `${global.serverName}Server`;
+ }
// Log in Cloud Foundry
if (Configuration.isCloudFoundry()) {
// Bind to express app
@@ -1009,7 +1014,7 @@ export default class Logging {
message, detailedMessages
});
}
- await PerformanceStorage.savePerformanceRecord(
+ Utils.isDevelopmentEnv() && await PerformanceStorage.savePerformanceRecord(
Utils.buildPerformanceRecord({
tenantID, chargingStationID,
group: PerformanceRecordGroup.OCPP,

MODIFY
src/utils/Utils.ts
src/utils/Utils.ts
@@ -1520,15 +1520,6 @@ export default class Utils {
durationMs: params.durationMs,
sizeKb: params.sizeKb,
host: Utils.getHostname(),
- process: cluster.isWorker ? 'worker ' + cluster.worker.id.toString() : 'master',
- processMemoryUsage: process.memoryUsage(),
- processCPUUsage: process.cpuUsage(),
- numberOfCPU: cpuInfo.length,
- modelOfCPU: cpuInfo.length > 0 ? cpuInfo[0].model : '',
- memoryTotalGb: Utils.createDecimal(os.totalmem()).div(Constants.ONE_BILLION).toNumber(),
- memoryFreeGb: Utils.createDecimal(os.freemem()).div(Constants.ONE_BILLION).toNumber(),
- loadAverageLastMin: os.loadavg()[0],
- numberOfChargingStations: global.centralSystemJsonServer?.getNumberOfJsonConnections(),
source: params.source,
module: params.module,
method: params.method,

Log the type of server in Source field, disabled perf logs in prod