X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fperformance%2FPerformanceStatistics.ts;h=c5748922bd3dbae68dc4a6c944d6ed7d6e7eb88c;hb=c4ab56bac3353a08b0b7e058e9edfcfc0e629c94;hp=6471265efa45136e3bf03c75f43de1ea58b54163;hpb=5d0498291974ec3a130ba4b1c4663d13d16992c5;p=e-mobility-charging-stations-simulator.git diff --git a/src/performance/PerformanceStatistics.ts b/src/performance/PerformanceStatistics.ts index 6471265e..c5748922 100644 --- a/src/performance/PerformanceStatistics.ts +++ b/src/performance/PerformanceStatistics.ts @@ -4,6 +4,8 @@ import { type PerformanceEntry, PerformanceObserver, performance } from 'node:pe import type { URL } from 'node:url'; import { parentPort } from 'node:worker_threads'; +import { secondsToMilliseconds } from 'date-fns'; + import { ConfigurationSection, type IncomingRequestCommand, @@ -131,20 +133,14 @@ export class PerformanceStatistics { public start(): void { this.startLogStatisticsInterval(); - if ( + const performanceStorageConfiguration = Configuration.getConfigurationSection( ConfigurationSection.performanceStorage, - ).enabled - ) { + ); + if (performanceStorageConfiguration.enabled) { logger.info( - `${this.logPrefix()} storage enabled: type ${ - Configuration.getConfigurationSection( - ConfigurationSection.performanceStorage, - ).type - }, uri: ${ - Configuration.getConfigurationSection( - ConfigurationSection.performanceStorage, - ).uri + `${this.logPrefix()} storage enabled: type ${performanceStorageConfiguration.type}, uri: ${ + performanceStorageConfiguration.uri }`, ); } @@ -182,16 +178,16 @@ export class PerformanceStatistics { } private startLogStatisticsInterval(): void { - const logStatisticsInterval = Configuration.getConfigurationSection( + const logConfiguration = Configuration.getConfigurationSection( ConfigurationSection.log, - ).enabled - ? Configuration.getConfigurationSection(ConfigurationSection.log) - .statisticsInterval! + ); + const logStatisticsInterval = logConfiguration.enabled + ? logConfiguration.statisticsInterval! : 0; if (logStatisticsInterval > 0 && !this.displayInterval) { this.displayInterval = setInterval(() => { this.logStatistics(); - }, logStatisticsInterval * 1000); + }, secondsToMilliseconds(logStatisticsInterval)); logger.info( `${this.logPrefix()} logged every ${formatDurationSeconds(logStatisticsInterval)}`, ); @@ -199,11 +195,9 @@ export class PerformanceStatistics { logger.info( `${this.logPrefix()} already logged every ${formatDurationSeconds(logStatisticsInterval)}`, ); - } else if ( - Configuration.getConfigurationSection(ConfigurationSection.log).enabled - ) { + } else if (logConfiguration.enabled) { logger.info( - `${this.logPrefix()} log interval is set to ${logStatisticsInterval?.toString()}. Not logging statistics`, + `${this.logPrefix()} log interval is set to ${logStatisticsInterval}. Not logging statistics`, ); } }