bba3d6b174fd829b8dcc9e714042ae67363c2e1d
1 const Configuration
= require('./Configuration');
2 const logger
= require('./Logger');
3 const Utils
= require('./Utils');
7 this._objName
= objName
;
12 return Utils
.basicFormatLog(` ${this._objName} Statistics:`);
15 addMessage(command
, response
= false) {
17 if (this._statistics
[command
]) {
18 if (this._statistics
[command
].countResponse
) {
19 this._statistics
[command
].countResponse
++;
21 this._statistics
[command
].countResponse
= 1;
24 this._statistics
[command
] = {};
25 this._statistics
[command
].countResponse
= 1;
27 } else if (this._statistics
[command
] && this._statistics
[command
].count
) {
28 this._statistics
[command
].count
++;
30 this._statistics
[command
] = {};
31 this._statistics
[command
].count
= 1;
35 addPerformanceTimer(command
, duration
) {
36 let currentStatistics
;
37 // Map to proper command name
39 sendMeterValues
: 'MeterValues',
40 startTransaction
: 'StartTransaction',
41 stopTransaction
: 'StopTransaction',
43 if (MAPCOMMAND
[command
]) { // Get current command statistics
44 currentStatistics
= this._statistics
[MAPCOMMAND
[command
]];
45 } else if (this._statistics
[command
]) {
46 currentStatistics
= this._statistics
[command
];
48 this._statistics
[command
] = {};
49 currentStatistics
= this._statistics
[command
];
52 if (currentStatistics
) {
53 // Update current statistics timers
54 currentStatistics
.countTime
= (currentStatistics
.countTime
? currentStatistics
.countTime
+ 1 : 1);
55 currentStatistics
.minTime
= (currentStatistics
.minTime
? (currentStatistics
.minTime
> duration
? duration
: currentStatistics
.minTime
) : duration
);
56 currentStatistics
.maxTime
= (currentStatistics
.maxTime
? (currentStatistics
.maxTime
< duration
? duration
: currentStatistics
.maxTime
) : duration
);
57 currentStatistics
.totalTime
= (currentStatistics
.totalTime
? currentStatistics
.totalTime
+ duration
: duration
);
58 currentStatistics
.avgTime
= currentStatistics
.totalTime
/ currentStatistics
.countTime
;
62 logPerformance(entry
, className
) {
63 this.addPerformanceTimer(entry
.name
, entry
.duration
);
64 logger
.info(`${this._basicFormatLog()} class->${className}, method->${entry.name}, duration->${entry.duration}`);
68 // logger.info(this._basicFormatLog() + ' STARTING')
69 logger
.info(this._basicFormatLog() + ' %j', this._statistics
);
70 // logger.info(this._basicFormatLog() + ' ENDING')
74 if (Configuration
.getStatisticsDisplayInterval()) {
75 logger
.info(this._basicFormatLog() + ' displayed every ' + Configuration
.getStatisticsDisplayInterval() + 's');
78 }, Configuration
.getStatisticsDisplayInterval() * 1000);
83 this._displayInterval();
87 module
.exports
= Statistics
;