Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
commons
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
3
Merge Requests
3
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DevOps
commons
Commits
8b0fbdb6
Commit
8b0fbdb6
authored
Mar 14, 2022
by
孙 楠
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature-2.6.4' of
http://git.quantgroup.cn/DevOps/commons
into feature-2.6.4
parents
b9f07542
bd8ee779
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
23 deletions
+20
-23
AgentReportServiceImpl.java
.../tech/enoch/agent/report/impl/AgentReportServiceImpl.java
+20
-23
No files found.
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/report/impl/AgentReportServiceImpl.java
View file @
8b0fbdb6
...
...
@@ -2,26 +2,25 @@ package cn.quantgroup.tech.enoch.agent.report.impl;
import
cn.quantgroup.tech.enoch.agent.configuration.EnochAgentProperties
;
import
cn.quantgroup.tech.enoch.agent.report.IAgentReportService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
import
com.google.gson.Gson
;
import
lombok.Data
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.commons.lang3.StringUtils
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.actuate.endpoint.MetricReaderPublicMetrics
;
import
org.springframework.boot.actuate.endpoint.MetricsEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.HealthMvcEndpoint
;
import
org.springframework.boot.actuate.env.EnvironmentEndpoint
;
import
org.springframework.boot.actuate.health.Health
;
import
org.springframework.boot.actuate.health.HealthComponent
;
import
org.springframework.boot.actuate.health.HealthEndpoint
;
import
org.springframework.boot.actuate.metrics.MetricsEndpoint
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Service
;
import
javax.annotation.PostConstruct
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.concurrent.ArrayBlockingQueue
;
import
java.util.stream.Collectors
;
/**
* @author: amen
...
...
@@ -33,7 +32,7 @@ public class AgentReportServiceImpl implements IAgentReportService {
@Autowired
private
Health
Mvc
Endpoint
healthMvcEndpoint
;
private
HealthEndpoint
healthMvcEndpoint
;
@Autowired
private
MetricsEndpoint
metricsEndpoint
;
...
...
@@ -45,10 +44,10 @@ public class AgentReportServiceImpl implements IAgentReportService {
private
EnochAgentProperties
enochAgentProperties
;
@Autowired
private
Environment
MvcEndpoint
environmentMvc
Endpoint
;
private
Environment
Endpoint
environment
Endpoint
;
@Autowired
private
MetricReaderPublicMetrics
metricReaderPublicMetrics
;
private
Gson
gson
;
private
final
ArrayBlockingQueue
<
Map
<
String
,
Object
>>
arrayBlockingQueue
=
new
ArrayBlockingQueue
<>(
600
);
...
...
@@ -71,16 +70,20 @@ public class AgentReportServiceImpl implements IAgentReportService {
pushPackage
.
put
(
"appName"
,
applicationInfo
.
getAppName
());
pushPackage
.
put
(
"endPoints"
,
slice
);
//todo 若发kafka失败,添加本地持久化操作,待下次提交时,一同push
kafkaTemplate
.
send
(
enochAgentProperties
.
getKafkaTopic
(),
JSON
.
toJSONString
(
pushPackage
,
SerializerFeature
.
DisableCircularReferenceDetect
));
kafkaTemplate
.
send
(
enochAgentProperties
.
getKafkaTopic
(),
gson
.
toJson
(
pushPackage
));
}
@Override
public
void
collect
()
{
HashMap
<
String
,
Object
>
endPoints
=
new
HashMap
<>(
16
);
Health
health
=
healthMvcEndpoint
.
getDelegate
().
invoke
();
HealthComponent
health
=
healthMvcEndpoint
.
health
();
Map
<
String
,
List
<
MetricsEndpoint
.
Sample
>>
metricCollect
=
metricsEndpoint
.
listNames
().
getNames
().
stream
().
collect
(
Collectors
.
toMap
(
i
->
i
,
j
->
metricsEndpoint
.
metric
(
j
,
null
).
getMeasurements
()));
Health
.
status
(
health
.
getStatus
()).
build
();
endPoints
.
put
(
"health"
,
health
);
endPoints
.
put
(
"metrics"
,
metric
sEndpoint
.
invoke
()
);
endPoints
.
put
(
"metrics"
,
metric
Collect
);
endPoints
.
put
(
"timestamp"
,
System
.
currentTimeMillis
());
try
{
arrayBlockingQueue
.
put
(
endPoints
);
...
...
@@ -90,19 +93,13 @@ public class AgentReportServiceImpl implements IAgentReportService {
}
private
ApplicationInfo
initApplicationInfo
()
{
Map
<
String
,
String
>
appName
=
(
HashMap
)
environmentMvcEndpoint
.
value
(
"spring.application.name"
);
Map
<
String
,
String
>
ip
=
(
HashMap
)
environmentMvcEndpoint
.
value
(
"spring.cloud.client.ipAddress"
);
applicationInfo
.
setAppName
(
appName
.
get
(
"spring.application.name"
)
);
applicationInfo
.
setIp
(
ip
.
get
(
"spring.cloud.client.ipAddress"
)
);
String
appName
=
(
String
)
environmentEndpoint
.
environmentEntry
(
"spring.application.name"
).
getProperty
().
getValue
(
);
String
ip
=(
String
)
environmentEndpoint
.
environmentEntry
(
"spring.cloud.client.ipAddress"
).
getProperty
().
getValue
(
);
applicationInfo
.
setAppName
(
appName
);
applicationInfo
.
setIp
(
ip
);
return
applicationInfo
;
}
@PostConstruct
public
void
init
(){
//注释掉不需要收集器
metricsEndpoint
.
unregisterPublicMetrics
(
metricReaderPublicMetrics
);
}
@Data
public
static
class
ApplicationInfo
{
private
String
ip
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment