heath impl
This commit is contained in:
115
src/health/dist/health.controller.js
vendored
Normal file
115
src/health/dist/health.controller.js
vendored
Normal file
@@ -0,0 +1,115 @@
|
||||
"use strict";
|
||||
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
||||
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
||||
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
||||
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
||||
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
||||
};
|
||||
exports.__esModule = true;
|
||||
exports.HealthController = void 0;
|
||||
var common_1 = require("@nestjs/common");
|
||||
var terminus_1 = require("@nestjs/terminus");
|
||||
var swagger_1 = require("@nestjs/swagger");
|
||||
var os = require("os");
|
||||
var HealthController = /** @class */ (function () {
|
||||
function HealthController(health, http, disk, memory, typeOrmHealth, dbPoolStats, configService) {
|
||||
this.health = health;
|
||||
this.http = http;
|
||||
this.disk = disk;
|
||||
this.memory = memory;
|
||||
this.typeOrmHealth = typeOrmHealth;
|
||||
this.dbPoolStats = dbPoolStats;
|
||||
this.configService = configService;
|
||||
// Define o caminho correto para o disco, baseado no sistema operacional
|
||||
this.diskPath = os.platform() === 'win32' ? 'C:\\' : '/';
|
||||
}
|
||||
HealthController.prototype.check = function () {
|
||||
var _this = this;
|
||||
return this.health.check([
|
||||
// Verifica o status da própria aplicação
|
||||
function () { return _this.http.pingCheck('api', 'http://localhost:8066/docs'); },
|
||||
// Verifica espaço em disco (espaço livre < 80%)
|
||||
function () { return _this.disk.checkStorage('disk_percent', {
|
||||
path: _this.diskPath,
|
||||
thresholdPercent: 0.8
|
||||
}); },
|
||||
// Verifica espaço em disco (pelo menos 500MB livres)
|
||||
function () { return _this.disk.checkStorage('disk_space', {
|
||||
path: _this.diskPath,
|
||||
threshold: 500 * 1024 * 1024
|
||||
}); },
|
||||
// Verifica uso de memória (heap <150MB)
|
||||
function () { return _this.memory.checkHeap('memory_heap', 150 * 1024 * 1024); },
|
||||
// Verifica as conexões de banco de dados
|
||||
function () { return _this.typeOrmHealth.checkOracle(); },
|
||||
function () { return _this.typeOrmHealth.checkPostgres(); },
|
||||
]);
|
||||
};
|
||||
HealthController.prototype.checkDatabase = function () {
|
||||
var _this = this;
|
||||
return this.health.check([
|
||||
function () { return _this.typeOrmHealth.checkOracle(); },
|
||||
function () { return _this.typeOrmHealth.checkPostgres(); },
|
||||
]);
|
||||
};
|
||||
HealthController.prototype.checkMemory = function () {
|
||||
var _this = this;
|
||||
return this.health.check([
|
||||
function () { return _this.memory.checkHeap('memory_heap', 150 * 1024 * 1024); },
|
||||
function () { return _this.memory.checkRSS('memory_rss', 300 * 1024 * 1024); },
|
||||
]);
|
||||
};
|
||||
HealthController.prototype.checkDisk = function () {
|
||||
var _this = this;
|
||||
return this.health.check([
|
||||
// Verificar espaço em disco usando porcentagem
|
||||
function () { return _this.disk.checkStorage('disk_percent', {
|
||||
path: _this.diskPath,
|
||||
thresholdPercent: 0.8
|
||||
}); },
|
||||
// Verificar espaço em disco usando valor absoluto
|
||||
function () { return _this.disk.checkStorage('disk_space', {
|
||||
path: _this.diskPath,
|
||||
threshold: 500 * 1024 * 1024
|
||||
}); },
|
||||
]);
|
||||
};
|
||||
HealthController.prototype.checkPoolStats = function () {
|
||||
var _this = this;
|
||||
return this.health.check([
|
||||
function () { return _this.dbPoolStats.checkOraclePoolStats(); },
|
||||
function () { return _this.dbPoolStats.checkPostgresPoolStats(); },
|
||||
]);
|
||||
};
|
||||
__decorate([
|
||||
common_1.Get(),
|
||||
terminus_1.HealthCheck(),
|
||||
swagger_1.ApiOperation({ summary: 'Verificar saúde geral da aplicação' })
|
||||
], HealthController.prototype, "check");
|
||||
__decorate([
|
||||
common_1.Get('db'),
|
||||
terminus_1.HealthCheck(),
|
||||
swagger_1.ApiOperation({ summary: 'Verificar saúde das conexões de banco de dados' })
|
||||
], HealthController.prototype, "checkDatabase");
|
||||
__decorate([
|
||||
common_1.Get('memory'),
|
||||
terminus_1.HealthCheck(),
|
||||
swagger_1.ApiOperation({ summary: 'Verificar uso de memória' })
|
||||
], HealthController.prototype, "checkMemory");
|
||||
__decorate([
|
||||
common_1.Get('disk'),
|
||||
terminus_1.HealthCheck(),
|
||||
swagger_1.ApiOperation({ summary: 'Verificar espaço em disco' })
|
||||
], HealthController.prototype, "checkDisk");
|
||||
__decorate([
|
||||
common_1.Get('pool'),
|
||||
terminus_1.HealthCheck(),
|
||||
swagger_1.ApiOperation({ summary: 'Verificar estatísticas do pool de conexões' })
|
||||
], HealthController.prototype, "checkPoolStats");
|
||||
HealthController = __decorate([
|
||||
swagger_1.ApiTags('Health Check'),
|
||||
common_1.Controller('health')
|
||||
], HealthController);
|
||||
return HealthController;
|
||||
}());
|
||||
exports.HealthController = HealthController;
|
||||
Reference in New Issue
Block a user