From ffb7a521a65b008c0810944a651b6953e1d3a695 Mon Sep 17 00:00:00 2001 From: DenisN Date: Wed, 17 Sep 2025 08:06:12 -0400 Subject: [PATCH] Output formulas API --- src/zvksmetrics/conf/intfrml.json | 1 + src/zvksmetrics/zvksmetrics.controller.ts | 7 +++---- src/zvksmetrics/zvksmetrics.service.ts | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 src/zvksmetrics/conf/intfrml.json diff --git a/src/zvksmetrics/conf/intfrml.json b/src/zvksmetrics/conf/intfrml.json new file mode 100644 index 0000000..50f52f6 --- /dev/null +++ b/src/zvksmetrics/conf/intfrml.json @@ -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))"} \ No newline at end of file diff --git a/src/zvksmetrics/zvksmetrics.controller.ts b/src/zvksmetrics/zvksmetrics.controller.ts index 6e0afae..34a5d1c 100644 --- a/src/zvksmetrics/zvksmetrics.controller.ts +++ b/src/zvksmetrics/zvksmetrics.controller.ts @@ -57,19 +57,18 @@ export class ZvksmetricsController { } //Заглушка для будующей API под интеграционные значения метрик - @Options('integrations/:code') + @Options('formulas/:code') async showIntegrationFormula(@Param('code', ParseIntPipe) code: number): Promise { let ret: JSON = JSON.parse('{"result":"normalek"}'); if (code === 3333) { - return ret; - // return await this.metricsService.showIntegrationMetricsConfig('File Name'); + return await this.metricsService.showFormulas('File Name'); } return ret; } @Post('input') async getPostMessage(@Body() inputMetrics: any): Promise { - console.log(inputMetrics); + // console.log(inputMetrics); let out: any = await this.metricsService.useStatusModel(inputMetrics); return out; diff --git a/src/zvksmetrics/zvksmetrics.service.ts b/src/zvksmetrics/zvksmetrics.service.ts index b656952..106fbd0 100644 --- a/src/zvksmetrics/zvksmetrics.service.ts +++ b/src/zvksmetrics/zvksmetrics.service.ts @@ -448,5 +448,19 @@ export class ZvksmetricsService { return content; } + async showFormulas(filePath: any): Promise { + 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; + } + + };