ref: 重构网元状态,提升加载网元列表带状态速度

Refactor network element state management

- Removed the NE state endpoint and related service logic from the network_data module.
- Introduced a new NEStateController to handle network element state records.
- Implemented NEState service and repository for managing state records in the database.
- Updated NEInfo and NeLicense controllers to utilize the new NEState service for fetching and saving state information.
- Enhanced state handling in the websocket processor to reflect the latest state of network elements.
- Added caching logic for network element states using Redis.
- Improved error handling and response formatting for state queries.
This commit is contained in:
TsMask
2025-10-27 15:15:27 +08:00
parent 667d0fdad8
commit e7ae390f6e
18 changed files with 428 additions and 343 deletions

View File

@@ -6,16 +6,20 @@ CREATE TABLE "ne_state" (
"id" integer NOT NULL,
"ne_type" text(16),
"ne_id" text(32),
"version" text(16),
"capability" integer,
"ne_version" text(16),
"standby" integer,
"nb_number" integer,
"ue_number" integer,
"serial_num" text(16),
"expiry_date" text(10),
"hostname" text(32),
"os" text(196),
"sys_cpu_usage" integer,
"sys_mem_usage" integer,
"sys_disk_usage" integer,
"nf_cpu_usage" integer,
"nf_mem_used" integer,
"create_time" integer,
"refresh_time" integer,
PRIMARY KEY ("id")
);
@@ -26,7 +30,7 @@ CREATE INDEX "idx_type_id_time"
ON "ne_state" (
"ne_type" ASC,
"ne_id" ASC,
"create_time" ASC
"refresh_time" ASC
);
-- ----------------------------

View File

@@ -0,0 +1,38 @@
-- ----------------------------
-- Table structure for ne_state
-- ----------------------------
DROP TABLE IF EXISTS "ne_state";
CREATE TABLE "ne_state" (
"id" integer NOT NULL,
"ne_type" text(16),
"ne_id" text(32),
"ne_version" text(16),
"standby" integer,
"nb_number" integer,
"ue_number" integer,
"serial_num" text(16),
"expiry_date" text(10),
"hostname" text(32),
"os" text(196),
"sys_cpu_usage" integer,
"sys_mem_usage" integer,
"sys_disk_usage" integer,
"nf_cpu_usage" integer,
"nf_mem_used" integer,
"refresh_time" integer,
PRIMARY KEY ("id")
);
-- ----------------------------
-- Indexes structure for table ne_state
-- ----------------------------
CREATE INDEX IF NOT EXISTS "idx_type_id_time"
ON "ne_state" (
"ne_type" ASC,
"ne_id" ASC,
"refresh_time" ASC
);
-- ----------------------------
-- Records of ne_state
-- ----------------------------

View File

@@ -7,20 +7,24 @@ SET FOREIGN_KEY_CHECKS = 0;
DROP TABLE IF EXISTS `ne_state`;
CREATE TABLE `ne_state` (
`id` int NOT NULL AUTO_INCREMENT,
`ne_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '',
`ne_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '',
`version` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '版本',
`capability` bigint DEFAULT '0' COMMENT '用户容量',
`ne_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元类型',
`ne_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元ID',
`ne_version` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元版本',
`standby` int DEFAULT '0' COMMENT '主备状态 0-主 1-备',
`nb_number` int DEFAULT '0' COMMENT '基站容量',
`ue_number` int DEFAULT '0' COMMENT '用户容量',
`serial_num` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '序列号',
`expiry_date` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '许可证到期日期',
`hostname` varchar(32) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '主机名 hostname',
`os` varchar(196) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '操作系统 uname',
`sys_cpu_usage` float DEFAULT '0' COMMENT 'cpu使用率-sys',
`sys_mem_usage` float DEFAULT '0' COMMENT '内存使用率-sys',
`sys_disk_usage` float DEFAULT '0' COMMENT '磁盘使用率-sys',
`nf_cpu_usage` float DEFAULT '0' COMMENT 'cpu使用率-nf',
`nf_mem_used` bigint DEFAULT '0' COMMENT '内存使用KB-nf',
`create_time` bigint DEFAULT '0' COMMENT '创建时间',
`refresh_time` bigint DEFAULT '0' COMMENT '刷新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_type_id_time` (`ne_type`,`ne_id`,`create_time`) USING BTREE COMMENT 'idx_state_ne_type_id_at'
KEY `idx_type_id_time` (`ne_type`,`ne_id`,`refresh_time`) USING BTREE COMMENT 'idx_state_ne_type_id_at'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='网元_状态记录内存/CPU/磁盘';
SET FOREIGN_KEY_CHECKS=1;

View File

@@ -1,49 +1,29 @@
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
--
-- Table structure for table `ne_state`
--
CREATE TABLE IF NOT EXISTS `ne_state` (
DROP TABLE IF EXISTS `ne_state`;
CREATE TABLE `ne_state` (
`id` int NOT NULL AUTO_INCREMENT,
`ne_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '',
`ne_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '',
`version` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '版本',
`capability` bigint DEFAULT '0' COMMENT '用户容量',
`ne_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元类型',
`ne_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元ID',
`ne_version` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '网元版本',
`standby` int DEFAULT '0' COMMENT '主备状态 0-主 1-备',
`nb_number` int DEFAULT '0' COMMENT '基站容量',
`ue_number` int DEFAULT '0' COMMENT '用户容量',
`serial_num` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '序列号',
`expiry_date` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '许可证到期日期',
`hostname` varchar(32) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '主机名 hostname',
`os` varchar(196) COLLATE utf8mb4_general_ci DEFAULT '' COMMENT '操作系统 uname',
`sys_cpu_usage` float DEFAULT '0' COMMENT 'cpu使用率-sys',
`sys_mem_usage` float DEFAULT '0' COMMENT '内存使用率-sys',
`sys_disk_usage` float DEFAULT '0' COMMENT '磁盘使用率-sys',
`nf_cpu_usage` float DEFAULT '0' COMMENT 'cpu使用率-nf',
`nf_mem_used` bigint DEFAULT '0' COMMENT '内存使用KB-nf',
`create_time` bigint DEFAULT '0' COMMENT '创建时间',
`refresh_time` bigint DEFAULT '0' COMMENT '刷新时间',
PRIMARY KEY (`id`) USING BTREE,
KEY `idx_type_id_time` (`ne_type`,`ne_id`,`create_time`) USING BTREE COMMENT 'idx_state_ne_type_id_at'
KEY `idx_type_id_time` (`ne_type`,`ne_id`,`refresh_time`) USING BTREE COMMENT 'idx_state_ne_type_id_at'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci COMMENT='网元_状态记录内存/CPU/磁盘';
-- ----------------------------
-- COLUMN for ne_state
-- ----------------------------
ALTER TABLE `ne_state` DROP COLUMN `cpu_usage`;
ALTER TABLE `ne_state` DROP COLUMN `mem_usage`;
ALTER TABLE `ne_state` DROP COLUMN `disk_space`;
ALTER TABLE `ne_state` DROP COLUMN `timestamp`;
ALTER TABLE `ne_state` DROP INDEX `idx_ne_type_id`;
ALTER TABLE `ne_state` DROP INDEX `idx_timestamp`;
ALTER TABLE `ne_state` MODIFY COLUMN `ne_type` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' AFTER `id`;
ALTER TABLE `ne_state` MODIFY COLUMN `ne_id` varchar(32) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' AFTER `ne_type`;
ALTER TABLE `ne_state` MODIFY COLUMN `version` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '版本' AFTER `ne_id`;
ALTER TABLE `ne_state` MODIFY COLUMN `capability` bigint(20) NULL DEFAULT 0 COMMENT '用户容量' AFTER `version`;
ALTER TABLE `ne_state` MODIFY COLUMN `serial_num` varchar(16) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '序列号' AFTER `capability`;
ALTER TABLE `ne_state` MODIFY COLUMN `expiry_date` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '' COMMENT '许可证到期日期' AFTER `serial_num`;
ALTER TABLE `ne_state` ADD COLUMN `sys_cpu_usage` float NULL DEFAULT 0 COMMENT 'cpu使用率-sys' AFTER `expiry_date`;
ALTER TABLE `ne_state` ADD COLUMN `sys_mem_usage` float NULL DEFAULT 0 COMMENT '内存使用率-sys' AFTER `sys_cpu_usage`;
ALTER TABLE `ne_state` ADD COLUMN `sys_disk_usage` float NULL DEFAULT 0 COMMENT '磁盘使用率-sys' AFTER `sys_mem_usage`;
ALTER TABLE `ne_state` ADD COLUMN `nf_cpu_usage` float NULL DEFAULT 0 COMMENT 'cpu使用率-nf' AFTER `sys_disk_usage`;
ALTER TABLE `ne_state` ADD COLUMN `nf_mem_used` bigint(20) NULL DEFAULT 0 COMMENT '内存使用KB-nf' AFTER `nf_cpu_usage`;
ALTER TABLE `ne_state` ADD COLUMN `create_time` bigint(20) NULL DEFAULT 0 COMMENT '创建时间' AFTER `nf_mem_used`;
ALTER TABLE `ne_state` ADD INDEX `idx_type_id_time`(`ne_type`, `ne_id`, `create_time`) USING BTREE COMMENT 'idx_state_ne_type_id_at';
ALTER TABLE `ne_state` COMMENT = '网元_状态记录内存/CPU/磁盘';
SET FOREIGN_KEY_CHECKS=1;