Compare commits

..

10 Commits

Author SHA1 Message Date
DenisN 1a622c140d Run Click house ... test 1 2025-09-19 09:39:25 -04:00
DenisN ffb7a521a6 Output formulas API 2025-09-17 08:06:12 -04:00
DenisN 150534bbba Var Change 2025-09-11 05:21:27 -04:00
DenisN 6cae690c05 Russian names 2025-08-26 03:22:40 -04:00
DenisN 896c54be03 Add integration & complex label 2025-08-21 04:17:13 -04:00
DenisN 6aec5760ca New Pasword 2025-08-08 05:05:14 -04:00
DenisN cd314efc6a DB add 2025-08-08 04:16:54 -04:00
DenisN ae9e5d3caa Add Env local 2025-08-08 03:48:54 -04:00
DenisN 76ce60060f New integration vtnhbr 2025-08-06 10:13:49 -04:00
DenisN d3f1924844 Add Integration Metrics 2025-07-29 08:33:38 -04:00
9 changed files with 1781 additions and 133 deletions

View File

@ -8,6 +8,8 @@ import { ConfigModule } from '@nestjs/config';
import { StatusModule } from './status/status.module'; import { StatusModule } from './status/status.module';
import { EventsModule } from './events/events.module'; import { EventsModule } from './events/events.module';
@Module({ @Module({
imports: [ZvksmetricsModule, GruberModule, DatabaseModule, ConfigModule.forRoot({ imports: [ZvksmetricsModule, GruberModule, DatabaseModule, ConfigModule.forRoot({
isGlobal: true, isGlobal: true,
@ -17,3 +19,6 @@ import { EventsModule } from './events/events.module';
providers: [AppService], providers: [AppService],
}) })
export class AppModule {} export class AppModule {}
ConfigModule.forRoot();

View File

@ -6,14 +6,14 @@ import { isInternalThread } from 'node:worker_threads';
export class ClickhouseService { export class ClickhouseService {
async ClickHouseConnect(): Promise<ClickHouse>{ async ClickHouseConnect(): Promise<ClickHouse>{
let connectionData = new ClickHouse({ let connectionData = new ClickHouse({
url: 'http://192.168.2.37', // url: 'http://192.168.2.37',
port: 8123, url: process.env.DATABASE_URL,
// url: DATABASE_NAME, port: process.env.DATABASE_PORT,
// PORT: DATABASE_PORT, // port: 8123,
debug: false, debug: false,
basicAuth: { basicAuth: {
username: 'root', username: process.env.DATABASE_USER,
password: 'dbss', password: process.env.USER_PASSWORD,
}, },
isUseGzip: false, isUseGzip: false,
trimQuery: false, trimQuery: false,
@ -40,25 +40,7 @@ export class ClickhouseService {
async ClickHouseDBsCreate(): Promise<ClickHouse> { async ClickHouseDBsCreate(): Promise<ClickHouse> {
let connectionData = await this.ClickHouseConnect(); let connectionData = await this.ClickHouseConnect();
try {
// let queries = [
// 'DROP TABLE IF EXISTS session_temp',
// `CREATE TABLE IF NOT EXISTS session_temp (
// id UInt128,
// body TEXT,
// ips Array(UInt32),
// ueries Nested (
// id UInt32,
// act String,
// uptime DateTime64
// ),
// create_date DateTime64,
// update_time DateTime64,
// ) ENGINE = MergeTree()
// PRIMARY KEY (id)`
// ];
let queries = [ let queries = [
`CREATE TABLE IF NOT EXISTS raw_parameters ( `CREATE TABLE IF NOT EXISTS raw_parameters (
EventDataTime DateTime64, EventDataTime DateTime64,
@ -132,53 +114,68 @@ export class ClickhouseService {
} }
// console.log(connectionData); // console.log(connectionData);
return connectionData; return connectionData;}
catch (e) {
return e;
}
} }
async ClickHouseAddRecords(recordFormat: string, parameterBody: any): Promise<any>{ async ClickHouseAddRecords(recordFormat: string, parameterBody: any): Promise<any>{
let connectionData = await this.ClickHouseDBsCreate(); let connectionData = await this.ClickHouseDBsCreate();
switch(recordFormat){ try {
case 'raw': switch(recordFormat){
let insertRawQuery = 'INSERT INTO raw_parameters VALUES(toDateTime(now()), \'{{parameterBody}}\', toDateTime(now()));'; case 'raw':
// console.log(insertQuery); let insertRawQuery = 'INSERT INTO raw_parameters VALUES(toDateTime(now()), \'{{parameterBody}}\', toDateTime(now()));';
insertRawQuery = insertRawQuery.replace('{{parameterBody}}', parameterBody); // console.log(insertQuery);
// console.log(insertRawQuery); insertRawQuery = insertRawQuery.replace('{{parameterBody}}', parameterBody);
// for (let query of insertQuery) { // console.log(insertRawQuery);
try{ // for (let query of insertQuery) {
let retRaw = await connectionData.query(insertRawQuery).toPromise(); try{
} let retRaw = await connectionData.query(insertRawQuery).toPromise();
catch{ console.log(retRaw);
console.log(insertRawQuery); }
} catch{
// console.log(retRaw); console.log(insertRawQuery);
// } }
break; // console.log(retRaw);
case 'complex': // }
let insertComplexQuery = 'INSERT INTO complex_parameters VALUES(toDateTime(now()), \'{{parameterBody}}\', toDateTime(now()));'; break;
// console.log(insertQuery); case 'complex':
insertComplexQuery = insertComplexQuery.replace('{{parameterBody}}', parameterBody); let insertComplexQuery = 'INSERT INTO complex_parameters VALUES(toDateTime(now()), \'{{parameterBody}}\', toDateTime(now()));';
// console.log(insertComplexQuery); // console.log(insertQuery);
// for (let query of insertQuery) { insertComplexQuery = insertComplexQuery.replace('{{parameterBody}}', parameterBody);
let retComplex = await connectionData.query(insertComplexQuery).toPromise(); // console.log(insertComplexQuery);
// console.log(retComplex); // for (let query of insertQuery) {
// } let retComplex = await connectionData.query(insertComplexQuery).toPromise();
break; // console.log(retComplex);
// }
break;
}
return 1;
} }
return 1; catch {
return 0;
}
} }
async ClickHouseAddEvents(parameterID: string, parameterName: string, parameterValue: string, parameterBody: string, previousStatus: string, currentStatus: string): Promise<any>{ async ClickHouseAddEvents(parameterID: string, parameterName: string, parameterValue: string, parameterBody: string, previousStatus: string, currentStatus: string): Promise<any>{
let connectionData = await this.ClickHouseDBsCreate(); let connectionData = await this.ClickHouseDBsCreate();
let insertEventQuery = 'INSERT INTO status_events VALUES(toDateTime(now()), {{parameterID}}, \'{{parameterName}}\', {{parameterValue}}, \'{{parameterBody}}\', {{previousStatus}}, {{currentStatus}}, toDateTime(now()));'; try {
insertEventQuery = insertEventQuery.replace('{{parameterID}}', parameterID); let insertEventQuery = 'INSERT INTO status_events VALUES(toDateTime(now()), {{parameterID}}, \'{{parameterName}}\', {{parameterValue}}, \'{{parameterBody}}\', {{previousStatus}}, {{currentStatus}}, toDateTime(now()));';
insertEventQuery = insertEventQuery.replace('{{parameterName}}', parameterName); insertEventQuery = insertEventQuery.replace('{{parameterID}}', parameterID);
insertEventQuery = insertEventQuery.replace('{{parameterValue}}', parameterValue); insertEventQuery = insertEventQuery.replace('{{parameterName}}', parameterName);
insertEventQuery = insertEventQuery.replace('{{parameterBody}}', parameterBody); insertEventQuery = insertEventQuery.replace('{{parameterValue}}', parameterValue);
insertEventQuery = insertEventQuery.replace('{{previousStatus}}', previousStatus); insertEventQuery = insertEventQuery.replace('{{parameterBody}}', parameterBody);
insertEventQuery = insertEventQuery.replace('{{currentStatus}}', currentStatus); insertEventQuery = insertEventQuery.replace('{{previousStatus}}', previousStatus);
let retEvent = await connectionData.query(insertEventQuery).toPromise(); insertEventQuery = insertEventQuery.replace('{{currentStatus}}', currentStatus);
// console.log(retEvent); let retEvent = await connectionData.query(insertEventQuery).toPromise();
return 1; // console.log(retEvent);
return 1;
}
catch {
return 0;
}
} }
} }

View File

@ -1,5 +1,6 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { ConfigService } from '@nestjs/config';
async function bootstrap() { async function bootstrap() {
const app = await NestFactory.create(AppModule); const app = await NestFactory.create(AppModule);

View File

@ -2,259 +2,583 @@
{ {
"id": "10001", "id": "10001",
"name": "cpu_utilization", "name": "cpu_utilization",
"values": {"arr":["cpurawidle", "cpurawuser", "cpurawnice", "cpurawsystem", "cpurawwait", "cpurawinterrupt"],"prevarr":["cpurawidle", "cpurawuser", "cpurawnice", "cpurawsystem", "cpurawwait", "cpurawinterrupt"]}, "desription": "Загруженность центрального процессора",
"values": {
"arr": [
"cpurawidle",
"cpurawuser",
"cpurawnice",
"cpurawsystem",
"cpurawwait",
"cpurawinterrupt"
],
"prevarr": [
"cpurawidle",
"cpurawuser",
"cpurawnice",
"cpurawsystem",
"cpurawwait",
"cpurawinterrupt"
]
},
"formula": "((arr[2]-prevarr[2])+(arr[3]-prevarr[3])+(arr[4]-prevarr[4])+(arr[6]-prevarr[6]))/((arr[1]-prevarr[1])+(arr[2]-prevarr[2])+(arr[3]-prevarr[3])+(arr[4]-prevarr[4])+(arr[5]-prevarr[5])+(arr[6]-prevarr[6]))*100" "formula": "((arr[2]-prevarr[2])+(arr[3]-prevarr[3])+(arr[4]-prevarr[4])+(arr[6]-prevarr[6]))/((arr[1]-prevarr[1])+(arr[2]-prevarr[2])+(arr[3]-prevarr[3])+(arr[4]-prevarr[4])+(arr[5]-prevarr[5])+(arr[6]-prevarr[6]))*100"
}, },
{ {
"id": "10002", "id": "10002",
"name": "cpu_load_average_1", "name": "cpu_load_average_1",
"values": {"arr":["cpu1min"]}, "desription": "Средняя загруженность центрального процессора в периоде 1-ой минуты",
"values": {
"arr": [
"cpu1min"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10003", "id": "10003",
"name": "cpu_load_average_5", "name": "cpu_load_average_5",
"values": {"arr":["cpu5min"]}, "desription": "Средняя загруженность центрального процессора в периоде 5-и минут",
"values": {
"arr": [
"cpu5min"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10004", "id": "10004",
"name": "cpu_load_average_15", "name": "cpu_load_average_15",
"values": {"arr":["cpu15min"]}, "desription": "Средняя загруженность центрального процессора в периоде 15-и минут",
"values": {
"arr": [
"cpu15min"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10005", "id": "10005",
"name": "ram_usage", "name": "ram_usage",
"values": {"arr":["totalMemory", "totalMemoryAvail"]}, "desription": "Объем использования оперативной памяти",
"values": {
"arr": [
"totalMemory",
"totalMemoryAvail"
]
},
"formula": "(arr[1]-arr[2])/arr[1]*100" "formula": "(arr[1]-arr[2])/arr[1]*100"
}, },
{ {
"id": "10006", "id": "10006",
"name": "disk_usage", "name": "disk_usage",
"values": {"arr":["totalDiskSize", "useDiskSize"]}, "desription": "Объем использования ресурсов области хранения данных",
"values": {
"arr": [
"totalDiskSize",
"useDiskSize"
]
},
"formula": "(arr[1]-arr[2])/arr[1]*100" "formula": "(arr[1]-arr[2])/arr[1]*100"
}, },
{ {
"id": "10007", "id": "10007",
"name": "disk_read_rate", "name": "disk_read_rate",
"values": {"arr":["diskReadAccess"], "prevarr":["diskReadAccess"]}, "desription": "Скорость чтения из области хранения данных",
"values": {
"arr": [
"diskReadAccess"
],
"prevarr": [
"diskReadAccess"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10008", "id": "10008",
"name": "disk_write_rate", "name": "disk_write_rate",
"values": {"arr":["diskWriteAccess"], "prevarr":["diskWriteAccess"]}, "desription": "Скорость записи в область хранения данных",
"values": {
"arr": [
"diskWriteAccess"
],
"prevarr": [
"diskWriteAccess"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10009", "id": "10009",
"name": "network_interface_rx_Eth_1", "name": "network_interface_rx_Eth_1",
"values": {"arr":["speed1", "ifInOctets1"], "prevarr":["speed1", "ifInOctets1"]}, "desription": "Скорость приема данных интерфейса Eth1",
"values": {
"arr": [
"speed1",
"ifInOctets1"
],
"prevarr": [
"speed1",
"ifInOctets1"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10010", "id": "10010",
"name": "network_interface_tx_Eth_1", "name": "network_interface_tx_Eth_1",
"values": {"arr":["speed1", "ifOutOctets1"], "prevarr":["speed1", "ifOutOctets1"]}, "desription": "Скорость передачи данных интерфейса Eth1",
"values": {
"arr": [
"speed1",
"ifOutOctets1"
],
"prevarr": [
"speed1",
"ifOutOctets1"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10011", "id": "10011",
"name": "network_interface_rx_Eth_2", "name": "network_interface_rx_Eth_2",
"values": {"arr":["speed2", "ifInOctets2"], "prevarr":["speed2", "ifInOctets2"]}, "desription": "Скорость приема данных интерфейса Eth2",
"values": {
"arr": [
"speed2",
"ifInOctets2"
],
"prevarr": [
"speed2",
"ifInOctets2"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10012", "id": "10012",
"name": "network_interface_tx_Eth_2", "name": "network_interface_tx_Eth_2",
"values": {"arr":["speed2", "ifOutOctets2"], "prevarr":["speed2", "ifOutOctets2"]}, "desription": "Скорость передачи данных интерфейса Eth2",
"values": {
"arr": [
"speed2",
"ifOutOctets2"
],
"prevarr": [
"speed2",
"ifOutOctets2"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10013", "id": "10013",
"name": "network_interface_rx_Eth_3", "name": "network_interface_rx_Eth_3",
"values": {"arr":["speed3", "ifInOctets3"], "prevarr":["speed3", "ifInOctets3"]}, "desription": "Скорость приема данных интерфейса Eth3",
"values": {
"arr": [
"speed3",
"ifInOctets3"
],
"prevarr": [
"speed3",
"ifInOctets3"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10014", "id": "10014",
"name": "network_interface_tx_Eth_3", "name": "network_interface_tx_Eth_3",
"values": {"arr":["speed3", "ifOutOctets3"], "prevarr":["speed3", "ifOutOctets3"]}, "desription": "Скорость передачи данных интерфейса Eth3",
"values": {
"arr": [
"speed3",
"ifOutOctets3"
],
"prevarr": [
"speed3",
"ifOutOctets3"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10015", "id": "10015",
"name": "network_interface_rx_Eth_4", "name": "network_interface_rx_Eth_4",
"values": {"arr":["speed4", "ifInOctets4"], "prevarr":["speed4", "ifInOctets4"]}, "desription": "Скорость приема данных интерфейса Eth4",
"values": {
"arr": [
"speed4",
"ifInOctets4"
],
"prevarr": [
"speed4",
"ifInOctets4"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10016", "id": "10016",
"name": "network_interface_tx_Eth_4", "name": "network_interface_tx_Eth_4",
"values": {"arr":["speed4", "ifOutOctets4"], "prevarr":["speed4", "ifOutOctets4"]}, "desription": "Скорость передачи данных интерфейса Eth4",
"values": {
"arr": [
"speed4",
"ifOutOctets4"
],
"prevarr": [
"speed4",
"ifOutOctets4"
]
},
"formula": "(arr[2]-prevarr[2])/arr[1]*100" "formula": "(arr[2]-prevarr[2])/arr[1]*100"
}, },
{ {
"id": "10017", "id": "10017",
"name": "network_interfaces_read_packets_errors_Eth_1", "name": "network_interfaces_read_packets_errors_Eth_1",
"values": {"arr":["ifInErrors1"], "prevarr":["ifInErrors1"]}, "desription": "Количество ошибок при чтении пакетов на интерфейсе Eth1",
"values": {
"arr": [
"ifInErrors1"
],
"prevarr": [
"ifInErrors1"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10018", "id": "10018",
"name": "network_interfaces_write_packets_errors_Eth_1", "name": "network_interfaces_write_packets_errors_Eth_1",
"values": {"arr":["ifOutErrors1"], "prevarr":["ifOutErrors1"]}, "desription": "Количество ошибок при отправки пакетов на интерфейсе Eth1",
"values": {
"arr": [
"ifOutErrors1"
],
"prevarr": [
"ifOutErrors1"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10019", "id": "10019",
"name": "network_interfaces_read_packets_errors_Eth_2", "name": "network_interfaces_read_packets_errors_Eth_2",
"values": {"arr":["ifInErrors2"], "prevarr":["ifInErrors2"]}, "desription": "Количество ошибок при чтении пакетов на интерфейсе Eth2",
"values": {
"arr": [
"ifInErrors2"
],
"prevarr": [
"ifInErrors2"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10020", "id": "10020",
"name": "network_interfaces_write_packets_errors_Eth_2", "name": "network_interfaces_write_packets_errors_Eth_2",
"values": {"arr":["ifOutErrors2"], "prevarr":["ifOutErrors2"]}, "desription": "Количество ошибок при отправки пакетов на интерфейсе Eth2",
"values": {
"arr": [
"ifOutErrors2"
],
"prevarr": [
"ifOutErrors2"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10021", "id": "10021",
"name": "network_interfaces_read_packets_errors_Eth_3", "name": "network_interfaces_read_packets_errors_Eth_3",
"values": {"arr":["ifInErrors3"], "prevarr":["ifInErrors3"]}, "desription": "Количество ошибок при чтении пакетов на интерфейсе Eth3",
"values": {
"arr": [
"ifInErrors3"
],
"prevarr": [
"ifInErrors3"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10022", "id": "10022",
"name": "network_interfaces_write_packets_errors_Eth_3", "name": "network_interfaces_write_packets_errors_Eth_3",
"values": {"arr":["ifOutErrors3"], "prevarr":["ifOutErrors3"]}, "desription": "Количество ошибок при отправки пакетов на интерфейсе Eth3",
"values": {
"arr": [
"ifOutErrors3"
],
"prevarr": [
"ifOutErrors3"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10023", "id": "10023",
"name": "network_interfaces_read_packets_errors_Eth_4", "name": "network_interfaces_read_packets_errors_Eth_4",
"values": {"arr":["ifInErrors4"], "prevarr":["ifInErrors4"]}, "desription": "Количество ошибок при чтении пакетов на интерфейсе Eth4",
"values": {
"arr": [
"ifInErrors4"
],
"prevarr": [
"ifInErrors4"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10024", "id": "10024",
"name": "network_interfaces_write_packets_errors_Eth_4", "name": "network_interfaces_write_packets_errors_Eth_4",
"values": {"arr":["ifOutErrors4"], "prevarr":["ifOutErrors4"]}, "desription": "Количество ошибок при отправки пакетов на интерфейсе Eth4",
"values": {
"arr": [
"ifOutErrors4"
],
"prevarr": [
"ifOutErrors4"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10025", "id": "10025",
"name": "network_interfaces_read_packets_discarded_Eth_1", "name": "network_interfaces_read_packets_discarded_Eth_1",
"values": {"arr":["ifInDiscard1"], "prevarr":["ifInDiscard1"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth1 при отправки данных",
"values": {
"arr": [
"ifInDiscard1"
],
"prevarr": [
"ifInDiscard1"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10026", "id": "10026",
"name": "network_interfaces_write_packets_discarded_Eth_1", "name": "network_interfaces_write_packets_discarded_Eth_1",
"values": {"arr":["ifOutDiscard1"], "prevarr":["ifOutDiscard1"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth1 при получении данных",
"values": {
"arr": [
"ifOutDiscard1"
],
"prevarr": [
"ifOutDiscard1"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10027", "id": "10027",
"name": "network_interfaces_read_packets_discarded_Eth_2", "name": "network_interfaces_read_packets_discarded_Eth_2",
"values": {"arr":["ifInDiscard2"], "prevarr":["ifInDiscard2"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth2 при отправки данных",
"values": {
"arr": [
"ifInDiscard2"
],
"prevarr": [
"ifInDiscard2"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10028", "id": "10028",
"name": "network_interfaces_write_packets_discarded_Eth_2", "name": "network_interfaces_write_packets_discarded_Eth_2",
"values": {"arr":["ifOutDiscard2"], "prevarr":["ifOutDiscard2"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth1 при получении данных",
"values": {
"arr": [
"ifOutDiscard2"
],
"prevarr": [
"ifOutDiscard2"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10029", "id": "10029",
"name": "network_interfaces_read_packets_discarded_Eth_3", "name": "network_interfaces_read_packets_discarded_Eth_3",
"values": {"arr":["ifInDiscard3"], "prevarr":["ifInDiscard3"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth3 при отправки данных",
"values": {
"arr": [
"ifInDiscard3"
],
"prevarr": [
"ifInDiscard3"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10030", "id": "10030",
"name": "network_interfaces_write_packets_discarded_Eth_3", "name": "network_interfaces_write_packets_discarded_Eth_3",
"values": {"arr":["ifOutDiscard3"], "prevarr":["ifOutDiscard3"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth3 при получении данных",
"values": {
"arr": [
"ifOutDiscard3"
],
"prevarr": [
"ifOutDiscard3"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10031", "id": "10031",
"name": "network_interfaces_read_packets_discarded_Eth_4", "name": "network_interfaces_read_packets_discarded_Eth_4",
"values": {"arr":["ifInDiscard4"], "prevarr":["ifInDiscard4"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth4 при отправки данных",
"values": {
"arr": [
"ifInDiscard4"
],
"prevarr": [
"ifInDiscard4"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10032", "id": "10032",
"name": "network_interfaces_write_packets_discarded_Eth_4", "name": "network_interfaces_write_packets_discarded_Eth_4",
"values": {"arr":["ifOutDiscard4"], "prevarr":["ifOutDiscard4"]}, "desription": "Количество не обработанных пакетов на интерфейсе Eth4 при получении данных",
"values": {
"arr": [
"ifOutDiscard4"
],
"prevarr": [
"ifOutDiscard4"
]
},
"formula": "(arr[1]-prevarr[1])" "formula": "(arr[1]-prevarr[1])"
}, },
{ {
"id": "10033", "id": "10033",
"name": "response_icmp", "name": "response_icmp",
"values": {"arr":["ping_check"]}, "desription": "Количество полученных ответов по протоколу ICMP",
"values": {
"arr": [
"ping_check"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10034", "id": "10034",
"name": "server_uptime", "name": "server_uptime",
"values": {"arr":["upTime"]}, "desription": "Текущее время безотказной работы сервера",
"values": {
"arr": [
"upTime"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10035", "id": "10035",
"name": "total_participants", "name": "total_participants",
"values": {"arr":["TotalParticipants"]}, "desription": "Текущее количество участников конференции",
"values": {
"arr": [
"TotalParticipants"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10036", "id": "10036",
"name": "registered_abonents", "name": "registered_abonents",
"values": {"arr":["RegisteredAbonents"]}, "desription": "Текущее количество зарегистрированных пользователей",
"values": {
"arr": [
"RegisteredAbonents"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10037", "id": "10037",
"name": "webcasts_HLS_clients", "name": "webcasts_HLS_clients",
"values": {"arr":["WebcastsHLSclients"]}, "desription": "Текущее количество клиентов, участвувающих в HLS WEB-трансляции ",
"values": {
"arr": [
"WebcastsHLSclients"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10038", "id": "10038",
"name": "total_P2P_rooms", "name": "total_P2P_rooms",
"values": {"arr":["TotalP2Prooms"]}, "desription": "Общее количество P2P зон общения",
"values": {
"arr": [
"TotalP2Prooms"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10039", "id": "10039",
"name": "conferences_total", "name": "conferences_total",
"values": {"arr":["Conferencestotal"]}, "desription": "Общее количество зарегистрированных конференций",
"values": {
"arr": [
"Conferencestotal"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10040", "id": "10040",
"name": "conferences_active", "name": "conferences_active",
"values": {"arr":["ConferencesActive"]}, "desription": "Общее количество текущих активных конференций",
"values": {
"arr": [
"ConferencesActive"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10041", "id": "10041",
"name": "records_active", "name": "records_active",
"values": {"arr":["RecordsActive"]}, "desription": "Текущее количество ведущихся записей",
"values": {
"arr": [
"RecordsActive"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10042", "id": "10042",
"name": "number_of_records_saved", "name": "number_of_records_saved",
"values": {"arr":["NumberRecordsSaved"]}, "desription": "Общее количество записанных записей",
"values": {
"arr": [
"NumberRecordsSaved"
]
},
"formula": "arr[1]" "formula": "arr[1]"
}, },
{ {
"id": "10043", "id": "10043",
"name": "replication_status", "name": "replication_status",
"values": {"arr":["replicationStatus"]}, "desription": "Статус репликации данных",
"values": {
"arr": [
"replicationStatus"
]
},
"formula": "arr[1]" "formula": "arr[1]"
} }
] ]

View File

@ -0,0 +1,51 @@
[
{
"id": "90001",
"name": "server_li",
"desription": "Индекс загрузки сервера - Server Load Index",
"values": {
"statusarr": [
"cpu_load_average_1",
"ram_usage",
"disk_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": "100 * (1 - (statusarr[1]*warr[1]+statusarr[2]*warr[1]+statusarr[3]*warr[4]+statusarr[4]*warr[3]+statusarr[4]*warr[3]+statusarr[5]*warr[3]+statusarr[6]*warr[3]+statusarr[7]*warr[3]+statusarr[8]*warr[3]+statusarr[9]*warr[3]+statusarr[10]*warr[3]+statusarr[11]*warr[3]+statusarr[12]*warr[3]+statusarr[13]*warr[3])/(warr[1]+warr[1]+warr[4]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]+warr[3]))"
},
{
"id": "90002",
"name": "application_li",
"desription": "Индекс нагрузки приложения - Application Load Index",
"values": {
"statusarr": [
"total_participants",
"conferences_active",
"registered_abonents",
"total_P2P_rooms"
],
"warr": [
"0.4",
"0.3",
"0.2",
"0.1"
]
},
"formula": "100 * (1 - (statusarr[1]*warr[1]+statusarr[2]*warr[2]+statusarr[3]*warr[4]+statusarr[4]*warr[3]+statusarr[4]*warr[3])/(warr[1]+warr[2]+warr[4]+warr[4]))"
}
]

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))"}

File diff suppressed because one or more lines are too long

View File

@ -46,6 +46,35 @@ export class ZvksmetricsController {
return ret; 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;
}
//Заглушка для будующей API под интеграционные значения метрик
@Options('formulas/:code')
async showIntegrationFormula(@Param('code', ParseIntPipe) code: number): Promise<JSON> {
let ret: JSON = JSON.parse('{"result":"normalek"}');
if (code === 3333) {
return await this.metricsService.showFormulas('File Name');
}
return ret;
}
@Post('formulas/:code')
async setFormulas(@Body() inputFormulas: any, @Param('code', ParseIntPipe) code: number): Promise<string> {
let ret: string = "Controller Error";
if (code === 1111) {
return await this.metricsService.saveFormulas(inputFormulas);
}
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);

View File

@ -1,3 +1,4 @@
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Body, Injectable } from '@nestjs/common'; import { Body, Injectable } from '@nestjs/common';
import axios, { Axios, AxiosResponse } from 'axios'; import axios, { Axios, AxiosResponse } from 'axios';
import { readFile, writeFile } from 'node:fs/promises'; import { readFile, writeFile } from 'node:fs/promises';
@ -46,9 +47,10 @@ export class MetricsRanges {
}; };
@Injectable() @Injectable()
export class ComplexMetricsCalculation { export class MetricsCalculation {
id: string; id: string;
name: string; name: string;
desription: string;
values: string; values: string;
formula: string; formula: string;
}; };
@ -67,18 +69,28 @@ export class ZvksmetricsService {
complex.service_name = inp.service_name; complex.service_name = inp.service_name;
complex.metrics = []; complex.metrics = [];
let model: ComplexMetricsCalculation[] = []; let integration: K2Metrics = new K2Metrics();
model = await this.setComplexMetrics(); integration.service_name = inp.service_name;
integration.metrics = [];
let scope: MetricsRanges[] = []; let scope: MetricsRanges[] = [];
scope = await this.setMetricsRanges(); scope = await this.setMetricsRanges();
let model: MetricsCalculation[] = [];
model = await this.setComplexMetrics();
let intgr: MetricsCalculation[] = [];
intgr = await this.setIntegrationMetrics();
if (!prev) { if (!prev) {
prev = inp; prev = inp;
} }
// console.log(prev); // console.log(prev);
let intermediate = await this.getComplexMetricsValues(inp, prev, complex, model, scope); 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); // console.log(intermediate);
let ctp: any = classToPlain(intermediate); let ctp: any = classToPlain(intermediate);
@ -97,7 +109,8 @@ export class ZvksmetricsService {
// let editedMetrics : K2Metrics = await this.getMetrics (inp, comlexCalc, scope); // let editedMetrics : K2Metrics = await this.getMetrics (inp, comlexCalc, scope);
let responseFromExporter: any = await this.sendMetrics(intermediate); let responseFromExporter: any = await this.sendMetrics(intermediate);
let responseFromExporter1: any = await this.sendMetrics(inp); let responseFromExporter1: any = await this.sendMetrics(inp);
let responseFromExporter2: any = await this.sendMetrics(integrate);
console.log(responseFromExporter2);
prev = inp; prev = inp;
return responseFromExporter; return responseFromExporter;
@ -128,7 +141,7 @@ export class ZvksmetricsService {
// return complexData; // 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 length: number = complexCalc.length;
let metrics: MetricK2[] = complexData.metrics; let metrics: MetricK2[] = complexData.metrics;
@ -139,11 +152,11 @@ export class ZvksmetricsService {
// const jsonData = require('../conf/devices.json'); // const jsonData = require('../conf/devices.json');
// console.log(jsonData); // console.log(jsonData);
let uptimeElements = inputData.metrics.filter(element=> element.name == 'upTime'); let uptimeElements = inputData.metrics.filter(element => element.name == 'upTime');
if(uptimeElements){ if (uptimeElements) {
for(let uptime of uptimeElements){ for (let uptime of uptimeElements) {
let uptStr: any = uptime?.value.toString().split(' '); let uptStr: any = uptime?.value.toString().split(' ');
uptime.value = (+uptStr[0])*3600+(uptStr[2])*60+(+uptStr[4]); uptime.value = (+uptStr[0]) * 3600 + (uptStr[2]) * 60 + (+uptStr[4]);
} }
} }
for (let d = 0; d < device_len; d++) { for (let d = 0; d < device_len; d++) {
@ -157,10 +170,10 @@ export class ZvksmetricsService {
complexMetric.type = inputData.metrics[0].type; complexMetric.type = inputData.metrics[0].type;
complexMetric.addr = inputData.metrics[0].addr; complexMetric.addr = inputData.metrics[0].addr;
complexMetric.value = val; complexMetric.value = val;
complexMetric.description = complexCalc[i].name; complexMetric.description = complexCalc[i].desription;
complexMetric.status = await this.showStatus(scope, complexMetric.name, val); complexMetric.status = await this.showStatus(scope, complexMetric.name, val);
complexMetric.device = devices[d]; complexMetric.device = devices[d];
complexMetric.source = metr.source; complexMetric.source = metr.source + ', complex';
metrics.push(complexMetric); metrics.push(complexMetric);
await compare.CompareStatus(complexMetric); await compare.CompareStatus(complexMetric);
@ -173,6 +186,43 @@ export class ZvksmetricsService {
return complexData; 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, intgrationCalc[i].name, 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].desription;
integrationMetric.status = await this.showStatus(scope, integrationMetric.name, val);
integrationMetric.device = devices[d];
integrationMetric.source = metr.source.replace(', complex', ', integration');
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> { async setComplexMetricValue(value: string, formula: string, currMetrics: MetricK2[], prevMetrics: MetricK2[], device: number, obj: any): Promise<any> {
const val = JSON.parse(JSON.stringify(value)); const val = JSON.parse(JSON.stringify(value));
let arr = val.arr; let arr = val.arr;
@ -186,10 +236,10 @@ export class ZvksmetricsService {
let temp = arr[i]; let temp = arr[i];
arr[i] = currMetrics.find(element => element.name == arr[i] && element.device == device)?.value; arr[i] = currMetrics.find(element => element.name == arr[i] && element.device == device)?.value;
// if(!arr[i]){ if (!arr[i]) {
// console.log(arr[i], temp, device); // console.log(arr[i], temp, device);
// arr[i]=0; arr[i] = 0;
// } }
} }
let prevarr = val.prevarr; let prevarr = val.prevarr;
if (prevarr) { if (prevarr) {
@ -206,7 +256,49 @@ export class ZvksmetricsService {
let result: number = evaluate(formula, val); let result: number = evaluate(formula, val);
// console.log(result); // console.log(result);
return result; return result;
// console.log(result); } catch {
return null;
}
}
async setIntegrationMetricValue(value: string, formula: string, metricName: string, metrics: MetricK2[], device: number, obj: any): Promise<any> {
const val = JSON.parse(JSON.stringify(value));
let arr = val.statusarr;
let arr_len: number = 13; //arr.length;
// console.log (metricName);
if (metricName == "application_li") {
arr = val.statusarr;
arr_len = 4;
}
// console.log(arr);
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];
// if(metricName == "server_li"){
arr[i] = metrics.find(element => element.name == arr[i] && element.device == device)?.status;
if (arr[i] != 0) {
arr[i]--;
}
// console.log(arr[i]);
// }
// if(metricName == "application_li"){
// arr[i] = metrics.find(element => element.name == arr[i] && element.device == device)?.value;
// }
// // console.log(arr[i]);
// 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(metricName, result);
return result;
} catch { } catch {
return null; return null;
} }
@ -223,7 +315,7 @@ export class ZvksmetricsService {
async sendMetrics(inputData: K2Metrics): Promise<string> { async sendMetrics(inputData: K2Metrics): Promise<string> {
let resp: any; let resp: any;
let path: string = 'http://192.168.2.34:9050/update'; let path: any = process.env.IM_UPDATE;
let body: any = JSON.stringify(inputData); let body: any = JSON.stringify(inputData);
let options: any = { let options: any = {
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
@ -257,7 +349,7 @@ export class ZvksmetricsService {
} }
async setMetricsRanges(@Body() rangesData: any = null): Promise<MetricsRanges[]> { async setMetricsRanges(@Body() rangesData: any = null): Promise<MetricsRanges[]> {
let url: string = 'http://192.168.2.39:9999/api/ranges/9999'; let url: any = process.env.METRICS_RANGES;
let options: any = { let options: any = {
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}; };
@ -273,7 +365,7 @@ export class ZvksmetricsService {
async saveRanges(inputRanges: string): Promise<any> { async saveRanges(inputRanges: string): Promise<any> {
let ret: any; let ret: any;
let filePath = './src/zvksmetrics/conf/ranges.json'; let filePath: any = process.env.RANGES_CONFIG;
// console.log(inputRanges); // console.log(inputRanges);
let inp: string = JSON.stringify(inputRanges); let inp: string = JSON.stringify(inputRanges);
try { try {
@ -287,8 +379,24 @@ export class ZvksmetricsService {
return ret; return ret;
} }
async setComplexMetrics(@Body() complexData: any = null): Promise<ComplexMetricsCalculation[]> { async saveFormulas(inputFormulas: string): Promise<any> {
let url: string = 'http://192.168.2.39:9999/api/complex/5555'; let ret: any;
let filePath: any = process.env.FORMULAS_CONFIG;
// console.log(inputRanges);
let inp: string = JSON.stringify(inputFormulas);
try {
await writeFile(filePath, inp);
ret = "200 OK";
}
catch {
ret = "Error write file";
console.log(ret);
}
return ret;
}
async setComplexMetrics(@Body() complexData: any = null): Promise<MetricsCalculation[]> {
let url: any = process.env.COMPLEX_METRICS;
let options: any = { let options: any = {
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}; };
@ -302,9 +410,9 @@ export class ZvksmetricsService {
return complexData; return complexData;
} }
async showRangesOptions(filePath: string): Promise<JSON> { async showRangesOptions(filePath: any): Promise<JSON> {
let content: JSON = JSON.parse('{"name":"name"}'); let content: JSON = JSON.parse('{"name":"name"}');
filePath = './src/zvksmetrics/conf/ranges.json'; filePath = process.env.RANGES_CONFIG;
try { try {
content = JSON.parse(await readFile(filePath, { encoding: 'utf8' })); content = JSON.parse(await readFile(filePath, { encoding: 'utf8' }));
} }
@ -315,9 +423,24 @@ export class ZvksmetricsService {
return content; return content;
} }
async showComplexMetricsConfig(filePath: string): Promise<JSON> { async setIntegrationMetrics(@Body() integrationData: any = null): Promise<MetricsCalculation[]> {
let url: any = process.env.INTEGRATION_METRICS;
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: any): Promise<JSON> {
let content: JSON = JSON.parse('{"name":"name"}'); let content: JSON = JSON.parse('{"name":"name"}');
filePath = './src/zvksmetrics/conf/complex.json'; filePath = process.env.COMPLEX_CONFIG;
try { try {
content = JSON.parse(await readFile(filePath, { encoding: 'utf8' })); content = JSON.parse(await readFile(filePath, { encoding: 'utf8' }));
} }
@ -328,5 +451,32 @@ export class ZvksmetricsService {
return content; return content;
} }
async showIntegrationMetricsConfig(filePath: any): Promise<JSON> {
let content: JSON = JSON.parse('{"name":"name"}');
filePath = process.env.INTEGRATION_CONFIG;
try {
content = JSON.parse(await readFile(filePath, { encoding: 'utf8' }));
}
catch {
console.log('Error read file');
}
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;
}
}; };