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
7498b554
Commit
7498b554
authored
Mar 12, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'enochAgent' into 'master'
Enoch agent See merge request
!1
parents
cf71cf88
8404fc51
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
308 additions
and
7 deletions
+308
-7
pom.xml
brave-spring-boot-starter/pom.xml
+1
-1
pom.xml
commons-core/pom.xml
+1
-1
pom.xml
commons-spring/pom.xml
+1
-1
pom.xml
enoch-agent-spring-boot-starter/pom.xml
+39
-0
AgentReportTask.java
.../java/cn/quantgroup/tech/enoch/agent/AgentReportTask.java
+38
-0
EnochAgentAutoConfiguration.java
...noch/agent/configuration/EnochAgentAutoConfiguration.java
+65
-0
EnochAgentProperties.java
.../tech/enoch/agent/configuration/EnochAgentProperties.java
+16
-0
IReportService.java
...cn/quantgroup/tech/enoch/agent/report/IReportService.java
+21
-0
ReportServiceImpl.java
...group/tech/enoch/agent/report/impl/ReportServiceImpl.java
+111
-0
spring.factories
...boot-starter/src/main/resources/META-INF/spring.factories
+2
-0
pom.xml
idgenerator-spring-boot-starter/pom.xml
+1
-1
package-lock.json
package-lock.json
+3
-0
pom.xml
pom.xml
+8
-2
pom.xml
shutdown-spring-boot-starter/pom.xml
+1
-1
No files found.
brave-spring-boot-starter/pom.xml
View file @
7498b554
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
commons-core/pom.xml
View file @
7498b554
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
commons-spring/pom.xml
View file @
7498b554
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
enoch-agent-spring-boot-starter/pom.xml
0 → 100644
View file @
7498b554
<?xml version="1.0" encoding="UTF-8"?>
<project
xmlns=
"http://maven.apache.org/POM/4.0.0"
xmlns:xsi=
"http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation=
"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
>
<modelVersion>
4.0.0
</modelVersion>
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.4
</version>
</parent>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
<properties>
<java.version>
1.8
</java.version>
</properties>
<dependencies>
<dependency>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-starter
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework.kafka
</groupId>
<artifactId>
spring-kafka
</artifactId>
<version>
2.2.4.RELEASE
</version>
</dependency>
<dependency>
<groupId>
org.projectlombok
</groupId>
<artifactId>
lombok
</artifactId>
<optional>
true
</optional>
</dependency>
<dependency>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-spring
</artifactId>
</dependency>
</dependencies>
</project>
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/AgentReportTask.java
0 → 100644
View file @
7498b554
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
;
import
cn.quantgroup.tech.enoch.agent.report.IReportService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.context.annotation.Lazy
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Lazy
@Component
@EnableScheduling
public
class
AgentReportTask
{
@Autowired
private
IReportService
reportService
;
/**
* 1毫秒采集一次数据
*/
@Scheduled
(
fixedRate
=
1000
)
public
void
collect
()
{
reportService
.
collect
();
}
/**
* 1毫秒上报一次数据
*/
@Scheduled
(
fixedRate
=
1000
)
public
void
report
()
{
reportService
.
report
();
}
}
\ No newline at end of file
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/configuration/EnochAgentAutoConfiguration.java
0 → 100644
View file @
7498b554
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
.
configuration
;
import
cn.quantgroup.tech.enoch.agent.AgentReportTask
;
import
lombok.extern.slf4j.Slf4j
;
import
org.apache.kafka.clients.producer.ProducerConfig
;
import
org.apache.kafka.common.serialization.StringSerializer
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnBean
;
import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.ComponentScan
;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.kafka.core.DefaultKafkaProducerFactory
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.kafka.core.ProducerFactory
;
import
org.springframework.scheduling.annotation.SchedulingConfigurer
;
import
org.springframework.scheduling.config.ScheduledTaskRegistrar
;
import
java.util.HashMap
;
import
java.util.concurrent.ScheduledThreadPoolExecutor
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Slf4j
@Configuration
@ComponentScan
(
basePackageClasses
=
AgentReportTask
.
class
)
@EnableConfigurationProperties
(
EnochAgentProperties
.
class
)
@ConditionalOnProperty
(
prefix
=
"tech.enoch"
,
name
=
"enabled"
,
havingValue
=
"true"
)
public
class
EnochAgentAutoConfiguration
{
@Autowired
private
EnochAgentProperties
enochAgentProperties
;
@Autowired
private
AgentReportTask
agentReportTask
;
@Bean
public
ProducerFactory
<
String
,
String
>
producerFactory
()
{
HashMap
<
String
,
Object
>
config
=
new
HashMap
<>(
16
);
config
.
put
(
ProducerConfig
.
BOOTSTRAP_SERVERS_CONFIG
,
enochAgentProperties
.
getKafkaHost
());
config
.
put
(
ProducerConfig
.
KEY_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
config
.
put
(
ProducerConfig
.
VALUE_SERIALIZER_CLASS_CONFIG
,
StringSerializer
.
class
);
return
new
DefaultKafkaProducerFactory
(
config
);
}
@Bean
@ConditionalOnBean
(
ProducerFactory
.
class
)
public
KafkaTemplate
<
String
,
String
>
kafkaTemplate
(
ProducerFactory
<
String
,
String
>
producerFactory
)
{
return
new
KafkaTemplate
<>(
producerFactory
);
}
@Configuration
public
static
class
ScheduleConfig
implements
SchedulingConfigurer
{
@Override
public
void
configureTasks
(
ScheduledTaskRegistrar
taskRegistrar
)
{
ScheduledThreadPoolExecutor
executor
=
new
ScheduledThreadPoolExecutor
(
2
);
taskRegistrar
.
setScheduler
(
executor
);
}
}
}
\ No newline at end of file
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/configuration/EnochAgentProperties.java
0 → 100644
View file @
7498b554
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
.
configuration
;
import
lombok.Data
;
import
org.springframework.boot.context.properties.ConfigurationProperties
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Data
@ConfigurationProperties
(
prefix
=
"tech.enoch"
)
public
class
EnochAgentProperties
{
private
String
kafkaHost
;
private
String
kafkaTopic
;
}
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/report/IReportService.java
0 → 100644
View file @
7498b554
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
.
report
;
/**
* @author: amen
* @date: 2019-02-26
*/
public
interface
IReportService
{
/**
* 上报节点信息
*
* @return
*/
void
report
();
/**
* 采集节点信息
*/
void
collect
();
}
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/report/impl/ReportServiceImpl.java
0 → 100644
View file @
7498b554
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
.
report
.
impl
;
import
cn.quantgroup.tech.enoch.agent.configuration.EnochAgentProperties
;
import
cn.quantgroup.tech.enoch.agent.report.IReportService
;
import
com.alibaba.fastjson.JSON
;
import
com.alibaba.fastjson.serializer.SerializerFeature
;
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.health.Health
;
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
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Slf4j
@Service
public
class
ReportServiceImpl
implements
IReportService
{
@Autowired
private
HealthMvcEndpoint
healthMvcEndpoint
;
@Autowired
private
MetricsEndpoint
metricsEndpoint
;
@Autowired
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
@Autowired
private
EnochAgentProperties
enochAgentProperties
;
@Autowired
private
EnvironmentMvcEndpoint
environmentMvcEndpoint
;
@Autowired
private
MetricReaderPublicMetrics
metricReaderPublicMetrics
;
private
final
ArrayBlockingQueue
<
Map
<
String
,
Object
>>
arrayBlockingQueue
=
new
ArrayBlockingQueue
<>(
600
);
private
final
ApplicationInfo
applicationInfo
=
new
ApplicationInfo
();
@Override
public
void
report
()
{
int
size
=
arrayBlockingQueue
.
size
();
if
(
size
<=
0
)
{
return
;
}
List
<
Map
<
String
,
Object
>>
slice
=
new
ArrayList
<>(
size
);
arrayBlockingQueue
.
drainTo
(
slice
,
size
);
Map
<
String
,
Object
>
pushPackage
=
new
HashMap
<>(
6
);
if
(
StringUtils
.
isBlank
(
applicationInfo
.
getAppName
()))
{
initApplicationInfo
();
}
pushPackage
.
put
(
"ip"
,
applicationInfo
.
getIp
());
pushPackage
.
put
(
"appName"
,
applicationInfo
.
getAppName
());
pushPackage
.
put
(
"endPoints"
,
slice
);
//todo 若发kafka失败,添加本地持久化操作,待下次提交时,一同push
kafkaTemplate
.
send
(
enochAgentProperties
.
getKafkaTopic
(),
JSON
.
toJSONString
(
pushPackage
,
SerializerFeature
.
DisableCircularReferenceDetect
));
}
@Override
public
void
collect
()
{
HashMap
<
String
,
Object
>
endPoints
=
new
HashMap
<>(
16
);
Health
health
=
healthMvcEndpoint
.
getDelegate
().
invoke
();
Health
.
status
(
health
.
getStatus
()).
build
();
endPoints
.
put
(
"health"
,
health
);
endPoints
.
put
(
"metrics"
,
metricsEndpoint
.
invoke
());
endPoints
.
put
(
"timestamp"
,
System
.
currentTimeMillis
());
try
{
arrayBlockingQueue
.
put
(
endPoints
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"enoch.agent collect data error: {}"
,
e
);
}
}
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"
));
return
applicationInfo
;
}
@PostConstruct
public
void
init
(){
//注释掉不需要收集器
metricsEndpoint
.
unregisterPublicMetrics
(
metricReaderPublicMetrics
);
}
@Data
public
static
class
ApplicationInfo
{
private
String
ip
;
private
String
appName
;
}
}
enoch-agent-spring-boot-starter/src/main/resources/META-INF/spring.factories
0 → 100644
View file @
7498b554
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.quantgroup.tech.enoch.agent.configuration.EnochAgentAutoConfiguration
idgenerator-spring-boot-starter/pom.xml
View file @
7498b554
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
package-lock.json
0 → 100644
View file @
7498b554
{
"lockfileVersion"
:
1
}
pom.xml
View file @
7498b554
...
...
@@ -6,7 +6,7 @@
<modelVersion>
4.0.0
</modelVersion>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
commons-parent
</artifactId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
<parent>
<groupId>
org.springframework.boot
</groupId>
...
...
@@ -20,6 +20,7 @@
<module>
shutdown-spring-boot-starter
</module>
<module>
brave-spring-boot-starter
</module>
<module>
idgenerator-spring-boot-starter
</module>
<module>
enoch-agent-spring-boot-starter
</module>
</modules>
<packaging>
pom
</packaging>
...
...
@@ -33,7 +34,7 @@
<lombok.version>
1.16.20
</lombok.version>
<guava.version>
23.0
</guava.version>
<apollo.client.version>
0.10.2
</apollo.client.version>
<common.parent.version>
0.2.5.
1
</common.parent.version>
<common.parent.version>
0.2.5.
4
</common.parent.version>
</properties>
<dependencies>
...
...
@@ -89,6 +90,11 @@
<artifactId>
idgenerator-spring-boot-starter
</artifactId>
<version>
${common.parent.version}
</version>
</dependency>
<dependency>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
<version>
${common.parent.version}
</version>
</dependency>
</dependencies>
</dependencyManagement>
...
...
shutdown-spring-boot-starter/pom.xml
View file @
7498b554
...
...
@@ -5,7 +5,7 @@
<parent>
<artifactId>
commons-parent
</artifactId>
<groupId>
cn.quantgroup
</groupId>
<version>
0.2.5.
1
</version>
<version>
0.2.5.
4
</version>
</parent>
<modelVersion>
4.0.0
</modelVersion>
...
...
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