From 9f36be5025e084b32a01e34b3342f07359e13df3 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Mon, 28 Aug 2023 14:06:09 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E7=A6=BB=E7=BA=BF=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/group.js | 33 +++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 150da65..21a518e 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -241,10 +241,19 @@ async function groupStatisticOnline (ctx) { const strucRes = strucIdArr.length ? await clickHouse.anxinyun.query( ` - SELECT * FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); + SELECT name, id FROM t_structure WHERE id IN (${[...strucIdArr].join(',')}); ` ).toPromise() : [] + // 查中断时间 + const maxOfflineTimeRes = strucIdArr.length ? await models.StructureOff.findAll({ + where: { + structure: { $in: strucIdArr }, + state: 0 + } + }) : [] + + // 查在线率 const strucOnlineClient = ctx.app.fs.esclient.strucOnline const onlineRes = await strucOnlineClient.search({ index: strucOnlineClient.config.index, @@ -264,7 +273,7 @@ async function groupStatisticOnline (ctx) { { "terms": { "structure": strucIdArr, - "structure": [1, 2, 3] + // "structure": [1, 2, 3] } } ] @@ -280,8 +289,26 @@ async function groupStatisticOnline (ctx) { } }) + for (let struc of strucRes) { + let curOnline = + onlineRes.hits.hits + .filter((h) => h._source.structure == struc.id) + // .sort((a, b) => { + // return a._source.collect_time - b._source.collect_time + // }) + .map(s => { + return { + ...s._source, + rate: s._source.online / s._source.total * 100 + } + }) + let curOffline = maxOfflineTimeRes.find((o) => o.structure == struc.id) + struc.online = curOnline + struc.offline = curOffline || {} + } + ctx.status = 200; - ctx.body = onlineRes.hits.hits; + ctx.body = strucRes; } catch (error) { ctx.fs.logger.error(`path: ${ctx.path}, error: error`); ctx.status = 400; From 082ed56e53bdc2e67e893b72d87a5591dd9a4207 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Mon, 28 Aug 2023 14:48:40 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E8=BE=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/controllers/project/group.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/app/lib/controllers/project/group.js b/api/app/lib/controllers/project/group.js index 21a518e..7f9f69a 100644 --- a/api/app/lib/controllers/project/group.js +++ b/api/app/lib/controllers/project/group.js @@ -196,7 +196,7 @@ async function groupStatistic (ctx) { ctx.status = 200; ctx.body = rslt } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined @@ -310,7 +310,7 @@ async function groupStatisticOnline (ctx) { ctx.status = 200; ctx.body = strucRes; } catch (error) { - ctx.fs.logger.error(`path: ${ctx.path}, error: error`); + ctx.fs.logger.error(`path: ${ctx.path}, error: ${error}`); ctx.status = 400; ctx.body = { message: typeof error == 'string' ? error : undefined From 0bfa29cc89b3c594f770e0ec8ced4c7efeff648d Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Mon, 28 Aug 2023 21:05:36 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E9=9B=86=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=BB=9F=E8=AE=A1=E6=9F=A5=E8=AF=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/app/lib/models/app_alarm.js | 280 +++++++++++----------- api/app/lib/models/structure_off.js | 112 ++++----- api/app/lib/models/system_problem.js | 56 ++--- web/client/src/sections/auth/index.js | 8 +- web/client/src/sections/install/routes.js | 4 +- 5 files changed, 230 insertions(+), 230 deletions(-) diff --git a/api/app/lib/models/app_alarm.js b/api/app/lib/models/app_alarm.js index c0a6412..e12b976 100644 --- a/api/app/lib/models/app_alarm.js +++ b/api/app/lib/models/app_alarm.js @@ -2,145 +2,145 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const AppAlarm = sequelize.define("appAlarm", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: true, - field: "id", - autoIncrement: true, - unique: "app_alarm_id_uindex" - }, - serialNumber: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "自定义编号", - primaryKey: false, - field: "serial_number", - autoIncrement: false - }, - projectAppId: { - type: DataTypes.INTEGER, - allowNull: true, - defaultValue: null, - comment: "对应的项目id", - primaryKey: false, - field: "project_app_id", - autoIncrement: false, - references: { - key: "id", - model: "app" + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const AppAlarm = sequelize.define("appAlarm", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "app_alarm_id_uindex" + }, + serialNumber: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "自定义编号", + primaryKey: false, + field: "serial_number", + autoIncrement: false + }, + projectAppId: { + type: DataTypes.INTEGER, + allowNull: true, + defaultValue: null, + comment: "对应的项目id", + primaryKey: false, + field: "project_app_id", + autoIncrement: false, + references: { + key: "id", + model: "app" + } + }, + appDomain: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "应用域名", + primaryKey: false, + field: "app_domain", + autoIncrement: false + }, + alarmContent: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "告警信息", + primaryKey: false, + field: "alarm_content", + autoIncrement: false + }, + createTime: { + type: DataTypes.DATE, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: false, + field: "create_time", + autoIncrement: false + }, + updateTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "update_time", + autoIncrement: false + }, + confirm: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "确认信息", + primaryKey: false, + field: "confirm", + autoIncrement: false + }, + router: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "路由", + primaryKey: false, + field: "router", + autoIncrement: false + }, + statusCode: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "状态码", + primaryKey: false, + field: "status_code", + autoIncrement: false + }, + screenshot: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "screenshot", + autoIncrement: false + }, + confirmTime: { + type: DataTypes.DATE, + allowNull: true, + defaultValue: null, + comment: "确认时间", + primaryKey: false, + field: "confirm_time", + autoIncrement: false + }, + confirmAuto: { + type: DataTypes.BOOLEAN, + allowNull: true, + defaultValue: null, + comment: "是否自动恢复", + primaryKey: false, + field: "confirm_auto", + autoIncrement: false + }, + type: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: null, + primaryKey: false, + field: "type", + autoIncrement: false } - }, - appDomain: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "应用域名", - primaryKey: false, - field: "app_domain", - autoIncrement: false - }, - alarmContent: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "告警信息", - primaryKey: false, - field: "alarm_content", - autoIncrement: false - }, - createTime: { - type: DataTypes.DATE, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: false, - field: "create_time", - autoIncrement: false - }, - updateTime: { - type: DataTypes.DATE, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "update_time", - autoIncrement: false - }, - confirm: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "确认信息", - primaryKey: false, - field: "confirm", - autoIncrement: false - }, - router: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "路由", - primaryKey: false, - field: "router", - autoIncrement: false - }, - statusCode: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "状态码", - primaryKey: false, - field: "status_code", - autoIncrement: false - }, - screenshot: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "screenshot", - autoIncrement: false - }, - confirmTime: { - type: DataTypes.DATE, - allowNull: true, - defaultValue: null, - comment: "确认时间", - primaryKey: false, - field: "confirm_time", - autoIncrement: false - }, - confirmAuto: { - type: DataTypes.BOOLEAN, - allowNull: true, - defaultValue: null, - comment: "是否自动恢复", - primaryKey: false, - field: "confirm_auto", - autoIncrement: false - }, - type: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: null, - primaryKey: false, - field: "type", - autoIncrement: false - } - }, { - tableName: "app_alarm", - comment: "", - indexes: [] - }); - dc.models.AppAlarm = AppAlarm; - return AppAlarm; + }, { + tableName: "app_alarm", + comment: "", + indexes: [] + }); + dc.models.AppAlarm = AppAlarm; + return AppAlarm; }; \ No newline at end of file diff --git a/api/app/lib/models/structure_off.js b/api/app/lib/models/structure_off.js index e286832..153f6a5 100644 --- a/api/app/lib/models/structure_off.js +++ b/api/app/lib/models/structure_off.js @@ -3,60 +3,60 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const StructureOff = sequelize.define("structureOff", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: true, - field: "id", - autoIncrement: true, - unique: "t_structure_off_id_uindex" - }, - structure: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "结构物id", - primaryKey: false, - field: "structure", - autoIncrement: false - }, - offline: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "离线时长(分钟)", - primaryKey: false, - field: "offline", - autoIncrement: false - }, - offtime: { - type: DataTypes.STRING, - allowNull: false, - defaultValue: null, - comment: "最后数据时间", - primaryKey: false, - field: "offtime", - autoIncrement: false - }, - state: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: "数据状态( 0:有效,1:无效)", - primaryKey: false, - field: "state", - autoIncrement: false - } - }, { - tableName: "t_structure_off", - comment: "", - indexes: [] - }); - dc.models.StructureOff = StructureOff; - return StructureOff; + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const StructureOff = sequelize.define("structureOff", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true, + unique: "t_structure_off_id_uindex" + }, + structure: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "结构物id", + primaryKey: false, + field: "structure", + autoIncrement: false + }, + offline: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "离线时长(分钟)", + primaryKey: false, + field: "offline", + autoIncrement: false + }, + offtime: { + type: DataTypes.STRING, + allowNull: false, + defaultValue: null, + comment: "最后数据时间", + primaryKey: false, + field: "offtime", + autoIncrement: false + }, + state: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: "数据状态( 0:有效,1:无效)", + primaryKey: false, + field: "state", + autoIncrement: false + } + }, { + tableName: "t_structure_off", + comment: "", + indexes: [] + }); + dc.models.StructureOff = StructureOff; + return StructureOff; }; \ No newline at end of file diff --git a/api/app/lib/models/system_problem.js b/api/app/lib/models/system_problem.js index 5d7d4fd..dff23c1 100644 --- a/api/app/lib/models/system_problem.js +++ b/api/app/lib/models/system_problem.js @@ -3,32 +3,32 @@ 'use strict'; module.exports = dc => { - const DataTypes = dc.ORM; - const sequelize = dc.orm; - const SystemProblem = sequelize.define("systemProblem", { - id: { - type: DataTypes.INTEGER, - allowNull: false, - defaultValue: null, - comment: null, - primaryKey: true, - field: "id", - autoIncrement: true - }, - type: { - type: DataTypes.STRING, - allowNull: true, - defaultValue: null, - comment: "问题类型:数据库异常、es异常、kafka异常、服务器异常、应用异常、其他", - primaryKey: false, - field: "type", - autoIncrement: false - } - }, { - tableName: "system_problem", - comment: "", - indexes: [] - }); - dc.models.SystemProblem = SystemProblem; - return SystemProblem; + const DataTypes = dc.ORM; + const sequelize = dc.orm; + const SystemProblem = sequelize.define("systemProblem", { + id: { + type: DataTypes.INTEGER, + allowNull: false, + defaultValue: null, + comment: null, + primaryKey: true, + field: "id", + autoIncrement: true + }, + type: { + type: DataTypes.STRING, + allowNull: true, + defaultValue: null, + comment: "问题类型:数据库异常、es异常、kafka异常、服务器异常、应用异常、其他", + primaryKey: false, + field: "type", + autoIncrement: false + } + }, { + tableName: "system_problem", + comment: "", + indexes: [] + }); + dc.models.SystemProblem = SystemProblem; + return SystemProblem; }; \ No newline at end of file diff --git a/web/client/src/sections/auth/index.js b/web/client/src/sections/auth/index.js index f8e40fb..a01ab7d 100644 --- a/web/client/src/sections/auth/index.js +++ b/web/client/src/sections/auth/index.js @@ -5,8 +5,8 @@ import reducers from './reducers'; import actions from './actions'; export default { - key: 'auth', - reducers: reducers, - routes: routes, - actions: actions + key: 'auth', + reducers: reducers, + routes: routes, + actions: actions }; \ No newline at end of file diff --git a/web/client/src/sections/install/routes.js b/web/client/src/sections/install/routes.js index 99892f7..e983d58 100644 --- a/web/client/src/sections/install/routes.js +++ b/web/client/src/sections/install/routes.js @@ -1,5 +1,5 @@ 'use strict'; -import { Roles, System,Setup,Set } from './containers'; +import { Roles, System, Setup, Set } from './containers'; export default [ { @@ -30,7 +30,7 @@ export default [ component: System, breadcrumb: '系统映射', }] - },, { + }, { path: '/order', key: 'order', breadcrumb: '工单管理', From 25044e79215c18438d18a8db4a2988d2ce3e7364 Mon Sep 17 00:00:00 2001 From: CODE <1650192445@qq.com> Date: Tue, 29 Aug 2023 08:44:05 +0800 Subject: [PATCH 4/4] sql --- script/3.1/schema/1.create_p_group.sql | 17 +++++++++++++++++ script/3.1/schema/2.create_struc_off.sql | 22 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 script/3.1/schema/1.create_p_group.sql create mode 100644 script/3.1/schema/2.create_struc_off.sql diff --git a/script/3.1/schema/1.create_p_group.sql b/script/3.1/schema/1.create_p_group.sql new file mode 100644 index 0000000..9554274 --- /dev/null +++ b/script/3.1/schema/1.create_p_group.sql @@ -0,0 +1,17 @@ +create table if not exists project_group +( + id serial not null + constraint project_group_pk + primary key, + name varchar(256), + poms_project_ids integer[] not null, + poms_user_id integer not null + constraint project_group_user_id_fk + references "user" +); + +comment on column project_group.poms_project_ids is '运维项目id'; + +create unique index if not exists project_group_id_uindex + on project_group (id); + diff --git a/script/3.1/schema/2.create_struc_off.sql b/script/3.1/schema/2.create_struc_off.sql new file mode 100644 index 0000000..862e603 --- /dev/null +++ b/script/3.1/schema/2.create_struc_off.sql @@ -0,0 +1,22 @@ +create table if not exists t_structure_off +( + id serial not null + constraint t_structure_off_pk + primary key, + structure integer not null, + offline integer not null, + offtime varchar not null, + state integer not null +); + +comment on column t_structure_off.structure is '结构物id'; + +comment on column t_structure_off.offline is '离线时长(分钟)'; + +comment on column t_structure_off.offtime is '最后数据时间'; + +comment on column t_structure_off.state is '数据状态( 0:有效,1:无效)'; + +create unique index if not exists t_structure_off_id_uindex + on t_structure_off (id); +