Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
22b64471
mica
项目概览
mica
/
mica
通知
10
Star
2
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
mica
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
22b64471
编写于
8月 17, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'mica-v2.4.x'
上级
d4b8b603
ebae5788
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
202 addition
and
21 deletion
+202
-21
build.gradle
build.gradle
+1
-1
mica-prometheus/README.md
mica-prometheus/README.md
+23
-2
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/config/PrometheusConfiguration.java
...u/mica/prometheus/api/config/PrometheusConfiguration.java
+10
-5
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/core/PrometheusApi.java
...a/net/dreamlu/mica/prometheus/api/core/PrometheusApi.java
+13
-4
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/core/ReactivePrometheusApi.java
...eamlu/mica/prometheus/api/core/ReactivePrometheusApi.java
+13
-4
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/pojo/AlertInfo.java
.../java/net/dreamlu/mica/prometheus/api/pojo/AlertInfo.java
+62
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/pojo/AlertMessage.java
...va/net/dreamlu/mica/prometheus/api/pojo/AlertMessage.java
+74
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/pojo/TargetGroup.java
...ava/net/dreamlu/mica/prometheus/api/pojo/TargetGroup.java
+1
-1
mica-xss/README.md
mica-xss/README.md
+1
-1
mica-xss/src/main/java/net/dreamlu/mica/xss/utils/XssUtil.java
...xss/src/main/java/net/dreamlu/mica/xss/utils/XssUtil.java
+4
-3
未找到文件。
build.gradle
浏览文件 @
22b64471
...
...
@@ -13,7 +13,7 @@ ext {
swaggerAnnotationsVersion
=
"1.5.22"
druidVersion
=
"1.2.6"
okhttpVersion
=
"3.14.9"
jsoupVersion
=
"1.14.
1
"
jsoupVersion
=
"1.14.
2
"
xxlJobVersion
=
"2.3.0"
lombokVersion
=
"1.18.20"
findbugsVersion
=
"3.0.2"
...
...
mica-prometheus/README.md
浏览文件 @
22b64471
...
...
@@ -18,7 +18,8 @@
compile
(
"net.dreamlu:mica-prometheus:${version}"
)
```
## 使用
## http-sd 使用
### 添加配置
```
yaml
-
job_name
:
micax-cloud
honor_timestamps
:
true
...
...
@@ -30,6 +31,26 @@ compile("net.dreamlu:mica-prometheus:${version}")
-
url
:
'
http://{ip}:{port}/actuator/prometheus/sd'
```
## 效果图
##
#
效果图
![
mica-prometheus 效果图
](
../docs/images/mica-prometheus-show.png
)
## alert web hook
### 添加配置
```
yaml
receivers
:
-
name
:
"
alerts"
webhook_configs
:
-
url
:
'
http://{ip}:{port}/actuator/prometheus/alerts'
send_resolved
:
true
```
### 自定义监听事件并处理
```
java
@Async
@EventListener
public
void
onAlertEvent
(
AlertMessage
message
)
{
// 处理 alert webhook message
}
```
\ No newline at end of file
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
sd
/PrometheusConfiguration.java
→
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
api/config
/PrometheusConfiguration.java
浏览文件 @
22b64471
...
...
@@ -14,14 +14,17 @@
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.
sd
;
package
net.dreamlu.mica.prometheus.
api.config
;
import
net.dreamlu.mica.prometheus.api.core.PrometheusApi
;
import
net.dreamlu.mica.prometheus.api.core.ReactivePrometheusApi
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.cloud.client.ConditionalOnDiscoveryEnabled
;
import
org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.cloud.client.discovery.ReactiveDiscoveryClient
;
import
org.springframework.context.ApplicationEventPublisher
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
...
...
@@ -41,8 +44,9 @@ public class PrometheusConfiguration {
public
static
class
PrometheusApiConfiguration
{
@Bean
public
PrometheusApi
prometheusApi
(
DiscoveryClient
discoveryClient
)
{
return
new
PrometheusApi
(
discoveryClient
);
public
PrometheusApi
prometheusApi
(
DiscoveryClient
discoveryClient
,
ApplicationEventPublisher
eventPublisher
)
{
return
new
PrometheusApi
(
discoveryClient
,
eventPublisher
);
}
}
...
...
@@ -54,8 +58,9 @@ public class PrometheusConfiguration {
public
static
class
ReactivePrometheusApiConfiguration
{
@Bean
public
ReactivePrometheusApi
reactivePrometheusApi
(
ReactiveDiscoveryClient
discoveryClient
)
{
return
new
ReactivePrometheusApi
(
discoveryClient
);
public
ReactivePrometheusApi
reactivePrometheusApi
(
ReactiveDiscoveryClient
discoveryClient
,
ApplicationEventPublisher
eventPublisher
)
{
return
new
ReactivePrometheusApi
(
discoveryClient
,
eventPublisher
);
}
}
...
...
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
sd
/PrometheusApi.java
→
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
api/core
/PrometheusApi.java
浏览文件 @
22b64471
...
...
@@ -14,15 +14,17 @@
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.
sd
;
package
net.dreamlu.mica.prometheus.
api.core
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.auto.annotation.AutoIgnore
;
import
net.dreamlu.mica.prometheus.api.pojo.AlertMessage
;
import
net.dreamlu.mica.prometheus.api.pojo.TargetGroup
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.
web.bind.annotation.GetMapping
;
import
org.springframework.
web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.
RestController
;
import
org.springframework.
context.ApplicationEventPublisher
;
import
org.springframework.
http.ResponseEntity
;
import
org.springframework.web.bind.annotation.
*
;
import
java.util.*
;
...
...
@@ -37,6 +39,7 @@ import java.util.*;
@RequiredArgsConstructor
public
class
PrometheusApi
{
private
final
DiscoveryClient
discoveryClient
;
private
final
ApplicationEventPublisher
eventPublisher
;
@GetMapping
(
"sd"
)
public
List
<
TargetGroup
>
getList
()
{
...
...
@@ -58,4 +61,10 @@ public class PrometheusApi {
return
targetGroupList
;
}
@PostMapping
(
"alerts"
)
public
ResponseEntity
<
Object
>
postAlerts
(
@RequestBody
AlertMessage
message
)
{
eventPublisher
.
publishEvent
(
message
);
return
ResponseEntity
.
ok
().
build
();
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
sd
/ReactivePrometheusApi.java
→
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
api/core
/ReactivePrometheusApi.java
浏览文件 @
22b64471
...
...
@@ -14,15 +14,17 @@
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.
sd
;
package
net.dreamlu.mica.prometheus.
api.core
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.auto.annotation.AutoIgnore
;
import
net.dreamlu.mica.prometheus.api.pojo.AlertMessage
;
import
net.dreamlu.mica.prometheus.api.pojo.TargetGroup
;
import
org.springframework.cloud.client.ServiceInstance
;
import
org.springframework.cloud.client.discovery.ReactiveDiscoveryClient
;
import
org.springframework.
web.bind.annotation.GetMapping
;
import
org.springframework.
web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.
RestController
;
import
org.springframework.
context.ApplicationEventPublisher
;
import
org.springframework.
http.ResponseEntity
;
import
org.springframework.web.bind.annotation.
*
;
import
reactor.core.publisher.Flux
;
import
java.util.HashMap
;
...
...
@@ -40,6 +42,7 @@ import java.util.stream.Collectors;
@RequiredArgsConstructor
public
class
ReactivePrometheusApi
{
private
final
ReactiveDiscoveryClient
discoveryClient
;
private
final
ApplicationEventPublisher
eventPublisher
;
@GetMapping
(
"sd"
)
public
Flux
<
TargetGroup
>
getList
()
{
...
...
@@ -55,4 +58,10 @@ public class ReactivePrometheusApi {
});
}
@PostMapping
(
"alerts"
)
public
ResponseEntity
<
Object
>
postAlerts
(
@RequestBody
AlertMessage
message
)
{
eventPublisher
.
publishEvent
(
message
);
return
ResponseEntity
.
ok
().
build
();
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/pojo/AlertInfo.java
0 → 100644
浏览文件 @
22b64471
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.api.pojo
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.time.OffsetDateTime
;
import
java.util.Map
;
/**
* 告警模型
*
* @author L.cm
*/
@Data
public
class
AlertInfo
implements
Serializable
{
/**
* 状态 resolved|firing
*/
private
String
status
;
/**
* 标签集合
*/
private
Map
<
String
,
String
>
labels
;
/**
* 注释集合
*/
private
Map
<
String
,
String
>
annotations
;
/**
* 开始时间
*/
private
OffsetDateTime
startsAt
;
/**
* 结束时间
*/
private
OffsetDateTime
endsAt
;
/**
* identifies the entity that caused the alert
*/
private
String
generatorURL
;
/**
* fingerprint to identify the alert
*/
private
String
fingerprint
;
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/api/pojo/AlertMessage.java
0 → 100644
浏览文件 @
22b64471
/*
* Copyright (c) 2019-2029, Dreamlu 卢春梦 (596392912@qq.com & www.dreamlu.net).
* <p>
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
* http://www.gnu.org/licenses/lgpl.html
* <p>
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.api.pojo
;
import
lombok.Data
;
import
java.io.Serializable
;
import
java.util.List
;
import
java.util.Map
;
/**
* alert hook
*
* @author L.cm
*/
@Data
public
class
AlertMessage
implements
Serializable
{
/**
* 版本号
*/
private
String
version
;
/**
* 由于 “max_alerts” 而截断了多少警报
*/
private
Integer
truncatedAlerts
;
/**
* 分组 key
*/
private
String
groupKey
;
/**
* 状态 resolved|firing
*/
private
String
status
;
/**
* 接收者
*/
private
String
receiver
;
/**
* 分组 labels
*/
private
Map
<
String
,
String
>
groupLabels
;
/**
* 通用 label
*/
private
Map
<
String
,
String
>
commonLabels
;
/**
* 通用注解
*/
private
Map
<
String
,
String
>
commonAnnotations
;
/**
* 扩展 url 地址
*/
private
String
externalURL
;
/**
* alerts
*/
private
List
<
AlertInfo
>
alerts
;
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
sd
/TargetGroup.java
→
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/
api/pojo
/TargetGroup.java
浏览文件 @
22b64471
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
net.dreamlu.mica.prometheus.
sd
;
package
net.dreamlu.mica.prometheus.
api.pojo
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
...
...
mica-xss/README.md
浏览文件 @
22b64471
...
...
@@ -58,7 +58,7 @@ public class MyXssCleaner implements XssCleaner {
// 2. 保留换行
.
prettyPrint
(
false
);
// 注意会被转义
String
escapedText
=
Jsoup
.
clean
(
html
,
""
,
XssUtil
.
WHITE_LIST
,
settings
);
String
escapedText
=
Jsoup
.
clean
(
html
,
""
,
XssUtil
.
HtmlWhitelist
.
INSTANCE
,
settings
);
// 3. 反转义
return
Entities
.
unescape
(
escapedText
);
}
...
...
mica-xss/src/main/java/net/dreamlu/mica/xss/utils/XssUtil.java
浏览文件 @
22b64471
...
...
@@ -32,7 +32,7 @@ import org.springframework.util.StringUtils;
* @author michael
*/
public
class
XssUtil
{
public
static
final
Html
Whitelist
WHITE_LIST
=
new
HtmlWhitelist
()
;
public
static
final
Html
SafeList
WHITE_LIST
=
HtmlSafeList
.
INSTANCE
;
/**
* trim 字符串
...
...
@@ -62,9 +62,10 @@ public class XssUtil {
*
* @author michael
*/
public
static
class
HtmlWhitelist
extends
org
.
jsoup
.
safety
.
Whitelist
{
public
static
class
HtmlSafeList
extends
org
.
jsoup
.
safety
.
Safelist
{
public
static
final
HtmlSafeList
INSTANCE
=
new
HtmlSafeList
();
public
Html
Whitel
ist
()
{
public
Html
SafeL
ist
()
{
addTags
(
"a"
,
"b"
,
"blockquote"
,
"br"
,
"caption"
,
"cite"
,
"code"
,
"col"
,
"colgroup"
,
"dd"
,
"div"
,
"span"
,
"embed"
,
"object"
,
"dl"
,
"dt"
,
"em"
,
"h1"
,
"h2"
,
"h3"
,
"h4"
,
"h5"
,
"h6"
,
"i"
,
"img"
,
"li"
,
"ol"
,
"p"
,
"pre"
,
"q"
,
"small"
,
"strike"
,
"strong"
,
"sub"
,
"sup"
,
"table"
,
"tbody"
,
"td"
,
"tfoot"
,
"th"
,
"thead"
,
"tr"
,
"u"
,
"ul"
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录