Add Integration Metrics
parent
e973ae50da
commit
d3f1924844
|
|
@ -0,0 +1,48 @@
|
|||
[
|
||||
{
|
||||
"id": "90001",
|
||||
"name": "server_li",
|
||||
"values": {
|
||||
"cmplxarr": [
|
||||
"cpu_utilization",
|
||||
"ram_usage",
|
||||
"disk_read_rate",
|
||||
"disk_write_rate",
|
||||
"network_interface_rx_Eth_1",
|
||||
"network_interface_tx_Eth_1",
|
||||
"network_interface_rx_Eth_2",
|
||||
"network_interface_tx_Eth_2",
|
||||
"network_interface_rx_Eth_3",
|
||||
"network_interface_tx_Eth_3",
|
||||
"network_interface_rx_Eth_4",
|
||||
"network_interface_tx_Eth_4"
|
||||
],
|
||||
"warr": [
|
||||
"0.4",
|
||||
"0.3",
|
||||
"0.2",
|
||||
"0.1"
|
||||
]
|
||||
},
|
||||
"formula": "cmplxarr[1]*warr[1]+cmplxarr[2]*warr[2]+(cmplxarr[3]+cmplxarr[4])/2*warr[3]+(cmplxarr[5]+cmplxarr[6]+cmplxarr[7]+cmplxarr[8]+cmplxarr[9]+cmplxarr[10]+cmplxarr[11]+cmplxarr[12])/2*warr[4]"
|
||||
},
|
||||
{
|
||||
"id": "90002",
|
||||
"name": "application_li",
|
||||
"values": {
|
||||
"cmplxarr": [
|
||||
"total_participants",
|
||||
"conferences_active",
|
||||
"registered_abonents",
|
||||
"total_P2P_rooms"
|
||||
],
|
||||
"warr": [
|
||||
"0.4",
|
||||
"0.3",
|
||||
"0.2",
|
||||
"0.1"
|
||||
]
|
||||
},
|
||||
"formula": "cmplxarr[1]*warr[1]+cmplxarr[2]*warr[2]+cmplxarr[3]*warr[3]+cmplxarr[4]*warr[4]"
|
||||
}
|
||||
]
|
||||
File diff suppressed because one or more lines are too long
|
|
@ -46,6 +46,16 @@ export class ZvksmetricsController {
|
|||
return ret;
|
||||
}
|
||||
|
||||
//Заглушка для будующей API под интеграционные значения метрик
|
||||
@Options('integration/:code')
|
||||
async showIntegrationMetrics(@Param('code', ParseIntPipe) code: number): Promise<JSON> {
|
||||
let ret: JSON = JSON.parse('{"result":"null"}');
|
||||
if (code === 7777) {
|
||||
return await this.metricsService.showIntegrationMetricsConfig('File Name');
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Post('input')
|
||||
async getPostMessage(@Body() inputMetrics: any): Promise<string> {
|
||||
// console.log(inputMetrics);
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ export class MetricsRanges {
|
|||
};
|
||||
|
||||
@Injectable()
|
||||
export class ComplexMetricsCalculation {
|
||||
export class MetricsCalculation {
|
||||
id: string;
|
||||
name: string;
|
||||
values: string;
|
||||
|
|
@ -67,18 +67,28 @@ export class ZvksmetricsService {
|
|||
complex.service_name = inp.service_name;
|
||||
complex.metrics = [];
|
||||
|
||||
let model: ComplexMetricsCalculation[] = [];
|
||||
model = await this.setComplexMetrics();
|
||||
let integration: K2Metrics = new K2Metrics();
|
||||
integration.service_name = inp.service_name;
|
||||
integration.metrics = [];
|
||||
|
||||
let scope: MetricsRanges[] = [];
|
||||
scope = await this.setMetricsRanges();
|
||||
|
||||
let model: MetricsCalculation[] = [];
|
||||
model = await this.setComplexMetrics();
|
||||
|
||||
let intgr: MetricsCalculation[] = [];
|
||||
intgr = await this.setIntegrationMetrics();
|
||||
|
||||
if (!prev) {
|
||||
prev = inp;
|
||||
}
|
||||
// console.log(prev);
|
||||
|
||||
let intermediate = await this.getComplexMetricsValues(inp, prev, complex, model, scope);
|
||||
// console.log(intermediate);
|
||||
let integrate = await this.getIntegrationMetricsValues(intermediate, integration, intgr, scope);
|
||||
// console.log(integrate);
|
||||
|
||||
// console.log(intermediate);
|
||||
let ctp: any = classToPlain(intermediate);
|
||||
|
|
@ -97,6 +107,7 @@ export class ZvksmetricsService {
|
|||
// let editedMetrics : K2Metrics = await this.getMetrics (inp, comlexCalc, scope);
|
||||
let responseFromExporter: any = await this.sendMetrics(intermediate);
|
||||
let responseFromExporter1: any = await this.sendMetrics(inp);
|
||||
let responseFromExporter2: any = await this.sendMetrics(integrate);
|
||||
|
||||
prev = inp;
|
||||
|
||||
|
|
@ -128,7 +139,7 @@ export class ZvksmetricsService {
|
|||
// return complexData;
|
||||
// }
|
||||
|
||||
async getComplexMetricsValues(inputData: K2Metrics, prevousData: K2Metrics, complexData: K2Metrics, complexCalc: ComplexMetricsCalculation[], scope: MetricsRanges[]): Promise<K2Metrics> {
|
||||
async getComplexMetricsValues(inputData: K2Metrics, prevousData: K2Metrics, complexData: K2Metrics, complexCalc: MetricsCalculation[], scope: MetricsRanges[]): Promise<K2Metrics> {
|
||||
let length: number = complexCalc.length;
|
||||
let metrics: MetricK2[] = complexData.metrics;
|
||||
|
||||
|
|
@ -173,6 +184,43 @@ export class ZvksmetricsService {
|
|||
return complexData;
|
||||
}
|
||||
|
||||
|
||||
async getIntegrationMetricsValues(complexData: K2Metrics, integrationData: K2Metrics, intgrationCalc: MetricsCalculation[], scope: MetricsRanges[]): Promise<K2Metrics> {
|
||||
let length: number = intgrationCalc.length;
|
||||
let metrics: MetricK2[] = integrationData.metrics;
|
||||
|
||||
let devices: number[] = [18, 19];
|
||||
let device_len: number = devices.length;
|
||||
|
||||
let compare = new EventsService();
|
||||
|
||||
for (let d = 0; d < device_len; d++) {
|
||||
for (let i = 0; i < length; i++) {
|
||||
let metr = { "source": "" };
|
||||
let val = await this.setIntegrationMetricValue(intgrationCalc[i].values, intgrationCalc[i].formula, complexData.metrics, devices[d], metr);
|
||||
if (val != null || val != undefined) {
|
||||
let integrationMetric = new MetricK2();
|
||||
integrationMetric.id = intgrationCalc[i].id;
|
||||
integrationMetric.name = intgrationCalc[i].name;
|
||||
integrationMetric.type = complexData.metrics[0].type;
|
||||
integrationMetric.addr = complexData.metrics[0].addr;
|
||||
integrationMetric.value = val;
|
||||
integrationMetric.description = intgrationCalc[i].name;
|
||||
integrationMetric.status = await this.showStatus(scope, integrationMetric.name, val);
|
||||
integrationMetric.device = devices[d];
|
||||
integrationMetric.source = metr.source;
|
||||
metrics.push(integrationMetric);
|
||||
|
||||
await compare.CompareStatus(integrationMetric);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// console.log(integrationData.metrics);
|
||||
|
||||
return integrationData;
|
||||
}
|
||||
|
||||
async setComplexMetricValue(value: string, formula: string, currMetrics: MetricK2[], prevMetrics: MetricK2[], device: number, obj: any): Promise<any> {
|
||||
const val = JSON.parse(JSON.stringify(value));
|
||||
let arr = val.arr;
|
||||
|
|
@ -212,6 +260,33 @@ export class ZvksmetricsService {
|
|||
}
|
||||
}
|
||||
|
||||
async setIntegrationMetricValue(value: string, formula: string, metrics: MetricK2[], device: number, obj: any): Promise<any> {
|
||||
const val = JSON.parse(JSON.stringify(value));
|
||||
|
||||
// console.log(val.cmplxarr);
|
||||
let arr = val.cmplxarr;
|
||||
|
||||
let arr_len: number = arr.length;
|
||||
obj.source = metrics.find(element => element.name == arr[0] && element.device == device)?.source;
|
||||
|
||||
for (let i = 0; i < arr_len; i++) {
|
||||
let temp = arr[i];
|
||||
arr[i] = metrics.find(element => element.name == arr[i] && element.device == device)?.value;
|
||||
if(arr[i]==undefined || arr[i]==null || Number.isNaN(arr[i])){
|
||||
arr[i]=Math.random()*10;
|
||||
}
|
||||
// console.log(arr[i]);
|
||||
}
|
||||
|
||||
try {
|
||||
let result: number = evaluate(formula, val);
|
||||
// console.log(result);
|
||||
return result;
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async setMetricsStatus(metric: MetricK2, scope: MetricsRanges[]): Promise<number> {
|
||||
if (metric && scope) {
|
||||
return await this.showStatus(scope, metric.name, metric.value);
|
||||
|
|
@ -287,7 +362,7 @@ export class ZvksmetricsService {
|
|||
return ret;
|
||||
}
|
||||
|
||||
async setComplexMetrics(@Body() complexData: any = null): Promise<ComplexMetricsCalculation[]> {
|
||||
async setComplexMetrics(@Body() complexData: any = null): Promise<MetricsCalculation[]> {
|
||||
let url: string = 'http://192.168.2.39:9999/api/complex/5555';
|
||||
let options: any = {
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
|
|
@ -315,6 +390,21 @@ export class ZvksmetricsService {
|
|||
return content;
|
||||
}
|
||||
|
||||
async setIntegrationMetrics(@Body() integrationData: any = null): Promise<MetricsCalculation[]> {
|
||||
let url: string = 'http://192.168.2.39:9999/api/integration/7777';
|
||||
let options: any = {
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
};
|
||||
|
||||
await axios.options(url, options).then((response) => {
|
||||
integrationData = response.data;
|
||||
}).catch((error) => {
|
||||
integrationData = error;
|
||||
});
|
||||
// console.log(rangesData);
|
||||
return integrationData;
|
||||
}
|
||||
|
||||
async showComplexMetricsConfig(filePath: string): Promise<JSON> {
|
||||
let content: JSON = JSON.parse('{"name":"name"}');
|
||||
filePath = './src/zvksmetrics/conf/complex.json';
|
||||
|
|
@ -328,5 +418,18 @@ export class ZvksmetricsService {
|
|||
return content;
|
||||
}
|
||||
|
||||
async showIntegrationMetricsConfig(filePath: string): Promise<JSON> {
|
||||
let content: JSON = JSON.parse('{"name":"name"}');
|
||||
filePath = './src/zvksmetrics/conf/integration.json';
|
||||
try {
|
||||
content = JSON.parse(await readFile(filePath, { encoding: 'utf8' }));
|
||||
}
|
||||
catch {
|
||||
console.log('Error read file');
|
||||
}
|
||||
|
||||
return content;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue