Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
hertzbeat
Hertzbeat
提交
c5e89bb0
Hertzbeat
项目概览
hertzbeat
/
Hertzbeat
9 个月 前同步成功
通知
1
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Hertzbeat
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
c5e89bb0
编写于
8月 07, 2023
作者:
sinat_25235033
提交者:
GitHub
8月 07, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
bugfix monitoring template app name already exists (#1152)
上级
9d18b304
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
41 addition
and
18 deletion
+41
-18
manager/src/main/java/org/dromara/hertzbeat/manager/controller/AppController.java
...g/dromara/hertzbeat/manager/controller/AppController.java
+16
-3
manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java
...ava/org/dromara/hertzbeat/manager/service/AppService.java
+3
-1
manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java
...romara/hertzbeat/manager/service/impl/AppServiceImpl.java
+15
-11
web-app/src/app/routes/setting/define/define.component.ts
web-app/src/app/routes/setting/define/define.component.ts
+1
-1
web-app/src/app/service/app-define.service.ts
web-app/src/app/service/app-define.service.ts
+6
-2
未找到文件。
manager/src/main/java/org/dromara/hertzbeat/manager/controller/AppController.java
浏览文件 @
c5e89bb0
...
...
@@ -89,10 +89,10 @@ public class AppController {
}
@PostMapping
(
path
=
"/define/yml"
)
@Operation
(
summary
=
"
Save and apply monitoring type define yml"
,
description
=
"保存并应用
监控类型的定义YML"
)
public
ResponseEntity
<
Message
<
Void
>>
apply
AppDefineYml
(
@Valid
@RequestBody
MonitorDefineDto
defineDto
)
{
@Operation
(
summary
=
"
Add new monitoring type define yml"
,
description
=
"新增
监控类型的定义YML"
)
public
ResponseEntity
<
Message
<
Void
>>
new
AppDefineYml
(
@Valid
@RequestBody
MonitorDefineDto
defineDto
)
{
try
{
appService
.
applyMonitorDefineYml
(
defineDto
.
getDefine
());
appService
.
applyMonitorDefineYml
(
defineDto
.
getDefine
()
,
false
);
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
ok
(
Message
.<
Void
>
builder
()
.
code
(
CommonConstants
.
FAIL_CODE
)
...
...
@@ -100,6 +100,19 @@ public class AppController {
}
return
ResponseEntity
.
ok
(
Message
.<
Void
>
builder
().
build
());
}
@PutMapping
(
path
=
"/define/yml"
)
@Operation
(
summary
=
"Update monitoring type define yml"
,
description
=
"更新监控类型的定义YML"
)
public
ResponseEntity
<
Message
<
Void
>>
updateAppDefineYml
(
@Valid
@RequestBody
MonitorDefineDto
defineDto
)
{
try
{
appService
.
applyMonitorDefineYml
(
defineDto
.
getDefine
(),
true
);
}
catch
(
Exception
e
)
{
return
ResponseEntity
.
ok
(
Message
.<
Void
>
builder
()
.
code
(
CommonConstants
.
FAIL_CODE
)
.
msg
(
e
.
getMessage
()).
build
());
}
return
ResponseEntity
.
ok
(
Message
.<
Void
>
builder
().
build
());
}
@GetMapping
(
path
=
"/hierarchy"
)
@Operation
(
summary
=
"Query all monitored types-indicator group-indicator level, output in a hierarchical structure"
,
description
=
"查询所有监控的类型-指标组-指标层级,以层级结构输出"
)
...
...
manager/src/main/java/org/dromara/hertzbeat/manager/service/AppService.java
浏览文件 @
c5e89bb0
...
...
@@ -94,9 +94,11 @@ public interface AppService {
/**
* update and apply app define yml
*
* @param ymlContent yml content
* @param isModify is modified?
*/
void
applyMonitorDefineYml
(
String
ymlContent
);
void
applyMonitorDefineYml
(
String
ymlContent
,
boolean
isModify
);
/**
* delete monitor define yml
...
...
manager/src/main/java/org/dromara/hertzbeat/manager/service/impl/AppServiceImpl.java
浏览文件 @
c5e89bb0
...
...
@@ -221,7 +221,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
}
@Override
public
void
applyMonitorDefineYml
(
String
ymlContent
)
{
public
void
applyMonitorDefineYml
(
String
ymlContent
,
boolean
isModify
)
{
Yaml
yaml
=
new
Yaml
();
Job
app
;
try
{
...
...
@@ -231,7 +231,7 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
throw
new
IllegalArgumentException
(
"parse yml define error: "
+
e
.
getMessage
());
}
// app params verify
verifyDefineAppContent
(
app
);
verifyDefineAppContent
(
app
,
isModify
);
String
classpath
=
Objects
.
requireNonNull
(
this
.
getClass
().
getClassLoader
().
getResource
(
""
)).
getPath
();
String
defineAppPath
=
classpath
+
"define"
+
File
.
separator
+
"app-"
+
app
.
getApp
()
+
".yml"
;
File
defineAppFile
=
new
File
(
defineAppPath
);
...
...
@@ -247,17 +247,21 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
SpringContextHolder
.
getBean
(
MonitorService
.
class
).
updateAppCollectJob
(
app
);
}
private
void
verifyDefineAppContent
(
Job
app
)
{
Assert
.
notNull
(
app
,
"
define yml
can not null"
);
Assert
.
notNull
(
app
.
getApp
(),
"
define yml
require attributes app"
);
Assert
.
notNull
(
app
.
getCategory
(),
"
define yml
require attributes category"
);
Assert
.
notEmpty
(
app
.
getName
(),
"
define yml
require attributes name"
);
Assert
.
notEmpty
(
app
.
getParams
(),
"
define yml
require attributes params"
);
private
void
verifyDefineAppContent
(
Job
app
,
boolean
isModify
)
{
Assert
.
notNull
(
app
,
"
monitoring template
can not null"
);
Assert
.
notNull
(
app
.
getApp
(),
"
monitoring template
require attributes app"
);
Assert
.
notNull
(
app
.
getCategory
(),
"
monitoring template
require attributes category"
);
Assert
.
notEmpty
(
app
.
getName
(),
"
monitoring template
require attributes name"
);
Assert
.
notEmpty
(
app
.
getParams
(),
"
monitoring template
require attributes params"
);
boolean
hasParamHost
=
app
.
getParams
().
stream
().
anyMatch
(
item
->
"host"
.
equals
(
item
.
getField
()));
Assert
.
isTrue
(
hasParamHost
,
"
define yml
attributes params must have param host"
);
Assert
.
notEmpty
(
app
.
getMetrics
(),
"
define yml
require attributes metrics"
);
Assert
.
isTrue
(
hasParamHost
,
"
monitoring template
attributes params must have param host"
);
Assert
.
notEmpty
(
app
.
getMetrics
(),
"
monitoring template
require attributes metrics"
);
boolean
hasAvailableMetrics
=
app
.
getMetrics
().
stream
().
anyMatch
(
item
->
item
.
getPriority
()
==
0
);
Assert
.
isTrue
(
hasAvailableMetrics
,
"define yml metrics list must have one priority 0 metrics"
);
Assert
.
isTrue
(
hasAvailableMetrics
,
"monitoring template metrics list must have one priority 0 metrics"
);
if
(!
isModify
)
{
Assert
.
isNull
(
appDefines
.
get
(
app
.
getApp
().
toLowerCase
()),
"monitoring template name "
+
app
.
getApp
()
+
" already exists."
);
}
}
@Override
...
...
web-app/src/app/routes/setting/define/define.component.ts
浏览文件 @
c5e89bb0
...
...
@@ -159,7 +159,7 @@ export class DefineComponent implements OnInit {
saveAndApply
()
{
this
.
saveLoading
=
true
;
const
saveDefine$
=
this
.
appDefineSvc
.
saveAppDefineYmlContent
(
this
.
code
)
.
newAppDefineYmlContent
(
this
.
code
,
this
.
currentApp
==
null
)
.
pipe
(
finalize
(()
=>
{
saveDefine$
.
unsubscribe
();
...
...
web-app/src/app/service/app-define.service.ts
浏览文件 @
c5e89bb0
...
...
@@ -42,14 +42,18 @@ export class AppDefineService {
return
this
.
http
.
get
<
Message
<
any
>>
(
`/apps/
${
app
}
/define/yml`
);
}
public
saveAppDefineYmlContent
(
defineContent
:
string
|
undefined
|
null
):
Observable
<
Message
<
any
>>
{
public
newAppDefineYmlContent
(
defineContent
:
string
|
undefined
|
null
,
isNew
:
boolean
):
Observable
<
Message
<
any
>>
{
if
(
defineContent
===
null
||
defineContent
===
undefined
)
{
console
.
log
(
'
defineContent can not null
'
);
}
let
body
=
{
define
:
defineContent
};
return
this
.
http
.
post
<
Message
<
any
>>
(
`/apps/define/yml`
,
body
);
if
(
isNew
)
{
return
this
.
http
.
post
<
Message
<
any
>>
(
`/apps/define/yml`
,
body
);
}
else
{
return
this
.
http
.
put
<
Message
<
any
>>
(
`/apps/define/yml`
,
body
);
}
}
public
getAppHierarchy
(
lang
:
string
|
undefined
):
Observable
<
Message
<
any
>>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录