Output formulas API

main
DenisN 2025-09-17 08:06:12 -04:00
parent 150534bbba
commit ffb7a521a6
3 changed files with 18 additions and 4 deletions

View File

@ -0,0 +1 @@
{"formula": "100 * (1 - (cpu_load_average_1*0.4+ram_usage*0.4+disk_usage*0.1+disk_read_rate*0.2+disk_write_rate*0.2+network_interface_rx_Eth_1*0.2+network_interface_tx_Eth_1*0.2+network_interface_rx_Eth_2*0.2+network_interface_tx_Eth_2*0.2+network_interface_rx_Eth_3*0.2+network_interface_tx_Eth_3*0.2+network_interface_rx_Eth_4*0.2+network_interface_tx_Eth_4*0.2))"}

View File

@ -57,19 +57,18 @@ export class ZvksmetricsController {
} }
//Заглушка для будующей API под интеграционные значения метрик //Заглушка для будующей API под интеграционные значения метрик
@Options('integrations/:code') @Options('formulas/:code')
async showIntegrationFormula(@Param('code', ParseIntPipe) code: number): Promise<JSON> { async showIntegrationFormula(@Param('code', ParseIntPipe) code: number): Promise<JSON> {
let ret: JSON = JSON.parse('{"result":"normalek"}'); let ret: JSON = JSON.parse('{"result":"normalek"}');
if (code === 3333) { if (code === 3333) {
return ret; return await this.metricsService.showFormulas('File Name');
// return await this.metricsService.showIntegrationMetricsConfig('File Name');
} }
return ret; return ret;
} }
@Post('input') @Post('input')
async getPostMessage(@Body() inputMetrics: any): Promise<string> { async getPostMessage(@Body() inputMetrics: any): Promise<string> {
console.log(inputMetrics); // console.log(inputMetrics);
let out: any = await this.metricsService.useStatusModel(inputMetrics); let out: any = await this.metricsService.useStatusModel(inputMetrics);
return out; return out;

View File

@ -448,5 +448,19 @@ export class ZvksmetricsService {
return content; return content;
} }
async showFormulas(filePath: any): Promise<JSON> {
let content: JSON = JSON.parse('{"name":"name"}');
filePath = process.env.FORMULAS_CONFIG;
try {
content = JSON.parse(await readFile(filePath, { encoding: 'utf8' }));
}
catch {
console.log('Error read file');
}
return content;
}
}; };