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
101a83f0
Commit
101a83f0
authored
Feb 27, 2019
by
Node- 门 忠鑫
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
# 添加enochAgent
parent
cf71cf88
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
293 additions
and
0 deletions
+293
-0
.gitignore
enoch-agent-spring-boot-starter/.gitignore
+25
-0
pom.xml
enoch-agent-spring-boot-starter/pom.xml
+51
-0
TimerTask.java
...c/main/java/cn/quantgroup/tech/enoch/agent/TimerTask.java
+34
-0
EnochAgentAutoConfiguration.java
...noch/agent/configuration/EnochAgentAutoConfiguration.java
+50
-0
EnochAgentProperties.java
.../tech/enoch/agent/configuration/EnochAgentProperties.java
+17
-0
IReportService.java
...cn/quantgroup/tech/enoch/agent/report/IReportService.java
+21
-0
ReportServiceImpl.java
...group/tech/enoch/agent/report/impl/ReportServiceImpl.java
+92
-0
spring.factories
...boot-starter/src/main/resources/META-INF/spring.factories
+2
-0
pom.xml
pom.xml
+1
-0
No files found.
enoch-agent-spring-boot-starter/.gitignore
0 → 100644
View file @
101a83f0
/target/
!.mvn/wrapper/maven-wrapper.jar
### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
/build/
enoch-agent-spring-boot-starter/pom.xml
0 → 100644
View file @
101a83f0
<?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.1
</version>
</parent>
<groupId>
cn.quantgroup
</groupId>
<artifactId>
enoch-agent-spring-boot-starter
</artifactId>
<version>
0.0.1-SNAPSHOT
</version>
<name>
enoch-agent-spring-boot-starter
</name>
<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>
<build>
<plugins>
<plugin>
<groupId>
org.springframework.boot
</groupId>
<artifactId>
spring-boot-maven-plugin
</artifactId>
</plugin>
</plugins>
</build>
</project>
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/TimerTask.java
0 → 100644
View file @
101a83f0
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
;
import
cn.quantgroup.tech.enoch.agent.report.IReportService
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.scheduling.annotation.EnableScheduling
;
import
org.springframework.scheduling.annotation.Scheduled
;
import
org.springframework.stereotype.Component
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Component
@EnableScheduling
public
class
TimerTask
{
@Autowired
private
IReportService
reportService
;
/**
* 1毫秒采集一次数据
*/
@Scheduled
(
fixedRate
=
1000
)
public
void
collect
()
{
reportService
.
collect
();
}
/**
* 30毫秒上报一次数据
*/
@Scheduled
(
fixedRate
=
30000
)
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 @
101a83f0
package
cn
.
quantgroup
.
tech
.
enoch
.
agent
.
configuration
;
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.ConditionalOnMissingBean
;
import
org.springframework.boot.context.properties.EnableConfigurationProperties
;
import
org.springframework.context.annotation.Bean
;
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
java.util.HashMap
;
/**
* @author: amen
* @date: 2019-02-26
*/
@Slf4j
@Configuration
@EnableConfigurationProperties
({
EnochAgentProperties
.
class
})
public
class
EnochAgentAutoConfiguration
{
@Autowired
private
EnochAgentProperties
enochAgentProperties
;
@Bean
@ConditionalOnBean
(
EnochAgentProperties
.
class
)
@ConditionalOnMissingBean
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
);
}
}
\ 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 @
101a83f0
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
;
private
Long
reportRate
=
30000L
;
}
enoch-agent-spring-boot-starter/src/main/java/cn/quantgroup/tech/enoch/agent/report/IReportService.java
0 → 100644
View file @
101a83f0
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 @
101a83f0
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
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.HealthEndpoint
;
import
org.springframework.boot.actuate.endpoint.MetricsEndpoint
;
import
org.springframework.boot.actuate.endpoint.mvc.EnvironmentMvcEndpoint
;
import
org.springframework.kafka.core.KafkaTemplate
;
import
org.springframework.stereotype.Service
;
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
HealthEndpoint
healthEndpoint
;
@Autowired
private
MetricsEndpoint
metricsEndpoint
;
@Autowired
private
KafkaTemplate
<
String
,
String
>
kafkaTemplate
;
@Autowired
private
EnochAgentProperties
enochAgentProperties
;
@Autowired
private
EnvironmentMvcEndpoint
environmentMvcEndpoint
;
private
final
ArrayBlockingQueue
<
Map
<
String
,
Object
>>
arrayBlockingQueue
=
new
ArrayBlockingQueue
<>(
600
);
private
final
ApplicationInfo
applicationInfo
=
new
ApplicationInfo
();
@Override
public
void
report
()
{
log
.
info
(
"enoch.agent report"
);
int
size
=
arrayBlockingQueue
.
size
();
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
));
}
@Override
public
void
collect
()
{
log
.
info
(
"enoch.agent collect"
);
//todo 添加timestamp
HashMap
<
String
,
Object
>
endPoints
=
new
HashMap
<>(
16
);
endPoints
.
put
(
"health"
,
healthEndpoint
.
invoke
());
endPoints
.
put
(
"metrics"
,
metricsEndpoint
.
invoke
());
endPoints
.
put
(
"timestamp"
,
System
.
nanoTime
());
try
{
arrayBlockingQueue
.
put
(
endPoints
);
}
catch
(
InterruptedException
e
)
{
log
.
error
(
"enoch.agent collect data error: {}"
,
e
);
}
}
private
ApplicationInfo
initApplicationInfo
()
{
applicationInfo
.
setAppName
(
environmentMvcEndpoint
.
value
(
"spring.application.name"
).
toString
());
applicationInfo
.
setIp
(
environmentMvcEndpoint
.
value
(
"spring.cloud.client.ipAddress"
).
toString
());
return
applicationInfo
;
}
@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 @
101a83f0
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
cn.quantgroup.tech.enoch.agent.configuration.EnochAgentAutoConfiguration
\ No newline at end of file
pom.xml
View file @
101a83f0
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
<module>
shutdown-spring-boot-starter
</module>
<module>
shutdown-spring-boot-starter
</module>
<module>
brave-spring-boot-starter
</module>
<module>
brave-spring-boot-starter
</module>
<module>
idgenerator-spring-boot-starter
</module>
<module>
idgenerator-spring-boot-starter
</module>
<module>
enoch-agent-spring-boot-starter
</module>
</modules>
</modules>
<packaging>
pom
</packaging>
<packaging>
pom
</packaging>
...
...
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