wenlele 1 year ago
parent
commit
0ce092f5c5
  1. 37
      api/app/lib/controllers/project/group.js
  2. 280
      api/app/lib/models/app_alarm.js
  3. 112
      api/app/lib/models/structure_off.js
  4. 56
      api/app/lib/models/system_problem.js
  5. 17
      script/3.1/schema/1.create_p_group.sql
  6. 22
      script/3.1/schema/2.create_struc_off.sql
  7. 8
      web/client/src/sections/auth/index.js
  8. 4
      web/client/src/sections/install/routes.js

37
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
@ -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,10 +289,28 @@ 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.fs.logger.error(`path: ${ctx.path}, error: ${error}`);
ctx.status = 400;
ctx.body = {
message: typeof error == 'string' ? error : undefined

280
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;
};

112
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;
};

56
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;
};

17
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);

22
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);

8
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
};

4
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: '工单管理',

Loading…
Cancel
Save