[manager,webapp]新增监控大类别,支持自定义监控页面菜单自动渲染

This commit is contained in:
tomsun28
2022-03-05 15:17:52 +08:00
parent 326cc35199
commit 36926f0fa2
15 changed files with 65 additions and 45 deletions

View File

@@ -42,6 +42,11 @@ public class Job {
* 监控ID 应用ID * 监控ID 应用ID
*/ */
private long monitorId; private long monitorId;
/**
* 监控的大类别
* service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
*/
private String category;
/** /**
* 监控的类型 eg: linux | mysql | jvm * 监控的类型 eg: linux | mysql | jvm
*/ */

View File

@@ -50,7 +50,7 @@ public class AppController {
} }
@GetMapping(path = "/hierarchy") @GetMapping(path = "/hierarchy")
@ApiOperation(value = "查询全部层级的监控类型", notes = "查询所有监控类型,以层级结构输出") @ApiOperation(value = "查询全部监控指标层级", notes = "查询所有监控类型-指标组-指标层级,以层级结构输出")
public ResponseEntity<Message<List<Hierarchy>>> queryAppsHierarchy( public ResponseEntity<Message<List<Hierarchy>>> queryAppsHierarchy(
@ApiParam(value = "语言类型", example = "zh-CN", defaultValue = "zh-CN") @ApiParam(value = "语言类型", example = "zh-CN", defaultValue = "zh-CN")
@RequestParam(name = "lang", required = false) String lang) { @RequestParam(name = "lang", required = false) String lang) {

View File

@@ -21,15 +21,18 @@ import static io.swagger.annotations.ApiModelProperty.AccessMode.READ_WRITE;
@Data @Data
public class Hierarchy { public class Hierarchy {
@ApiModelProperty(value = "属性", example = "linux", accessMode = READ_WRITE, position = 0) @ApiModelProperty(value = "类别", example = "os", accessMode = READ_WRITE, position = 0)
String category;
@ApiModelProperty(value = "属性值", example = "linux", accessMode = READ_WRITE, position = 1)
String value; String value;
@ApiModelProperty(value = "属性国际化标签", example = "Linux系统", accessMode = READ_WRITE, position = 1) @ApiModelProperty(value = "属性国际化标签", example = "Linux系统", accessMode = READ_WRITE, position = 2)
String label; String label;
@ApiModelProperty(value = "是否是叶子节点", example = "true", accessMode = READ_WRITE, position = 2) @ApiModelProperty(value = "是否是叶子节点", example = "true", accessMode = READ_WRITE, position = 3)
Boolean isLeaf = false; Boolean isLeaf = false;
@ApiModelProperty(value = "下一关联层级", accessMode = READ_WRITE, position = 3) @ApiModelProperty(value = "下一关联层级", accessMode = READ_WRITE, position = 4)
private List<Hierarchy> children; private List<Hierarchy> children;
} }

View File

@@ -84,6 +84,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
List<Hierarchy> hierarchies = new LinkedList<>(); List<Hierarchy> hierarchies = new LinkedList<>();
for (Job job : appDefines.values()) { for (Job job : appDefines.values()) {
Hierarchy hierarchyApp = new Hierarchy(); Hierarchy hierarchyApp = new Hierarchy();
hierarchyApp.setCategory(job.getCategory());
hierarchyApp.setValue(job.getApp()); hierarchyApp.setValue(job.getApp());
Map<String, String> nameMap = job.getName(); Map<String, String> nameMap = job.getName();
if (nameMap != null) { if (nameMap != null) {

View File

@@ -1,3 +1,5 @@
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: custom
# 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws... # 监控应用类型(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: example app: example
name: name:

View File

@@ -1,3 +1,5 @@
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: service
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws... # 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: api app: api
name: name:

View File

@@ -1,3 +1,4 @@
category: service
app: fullsite app: fullsite
name: name:
zh-CN: 全站监控 zh-CN: 全站监控

View File

@@ -1,3 +1,4 @@
category: db
app: mysql app: mysql
name: name:
zh-CN: MYSQL数据库 zh-CN: MYSQL数据库

View File

@@ -1,3 +1,5 @@
# 此监控类型所属类别service-应用服务监控 db-数据库监控 custom-自定义监控 os-操作系统监控
category: service
# 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws... # 监控应用类型名称(与文件名保持一致) eg: linux windows tomcat mysql aws...
app: ping app: ping
name: name:

View File

@@ -1,3 +1,4 @@
category: service
app: port app: port
name: name:
zh-CN: 端口可用性 zh-CN: 端口可用性

View File

@@ -1,3 +1,4 @@
category: service
app: telnet app: telnet
name: name:
zh-CN: TELNET端口可用性 zh-CN: TELNET端口可用性

View File

@@ -1,3 +1,4 @@
category: service
app: website app: website
name: name:
zh-CN: 网站监测 zh-CN: 网站监测

View File

@@ -3,7 +3,7 @@ import { Injectable, Inject } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { ACLService } from '@delon/acl'; import { ACLService } from '@delon/acl';
import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth'; import { DA_SERVICE_TOKEN, ITokenService } from '@delon/auth';
import { ALAIN_I18N_TOKEN, MenuService, SettingsService, TitleService } from '@delon/theme'; import { ALAIN_I18N_TOKEN, Menu, MenuService, SettingsService, TitleService } from '@delon/theme';
import type { NzSafeAny } from 'ng-zorro-antd/core/types'; import type { NzSafeAny } from 'ng-zorro-antd/core/types';
import { NzIconService } from 'ng-zorro-antd/icon'; import { NzIconService } from 'ng-zorro-antd/icon';
import { Observable, zip, of } from 'rxjs'; import { Observable, zip, of } from 'rxjs';
@@ -37,13 +37,17 @@ export class StartupService {
private viaHttp(): Observable<void> { private viaHttp(): Observable<void> {
const defaultLang = this.i18n.defaultLang; const defaultLang = this.i18n.defaultLang;
return zip(this.i18n.loadLangData(defaultLang), this.httpClient.get('./assets/app-data.json')).pipe( return zip(
this.i18n.loadLangData(defaultLang),
this.httpClient.get('./assets/app-data.json'),
this.httpClient.get('/apps/hierarchy')
).pipe(
catchError((res: NzSafeAny) => { catchError((res: NzSafeAny) => {
console.warn(`StartupService.load: Network request failed`, res); console.warn(`StartupService.load: Network request failed`, res);
setTimeout(() => this.router.navigateByUrl(`/exception/500`)); setTimeout(() => this.router.navigateByUrl(`/exception/500`));
return []; return [];
}), }),
map(([langData, appData]: [Record<string, string>, NzSafeAny]) => { map(([langData, appData, menuData]: [Record<string, string>, NzSafeAny, NzSafeAny]) => {
// setting language data // setting language data
this.i18n.use(defaultLang, langData); this.i18n.use(defaultLang, langData);
@@ -56,6 +60,20 @@ export class StartupService {
this.aclService.setFull(true); this.aclService.setFull(true);
// Menu data, https://ng-alain.com/theme/menu // Menu data, https://ng-alain.com/theme/menu
this.menuService.add(appData.menu); this.menuService.add(appData.menu);
menuData.data.forEach((item: { category: string; value: string }) => {
let category = item.category;
let app = item.value;
let menu: Menu | null = this.menuService.getItem(category);
if (menu != null) {
menu.children?.push({
text: app,
link: `/monitors?app=${app}`,
i18n: `monitor.app.${app}`
});
}
});
// 刷新菜单
this.menuService.resume();
// Can be set page suffix title, https://ng-alain.com/theme/title // Can be set page suffix title, https://ng-alain.com/theme/title
this.titleService.suffix = appData.app.name; this.titleService.suffix = appData.app.name;
}) })

View File

@@ -30,48 +30,29 @@
"hideInBreadcrumb": true, "hideInBreadcrumb": true,
"children": [ "children": [
{ {
"key": "service",
"text": "应用服务", "text": "应用服务",
"i18n": "menu.monitor.service", "i18n": "menu.monitor.service",
"icon": "anticon-cloud", "icon": "anticon-cloud"
"children": [
{
"text": "website",
"link": "/monitors?app=website",
"i18n": "monitor.app.website"
},
{
"text": "api",
"link": "/monitors?app=api",
"i18n": "monitor.app.api"
},
{
"text": "ping",
"link": "/monitors?app=ping",
"i18n": "monitor.app.ping"
},
{
"text": "port",
"link": "/monitors?app=port",
"i18n": "monitor.app.port"
},
{
"text": "fullsite",
"link": "/monitors?app=fullsite",
"i18n": "monitor.app.fullsite"
}
]
}, },
{ {
"key": "db",
"text": "数据库", "text": "数据库",
"i18n": "menu.monitor.db", "i18n": "menu.monitor.db",
"icon": "anticon-database", "icon": "anticon-database"
"children": [ },
{ {
"text": "Mysql", "key": "os",
"link": "/monitors?app=mysql", "text": "操作系统",
"i18n": "monitor.app.mysql" "hide": true,
} "i18n": "menu.monitor.os",
] "icon": "anticon-windows"
},
{
"key": "custom",
"text": "自定义",
"i18n": "menu.monitor.custom",
"icon": "anticon-skin"
} }
] ]
}, },

View File

@@ -12,7 +12,8 @@
"service": "应用服务监控", "service": "应用服务监控",
"db": "数据库监控", "db": "数据库监控",
"os": "操作系统监控", "os": "操作系统监控",
"mid": "中间件监控" "mid": "中间件监控",
"custom": "自定义监控"
}, },
"account": { "account": {
"": "个人页", "": "个人页",