Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
mica
mica
提交
4c9758f7
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 搜索 >>
提交
4c9758f7
编写于
8月 05, 2021
作者:
如梦技术
🐛
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
完善 mica-prometheus 模块。
上级
199bd8fc
变更
9
隐藏空白更改
内联
并排
Showing
9 changed file
with
253 addition
and
2 deletion
+253
-2
mica-bom/build.gradle
mica-bom/build.gradle
+1
-0
mica-prometheus/README.md
mica-prometheus/README.md
+12
-0
mica-prometheus/build.gradle
mica-prometheus/build.gradle
+6
-1
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/PrometheusApi.java
...in/java/net/dreamlu/mica/prometheus/sd/PrometheusApi.java
+61
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/PrometheusConfiguration.java
...t/dreamlu/mica/prometheus/sd/PrometheusConfiguration.java
+40
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/ReactivePrometheusApi.java
...net/dreamlu/mica/prometheus/sd/ReactivePrometheusApi.java
+58
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/ReactivePrometheusConfiguration.java
...u/mica/prometheus/sd/ReactivePrometheusConfiguration.java
+40
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/TargetGroup.java
...main/java/net/dreamlu/mica/prometheus/sd/TargetGroup.java
+35
-0
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/package-info.java
...ain/java/net/dreamlu/mica/prometheus/sd/package-info.java
+0
-1
未找到文件。
mica-bom/build.gradle
浏览文件 @
4c9758f7
...
...
@@ -34,6 +34,7 @@ dependencyManagement {
dependency
"net.dreamlu:mica-jetcache:${VERSION}"
dependency
"net.dreamlu:mica-lite:${VERSION}"
dependency
"net.dreamlu:mica-activerecord:${VERSION}"
dependency
"net.dreamlu:mica-prometheus:${VERSION}"
// commons
dependency
"com.google.code.findbugs:jsr305:${findbugsVersion}"
dependency
"io.swagger:swagger-annotations:${swaggerAnnotationsVersion}"
...
...
mica-prometheus/README.md
浏览文件 @
4c9758f7
...
...
@@ -17,3 +17,15 @@
```
groovy
compile
(
"net.dreamlu:mica-prometheus:${version}"
)
```
## 使用
```
yaml
-
job_name
:
micax-cloud
honor_timestamps
:
true
scrape_interval
:
15s
scrape_timeout
:
10s
metrics_path
:
/actuator/prometheus
scheme
:
http
http_sd_configs
:
-
url
:
'
http://{ip}:{port}/actuator/prometheus/sd'
```
mica-prometheus/build.gradle
浏览文件 @
4c9758f7
dependencies
{
implementation
"org.springframework.boot:spring-boot-actuator-autoconfigure"
api
"org.springframework.boot:spring-boot-starter"
api
"org.springframework.cloud:spring-cloud-commons"
compileOnly
"org.springframework:spring-web"
compileOnly
"org.springframework:spring-webflux"
compileOnly
"net.dreamlu:mica-auto:${micaAutoVersion}"
annotationProcessor
"net.dreamlu:mica-auto:${micaAutoVersion}"
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/PrometheusApi.java
0 → 100644
浏览文件 @
4c9758f7
/*
* 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.sd
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.auto.annotation.AutoIgnore
;
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
java.util.*
;
/**
* prometheus http sd
*
* @author L.cm
*/
@AutoIgnore
@RestController
@RequestMapping
(
"actuator/prometheus"
)
@RequiredArgsConstructor
public
class
PrometheusApi
{
private
final
DiscoveryClient
discoveryClient
;
@GetMapping
(
"sd"
)
public
List
<
TargetGroup
>
getList
()
{
List
<
String
>
serviceIdList
=
discoveryClient
.
getServices
();
if
(
serviceIdList
==
null
||
serviceIdList
.
isEmpty
())
{
return
Collections
.
emptyList
();
}
List
<
TargetGroup
>
targetGroupList
=
new
ArrayList
<>();
for
(
String
serviceId
:
serviceIdList
)
{
List
<
ServiceInstance
>
instanceList
=
discoveryClient
.
getInstances
(
serviceId
);
List
<
String
>
targets
=
new
ArrayList
<>();
for
(
ServiceInstance
instance
:
instanceList
)
{
targets
.
add
(
String
.
format
(
"%s:%d"
,
instance
.
getHost
(),
instance
.
getPort
()));
}
Map
<
String
,
String
>
labels
=
new
HashMap
<>(
2
);
labels
.
put
(
"__meta_prometheus_job"
,
serviceId
);
targetGroupList
.
add
(
new
TargetGroup
(
targets
,
labels
));
}
return
targetGroupList
;
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/PrometheusConfiguration.java
0 → 100644
浏览文件 @
4c9758f7
/*
* 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.sd
;
import
org.springframework.cloud.client.ConditionalOnBlockingDiscoveryEnabled
;
import
org.springframework.cloud.client.ConditionalOnDiscoveryEnabled
;
import
org.springframework.cloud.client.discovery.DiscoveryClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* prometheus http sd
*
* @author L.cm
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnDiscoveryEnabled
@ConditionalOnBlockingDiscoveryEnabled
public
class
PrometheusConfiguration
{
@Bean
public
PrometheusApi
prometheusApi
(
DiscoveryClient
discoveryClient
)
{
return
new
PrometheusApi
(
discoveryClient
);
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/ReactivePrometheusApi.java
0 → 100644
浏览文件 @
4c9758f7
/*
* 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.sd
;
import
lombok.RequiredArgsConstructor
;
import
net.dreamlu.mica.auto.annotation.AutoIgnore
;
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
reactor.core.publisher.Flux
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.stream.Collectors
;
/**
* prometheus http sd
*
* @author L.cm
*/
@AutoIgnore
@RestController
@RequestMapping
(
"actuator/prometheus"
)
@RequiredArgsConstructor
public
class
ReactivePrometheusApi
{
private
final
ReactiveDiscoveryClient
discoveryClient
;
@GetMapping
(
"sd"
)
public
Flux
<
TargetGroup
>
getList
()
{
return
discoveryClient
.
getServices
()
.
flatMap
(
discoveryClient:
:
getInstances
)
.
groupBy
(
ServiceInstance:
:
getServiceId
,
(
instance
)
->
String
.
format
(
"%s:%d"
,
instance
.
getHost
(),
instance
.
getPort
())
).
flatMap
(
instanceGrouped
->
{
Map
<
String
,
String
>
labels
=
new
HashMap
<>(
2
);
String
serviceId
=
instanceGrouped
.
key
();
labels
.
put
(
"__meta_prometheus_job"
,
serviceId
);
return
instanceGrouped
.
collect
(
Collectors
.
toList
()).
map
(
targets
->
new
TargetGroup
(
targets
,
labels
));
});
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/ReactivePrometheusConfiguration.java
0 → 100644
浏览文件 @
4c9758f7
/*
* 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.sd
;
import
org.springframework.cloud.client.ConditionalOnDiscoveryEnabled
;
import
org.springframework.cloud.client.ConditionalOnReactiveDiscoveryEnabled
;
import
org.springframework.cloud.client.discovery.ReactiveDiscoveryClient
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
/**
* prometheus http sd
*
* @author L.cm
*/
@Configuration
(
proxyBeanMethods
=
false
)
@ConditionalOnDiscoveryEnabled
@ConditionalOnReactiveDiscoveryEnabled
public
class
ReactivePrometheusConfiguration
{
@Bean
public
ReactivePrometheusApi
prometheusApi
(
ReactiveDiscoveryClient
discoveryClient
)
{
return
new
ReactivePrometheusApi
(
discoveryClient
);
}
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/TargetGroup.java
0 → 100644
浏览文件 @
4c9758f7
/*
* 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.sd
;
import
lombok.Getter
;
import
lombok.RequiredArgsConstructor
;
import
java.util.List
;
import
java.util.Map
;
/**
* prometheus http sd 模型
*
* @author L.cm
*/
@Getter
@RequiredArgsConstructor
public
class
TargetGroup
{
private
final
List
<
String
>
targets
;
private
final
Map
<
String
,
String
>
labels
;
}
mica-prometheus/src/main/java/net/dreamlu/mica/prometheus/sd/package-info.java
已删除
100644 → 0
浏览文件 @
199bd8fc
package
net.dreamlu.mica.prometheus.sd
;
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录