UNPKG

airship-server

Version:

Airship is a framework for Node.JS & TypeScript that helps you to write big, scalable and maintainable API servers.

46 lines 1.92 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const BaseStatisticsCounter_1 = require("../domain/BaseStatisticsCounter"); const process_1 = require("process"); class LocalStatisticsCounter extends BaseStatisticsCounter_1.BaseStatisticsCounter { constructor(logger, silently = false, logFrequency = 5000) { super(); this._logger = logger; this._hitsPerSecond = 0; this._hitsPerMinute = 0; this._concurrentRequests = 0; this._allRequests = 0; this._logger.log('Local statistics started'); setInterval(() => { if (!silently) { let memUsage = process_1.memoryUsage(); this._logger.log('Local statistics:', `\n Hits per second: ${this._hitsPerSecond}\n` + ` Hits per minute: ${this._hitsPerMinute}\n` + ` All hits: ${this._allRequests}\n` + ` Concurrent requests: ${this._concurrentRequests}\n` + ` Total memory in RAM: ${this.toMegabytes(memUsage.rss)} mb\n` + ` Native modules memory usage: ${this.toMegabytes(memUsage.external)} mb\n` + ` V8 total heap: ${this.toMegabytes(memUsage.heapTotal)} mb\n` + ` V8 used heap: ${this.toMegabytes(memUsage.heapUsed)} mb\n`); } this._hitsPerSecond = 0; }, logFrequency); setInterval(() => { this._hitsPerMinute = 0; }, 1000 * 60); } countRequestHit() { this._hitsPerSecond++; this._hitsPerMinute++; this._concurrentRequests++; this._allRequests++; } doneRequest() { this._concurrentRequests--; } toMegabytes(bytes) { return (bytes / 1048576).toFixed(2); } } exports.default = LocalStatisticsCounter; //# sourceMappingURL=LocalStatisticsCounter.js.map