Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
kafka-manager
提交
06a97ef0
K
kafka-manager
项目概览
DiDi
/
kafka-manager
8 个月 前同步成功
通知
58
Star
6372
Fork
1229
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kafka-manager
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
06a97ef0
编写于
11月 22, 2020
作者:
Z
zengqiao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
FIX N9e Mon
上级
bc4dac9c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
101 addition
and
33 deletion
+101
-33
kafka-manager-extends/kafka-manager-monitor/pom.xml
kafka-manager-extends/kafka-manager-monitor/pom.xml
+4
-0
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/N9eConverter.java
...eji/kafka/manager/monitor/component/n9e/N9eConverter.java
+47
-11
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/N9eService.java
...ukeji/kafka/manager/monitor/component/n9e/N9eService.java
+33
-8
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/entry/N9eStrategy.java
...afka/manager/monitor/component/n9e/entry/N9eStrategy.java
+6
-6
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/entry/N9eStrategyAlertUpgrade.java
.../monitor/component/n9e/entry/N9eStrategyAlertUpgrade.java
+7
-6
kafka-manager-web/src/main/resources/application.yml
kafka-manager-web/src/main/resources/application.yml
+4
-2
未找到文件。
kafka-manager-extends/kafka-manager-monitor/pom.xml
浏览文件 @
06a97ef0
...
...
@@ -55,6 +55,10 @@
<groupId>
commons-lang
</groupId>
<artifactId>
commons-lang
</artifactId>
</dependency>
<dependency>
<groupId>
com.github.ben-manes.caffeine
</groupId>
<artifactId>
caffeine
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
...
...
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/N9eConverter.java
浏览文件 @
06a97ef0
package
com.xiaojukeji.kafka.manager.monitor.component.n9e
;
import
com.xiaojukeji.kafka.manager.common.utils.ListUtils
;
import
com.xiaojukeji.kafka.manager.common.utils.ValidateUtils
;
import
com.xiaojukeji.kafka.manager.monitor.common.entry.*
;
import
com.xiaojukeji.kafka.manager.monitor.component.n9e.entry.*
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.*
;
/**
* @author zengqiao
...
...
@@ -31,13 +30,20 @@ public class N9eConverter {
return
n9ePointList
;
}
public
static
N9eStrategy
convert2N9eStrategy
(
Strategy
strategy
,
Integer
monitorN9eNid
)
{
public
static
N9eStrategy
convert2N9eStrategy
(
Strategy
strategy
,
Integer
monitorN9eNid
,
Map
<
String
,
NotifyGroup
>
notifyGroupMap
)
{
if
(
strategy
==
null
)
{
return
null
;
}
if
(
ValidateUtils
.
isNull
(
notifyGroupMap
))
{
notifyGroupMap
=
new
HashMap
<>();
}
N9eStrategy
n9eStrategy
=
new
N9eStrategy
();
n9eStrategy
.
setId
(
strategy
.
getId
().
intValue
());
if
(!
ValidateUtils
.
isNull
(
strategy
.
getId
()))
{
n9eStrategy
.
setId
(
strategy
.
getId
().
intValue
());
}
n9eStrategy
.
setCategory
(
1
);
n9eStrategy
.
setName
(
strategy
.
getName
());
n9eStrategy
.
setNid
(
monitorN9eNid
);
...
...
@@ -72,7 +78,17 @@ public class N9eConverter {
StrategyAction
strategyAction
=
strategy
.
getStrategyActionList
().
get
(
0
);
n9eStrategy
.
setConverge
(
ListUtils
.
string2IntList
(
strategyAction
.
getConverge
()));
n9eStrategy
.
setNotify_group
(
ListUtils
.
string2StrList
(
strategyAction
.
getNotifyGroup
()));
List
<
Integer
>
notifyGroups
=
new
ArrayList
<>();
for
(
String
name:
ListUtils
.
string2StrList
(
strategyAction
.
getNotifyGroup
()))
{
NotifyGroup
notifyGroup
=
notifyGroupMap
.
get
(
name
);
if
(
ValidateUtils
.
isNull
(
notifyGroup
))
{
continue
;
}
notifyGroups
.
add
(
notifyGroup
.
getId
().
intValue
());
}
n9eStrategy
.
setNotify_group
(
notifyGroups
);
n9eStrategy
.
setNotify_user
(
new
ArrayList
<>());
n9eStrategy
.
setCallback
(
strategyAction
.
getCallback
());
n9eStrategy
.
setEnable_stime
(
"00:00"
);
...
...
@@ -80,26 +96,36 @@ public class N9eConverter {
n9eStrategy
.
setEnable_days_of_week
(
ListUtils
.
string2IntList
(
strategy
.
getPeriodDaysOfWeek
()));
n9eStrategy
.
setNeed_upgrade
(
0
);
n9eStrategy
.
setAlert_upgrade
(
new
ArrayList
<>
());
n9eStrategy
.
setAlert_upgrade
(
new
N9eStrategyAlertUpgrade
());
return
n9eStrategy
;
}
public
static
List
<
Strategy
>
convert2StrategyList
(
List
<
N9eStrategy
>
n9eStrategyList
)
{
public
static
List
<
Strategy
>
convert2StrategyList
(
List
<
N9eStrategy
>
n9eStrategyList
,
Map
<
String
,
NotifyGroup
>
notifyGroupMap
)
{
if
(
n9eStrategyList
==
null
||
n9eStrategyList
.
isEmpty
())
{
return
new
ArrayList
<>();
}
List
<
Strategy
>
strategyList
=
new
ArrayList
<>();
for
(
N9eStrategy
n9eStrategy:
n9eStrategyList
)
{
strategyList
.
add
(
convert2Strategy
(
n9eStrategy
));
strategyList
.
add
(
convert2Strategy
(
n9eStrategy
,
notifyGroupMap
));
}
return
strategyList
;
}
public
static
Strategy
convert2Strategy
(
N9eStrategy
n9eStrategy
)
{
public
static
Strategy
convert2Strategy
(
N9eStrategy
n9eStrategy
,
Map
<
String
,
NotifyGroup
>
notifyGroupMap
)
{
if
(
n9eStrategy
==
null
)
{
return
null
;
}
if
(
ValidateUtils
.
isNull
(
notifyGroupMap
))
{
notifyGroupMap
=
new
HashMap
<>();
}
Map
<
Integer
,
NotifyGroup
>
newNotifyGroupMap
=
new
HashMap
<>(
notifyGroupMap
.
size
());
for
(
NotifyGroup
notifyGroup:
notifyGroupMap
.
values
())
{
newNotifyGroupMap
.
put
(
notifyGroup
.
getId
().
intValue
(),
notifyGroup
);
}
Strategy
strategy
=
new
Strategy
();
strategy
.
setId
(
n9eStrategy
.
getId
().
longValue
());
strategy
.
setName
(
n9eStrategy
.
getName
());
...
...
@@ -130,7 +156,17 @@ public class N9eConverter {
strategy
.
setStrategyFilterList
(
strategyFilterList
);
StrategyAction
strategyAction
=
new
StrategyAction
();
strategyAction
.
setNotifyGroup
(
ListUtils
.
strList2String
(
n9eStrategy
.
getNotify_group
()));
List
<
String
>
notifyGroups
=
new
ArrayList
<>();
for
(
Integer
id:
n9eStrategy
.
getNotify_group
())
{
NotifyGroup
notifyGroup
=
newNotifyGroupMap
.
get
(
id
);
if
(
ValidateUtils
.
isNull
(
notifyGroup
))
{
continue
;
}
notifyGroups
.
add
(
notifyGroup
.
getName
());
}
strategyAction
.
setNotifyGroup
(
ListUtils
.
strList2String
(
notifyGroups
));
strategyAction
.
setConverge
(
ListUtils
.
intList2String
(
n9eStrategy
.
getConverge
()));
strategyAction
.
setCallback
(
n9eStrategy
.
getCallback
());
strategy
.
setStrategyActionList
(
Arrays
.
asList
(
strategyAction
));
...
...
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/N9eService.java
浏览文件 @
06a97ef0
package
com.xiaojukeji.kafka.manager.monitor.component.n9e
;
import
com.alibaba.fastjson.JSON
;
import
com.github.benmanes.caffeine.cache.Cache
;
import
com.github.benmanes.caffeine.cache.Caffeine
;
import
com.xiaojukeji.kafka.manager.common.utils.HttpUtils
;
import
com.xiaojukeji.kafka.manager.common.utils.ValidateUtils
;
import
com.xiaojukeji.kafka.manager.monitor.component.AbstractMonitorService
;
...
...
@@ -14,6 +16,7 @@ import org.springframework.beans.factory.annotation.Value;
import
org.springframework.stereotype.Service
;
import
java.util.*
;
import
java.util.concurrent.TimeUnit
;
/**
* 夜莺
...
...
@@ -36,6 +39,13 @@ public class N9eService extends AbstractMonitorService {
@Value
(
"${monitor.n9e.sink.base-url}"
)
private
String
monitorN9eSinkBaseUrl
;
@Value
(
"${monitor.n9e.rdb.base-url}"
)
private
String
monitorN9eRdbBaseUrl
;
private
static
final
Cache
<
String
,
NotifyGroup
>
NOTIFY_GROUP_CACHE
=
Caffeine
.
newBuilder
()
.
maximumSize
(
100000
)
.
expireAfterWrite
(
60
,
TimeUnit
.
MINUTES
).
build
();
/**
* 告警策略
*/
...
...
@@ -75,7 +85,7 @@ public class N9eService extends AbstractMonitorService {
/**
* 告警组
*/
private
static
final
String
ALL_NOTIFY_GROUP_URL
=
"/api/rdb/teams/all"
;
private
static
final
String
ALL_NOTIFY_GROUP_URL
=
"/api/rdb/teams/all
?limit=10000
"
;
/**
* 监控策略的增删改查
...
...
@@ -86,7 +96,7 @@ public class N9eService extends AbstractMonitorService {
try
{
response
=
HttpUtils
.
postForString
(
monitorN9eMonBaseUrl
+
STRATEGY_ADD_URL
,
JSON
.
toJSONString
(
N9eConverter
.
convert2N9eStrategy
(
strategy
,
monitorN9eNid
)),
JSON
.
toJSONString
(
N9eConverter
.
convert2N9eStrategy
(
strategy
,
monitorN9eNid
,
getNotifyGroupsFromCacheFirst
()
)),
buildHeader
()
);
N9eResult
n9eResult
=
JSON
.
parseObject
(
response
,
N9eResult
.
class
);
...
...
@@ -94,7 +104,7 @@ public class N9eService extends AbstractMonitorService {
LOGGER
.
error
(
"create strategy failed, strategy:{} response:{}."
,
strategy
,
response
);
return
null
;
}
return
(
Integer
)
n9eResult
.
getDat
(
);
return
JSON
.
parseObject
(
JSON
.
toJSONString
(
n9eResult
.
getDat
())).
getInteger
(
"id"
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"create strategy failed, strategy:{} response:{}."
,
strategy
,
response
,
e
);
}
...
...
@@ -131,7 +141,7 @@ public class N9eService extends AbstractMonitorService {
try
{
response
=
HttpUtils
.
putForString
(
monitorN9eMonBaseUrl
+
STRATEGY_MODIFY_URL
,
JSON
.
toJSONString
(
N9eConverter
.
convert2N9eStrategy
(
strategy
,
monitorN9eNid
)),
JSON
.
toJSONString
(
N9eConverter
.
convert2N9eStrategy
(
strategy
,
monitorN9eNid
,
getNotifyGroupsFromCacheFirst
()
)),
buildHeader
()
);
N9eResult
n9eResult
=
JSON
.
parseObject
(
response
,
N9eResult
.
class
);
...
...
@@ -159,7 +169,7 @@ public class N9eService extends AbstractMonitorService {
LOGGER
.
error
(
"get monitor strategies failed, response:{}."
,
response
);
return
new
ArrayList
<>();
}
return
N9eConverter
.
convert2StrategyList
(
JSON
.
parseArray
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eStrategy
.
class
));
return
N9eConverter
.
convert2StrategyList
(
JSON
.
parseArray
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eStrategy
.
class
)
,
getNotifyGroupsFromCacheFirst
()
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"get monitor strategies failed, response:{}."
,
response
,
e
);
}
...
...
@@ -178,7 +188,7 @@ public class N9eService extends AbstractMonitorService {
LOGGER
.
error
(
"get monitor strategy failed, response:{}."
,
response
);
return
null
;
}
return
N9eConverter
.
convert2Strategy
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eStrategy
.
class
));
return
N9eConverter
.
convert2Strategy
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eStrategy
.
class
)
,
getNotifyGroupsFromCacheFirst
()
);
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"get monitor strategy failed, response:{}."
,
response
,
e
);
}
...
...
@@ -254,19 +264,34 @@ public class N9eService extends AbstractMonitorService {
public
List
<
NotifyGroup
>
getNotifyGroups
()
{
String
response
=
null
;
try
{
response
=
HttpUtils
.
get
(
monitorN9e
Mon
BaseUrl
+
ALL_NOTIFY_GROUP_URL
,
new
HashMap
<>(
0
),
buildHeader
());
response
=
HttpUtils
.
get
(
monitorN9e
Rdb
BaseUrl
+
ALL_NOTIFY_GROUP_URL
,
new
HashMap
<>(
0
),
buildHeader
());
N9eResult
n9eResult
=
JSON
.
parseObject
(
response
,
N9eResult
.
class
);
if
(!
ValidateUtils
.
isBlank
(
n9eResult
.
getErr
()))
{
LOGGER
.
error
(
"get notify group failed, response:{}."
,
response
);
return
new
ArrayList
<>();
}
return
N9eConverter
.
convert2NotifyGroupList
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eNotifyGroup
.
class
));
List
<
NotifyGroup
>
notifyGroupList
=
N9eConverter
.
convert2NotifyGroupList
(
JSON
.
parseObject
(
JSON
.
toJSONString
(
n9eResult
.
getDat
()),
N9eNotifyGroup
.
class
));
if
(
ValidateUtils
.
isEmptyList
(
notifyGroupList
))
{
return
new
ArrayList
<>();
}
for
(
NotifyGroup
notifyGroup:
notifyGroupList
)
{
NOTIFY_GROUP_CACHE
.
put
(
notifyGroup
.
getName
(),
notifyGroup
);
}
return
notifyGroupList
;
}
catch
(
Exception
e
)
{
LOGGER
.
error
(
"get notify group failed, response:{}."
,
response
,
e
);
}
return
new
ArrayList
<>();
}
private
Map
<
String
,
NotifyGroup
>
getNotifyGroupsFromCacheFirst
()
{
Map
<
String
,
NotifyGroup
>
notifyGroupMap
=
NOTIFY_GROUP_CACHE
.
asMap
();
if
(
ValidateUtils
.
isEmptyMap
(
notifyGroupMap
))
{
this
.
getNotifyGroups
();
}
return
NOTIFY_GROUP_CACHE
.
asMap
();
}
private
Map
<
String
,
String
>
buildHeader
()
{
Map
<
String
,
String
>
header
=
new
HashMap
<>(
2
);
header
.
put
(
"Content-Type"
,
"application/json"
);
...
...
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/entry/N9eStrategy.java
浏览文件 @
06a97ef0
...
...
@@ -36,11 +36,11 @@ public class N9eStrategy {
private
Integer
recovery_notify
;
private
List
<
N9eStrategyAlertUpgrade
>
alert_upgrade
=
new
ArrayList
<>()
;
private
N9eStrategyAlertUpgrade
alert_upgrade
;
private
List
<
Integer
>
converge
;
private
List
<
String
>
notify_group
;
private
List
<
Integer
>
notify_group
;
private
List
<
Integer
>
notify_user
;
...
...
@@ -142,11 +142,11 @@ public class N9eStrategy {
this
.
recovery_notify
=
recovery_notify
;
}
public
List
<
N9eStrategyAlertUpgrade
>
getAlert_upgrade
()
{
public
N9eStrategyAlertUpgrade
getAlert_upgrade
()
{
return
alert_upgrade
;
}
public
void
setAlert_upgrade
(
List
<
N9eStrategyAlertUpgrade
>
alert_upgrade
)
{
public
void
setAlert_upgrade
(
N9eStrategyAlertUpgrade
alert_upgrade
)
{
this
.
alert_upgrade
=
alert_upgrade
;
}
...
...
@@ -158,11 +158,11 @@ public class N9eStrategy {
this
.
converge
=
converge
;
}
public
List
<
String
>
getNotify_group
()
{
public
List
<
Integer
>
getNotify_group
()
{
return
notify_group
;
}
public
void
setNotify_group
(
List
<
String
>
notify_group
)
{
public
void
setNotify_group
(
List
<
Integer
>
notify_group
)
{
this
.
notify_group
=
notify_group
;
}
...
...
kafka-manager-extends/kafka-manager-monitor/src/main/java/com/xiaojukeji/kafka/manager/monitor/component/n9e/entry/N9eStrategyAlertUpgrade.java
浏览文件 @
06a97ef0
package
com.xiaojukeji.kafka.manager.monitor.component.n9e.entry
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
...
...
@@ -7,13 +8,13 @@ import java.util.List;
* @date 20/10/19
*/
public
class
N9eStrategyAlertUpgrade
{
private
Integer
duration
;
private
Integer
duration
=
60
;
private
Integer
level
;
private
Integer
level
=
1
;
private
List
<
Integer
>
users
;
private
List
<
Integer
>
users
=
new
ArrayList
<>()
;
private
List
<
String
>
groups
;
private
List
<
Integer
>
groups
=
new
ArrayList
<>()
;
public
Integer
getDuration
()
{
return
duration
;
...
...
@@ -39,11 +40,11 @@ public class N9eStrategyAlertUpgrade {
this
.
users
=
users
;
}
public
List
<
String
>
getGroups
()
{
public
List
<
Integer
>
getGroups
()
{
return
groups
;
}
public
void
setGroups
(
List
<
String
>
groups
)
{
public
void
setGroups
(
List
<
Integer
>
groups
)
{
this
.
groups
=
groups
;
}
...
...
kafka-manager-web/src/main/resources/application.yml
浏览文件 @
06a97ef0
...
...
@@ -49,11 +49,13 @@ monitor:
enabled
:
false
n9e
:
nid
:
2
user-token
:
123456
7890
user-token
:
123456
mon
:
base-url
:
http://127.0.0.1:8032
sink
:
base-url
:
http://127.0.0.1:8008
base-url
:
http://127.0.0.1:8006
rdb
:
base-url
:
http://127.0.0.1:80
notify
:
kafka
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录