commit
affefae5e6
13 changed files with 452 additions and 0 deletions
-
40.classpath
-
2.gitignore
-
23.project
-
5.settings/org.eclipse.core.resources.prefs
-
9.settings/org.eclipse.jdt.core.prefs
-
4.settings/org.eclipse.m2e.core.prefs
-
1README.md
-
149pom.xml
-
26src/main/java/com/bfd/manager/Application.java
-
108src/main/java/com/bfd/manager/alter/AdminNotifier.java
-
29src/main/resources/application.yml
-
36src/main/resources/logback-spring.xml
-
20src/test/java/com/bfd/AppTest.java
@ -0,0 +1,40 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<classpath> |
||||
|
<classpathentry kind="src" output="target/classes" path="src/main/java"> |
||||
|
<attributes> |
||||
|
<attribute name="optional" value="true"/> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> |
||||
|
<attributes> |
||||
|
<attribute name="optional" value="true"/> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
<attribute name="test" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"> |
||||
|
<attributes> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
<attribute name="optional" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> |
||||
|
<attributes> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> |
||||
|
<attributes> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> |
||||
|
<attributes> |
||||
|
<attribute name="maven.pomderived" value="true"/> |
||||
|
<attribute name="test" value="true"/> |
||||
|
<attribute name="optional" value="true"/> |
||||
|
</attributes> |
||||
|
</classpathentry> |
||||
|
<classpathentry kind="output" path="target/classes"/> |
||||
|
</classpath> |
@ -0,0 +1,2 @@ |
|||||
|
/target/ |
||||
|
/logs/ |
@ -0,0 +1,23 @@ |
|||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||
|
<projectDescription> |
||||
|
<name>appliction_manager</name> |
||||
|
<comment></comment> |
||||
|
<projects> |
||||
|
</projects> |
||||
|
<buildSpec> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.jdt.core.javabuilder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
<buildCommand> |
||||
|
<name>org.eclipse.m2e.core.maven2Builder</name> |
||||
|
<arguments> |
||||
|
</arguments> |
||||
|
</buildCommand> |
||||
|
</buildSpec> |
||||
|
<natures> |
||||
|
<nature>org.eclipse.jdt.core.javanature</nature> |
||||
|
<nature>org.eclipse.m2e.core.maven2Nature</nature> |
||||
|
</natures> |
||||
|
</projectDescription> |
@ -0,0 +1,5 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
encoding//src/main/java=UTF-8 |
||||
|
encoding//src/main/resources=UTF-8 |
||||
|
encoding//src/test/java=UTF-8 |
||||
|
encoding/<project>=UTF-8 |
@ -0,0 +1,9 @@ |
|||||
|
eclipse.preferences.version=1 |
||||
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate |
||||
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 |
||||
|
org.eclipse.jdt.core.compiler.compliance=1.8 |
||||
|
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled |
||||
|
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning |
||||
|
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore |
||||
|
org.eclipse.jdt.core.compiler.release=disabled |
||||
|
org.eclipse.jdt.core.compiler.source=1.8 |
@ -0,0 +1,4 @@ |
|||||
|
activeProfiles= |
||||
|
eclipse.preferences.version=1 |
||||
|
resolveWorkspaceProjects=true |
||||
|
version=1 |
@ -0,0 +1 @@ |
|||||
|
应用管理中心 |
@ -0,0 +1,149 @@ |
|||||
|
<?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> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-parent</artifactId> |
||||
|
<version>2.2.4.RELEASE</version> |
||||
|
</parent> |
||||
|
<groupId>com.bfd</groupId> |
||||
|
<artifactId>appliction_manager</artifactId> |
||||
|
<version>0.0.1-SNAPSHOT</version> |
||||
|
|
||||
|
<name>appliction_manager</name> |
||||
|
<!-- FIXME change it to the project's website --> |
||||
|
<url>http://www.example.com</url> |
||||
|
|
||||
|
<properties> |
||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> |
||||
|
<maven.compiler.source>1.8</maven.compiler.source> |
||||
|
<maven.compiler.target>1.8</maven.compiler.target> |
||||
|
</properties> |
||||
|
|
||||
|
<dependencies> |
||||
|
<dependency> |
||||
|
<groupId>junit</groupId> |
||||
|
<artifactId>junit</artifactId> |
||||
|
<version>4.11</version> |
||||
|
<scope>test</scope> |
||||
|
</dependency> |
||||
|
<!-- https://mvnrepository.com/artifact/de.codecentric/spring-boot-admin-starter-server --> |
||||
|
<dependency> |
||||
|
<groupId>de.codecentric</groupId> |
||||
|
<artifactId>spring-boot-admin-starter-server</artifactId> |
||||
|
<version>2.2.4</version> |
||||
|
</dependency> |
||||
|
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-mail --> |
||||
|
<dependency> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-starter-mail</artifactId> |
||||
|
<version>2.2.4.RELEASE</version> |
||||
|
</dependency> |
||||
|
<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok --> |
||||
|
<dependency> |
||||
|
<groupId>org.projectlombok</groupId> |
||||
|
<artifactId>lombok</artifactId> |
||||
|
<version>1.18.16</version> |
||||
|
<scope>provided</scope> |
||||
|
</dependency> |
||||
|
<dependency> |
||||
|
<groupId>com.alibaba</groupId> |
||||
|
<artifactId>fastjson</artifactId> |
||||
|
<version>2.0.17</version> |
||||
|
</dependency> |
||||
|
|
||||
|
</dependencies> |
||||
|
|
||||
|
<build> |
||||
|
<!-- <pluginManagement> --><!-- lock down plugins versions to avoid using Maven defaults (may be moved |
||||
|
to parent pom) --> |
||||
|
<plugins> |
||||
|
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle --> |
||||
|
<plugin> |
||||
|
<artifactId>maven-clean-plugin</artifactId> |
||||
|
<version>3.1.0</version> |
||||
|
</plugin> |
||||
|
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging --> |
||||
|
<plugin> |
||||
|
<artifactId>maven-resources-plugin</artifactId> |
||||
|
<version>3.0.2</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-compiler-plugin</artifactId> |
||||
|
<version>3.8.0</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-surefire-plugin</artifactId> |
||||
|
<version>2.22.1</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-jar-plugin</artifactId> |
||||
|
<version>3.0.2</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-install-plugin</artifactId> |
||||
|
<version>2.5.2</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-deploy-plugin</artifactId> |
||||
|
<version>2.8.2</version> |
||||
|
</plugin> |
||||
|
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle --> |
||||
|
<plugin> |
||||
|
<artifactId>maven-site-plugin</artifactId> |
||||
|
<version>3.7.1</version> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<artifactId>maven-project-info-reports-plugin</artifactId> |
||||
|
<version>3.0.0</version> |
||||
|
</plugin> |
||||
|
<!-- spring-boot-maven-plugin插件就是打包spring boot应用的 --> |
||||
|
|
||||
|
<plugin> |
||||
|
<groupId>org.springframework.boot</groupId> |
||||
|
<artifactId>spring-boot-maven-plugin</artifactId> |
||||
|
<configuration> |
||||
|
<mainClass>com.bfd.manager.Application</mainClass> |
||||
|
<layout>ZIP</layout> |
||||
|
<includes> |
||||
|
<include> |
||||
|
<groupId>${project.groupId}</groupId> |
||||
|
<artifactId>${project.artifactId}</artifactId> |
||||
|
</include> |
||||
|
</includes> |
||||
|
</configuration> |
||||
|
<executions> |
||||
|
<execution> |
||||
|
<goals> |
||||
|
<goal>repackage</goal> |
||||
|
</goals> |
||||
|
</execution> |
||||
|
</executions> |
||||
|
</plugin> |
||||
|
<plugin> |
||||
|
<groupId>org.apache.maven.plugins</groupId> |
||||
|
<artifactId>maven-dependency-plugin</artifactId> |
||||
|
<version>3.1.1</version> |
||||
|
<executions> |
||||
|
<execution> |
||||
|
<id>copy</id> |
||||
|
<phase>package</phase> |
||||
|
<goals> |
||||
|
<goal>copy-dependencies</goal> |
||||
|
</goals> |
||||
|
<configuration> |
||||
|
<type>jar</type> |
||||
|
<includeTypes>jar</includeTypes> |
||||
|
<includeScope>runtime</includeScope> |
||||
|
<outputDirectory>${project.build.directory}/libs</outputDirectory> |
||||
|
</configuration> |
||||
|
</execution> |
||||
|
</executions> |
||||
|
</plugin> |
||||
|
</plugins> |
||||
|
<!-- </pluginManagement> --> |
||||
|
</build> |
||||
|
</project> |
@ -0,0 +1,26 @@ |
|||||
|
package com.bfd.manager; |
||||
|
|
||||
|
|
||||
|
|
||||
|
import org.springframework.boot.SpringApplication; |
||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication; |
||||
|
|
||||
|
import de.codecentric.boot.admin.server.config.EnableAdminServer; |
||||
|
|
||||
|
/** |
||||
|
* 主入口 |
||||
|
* |
||||
|
* @author jian.mao |
||||
|
* @date 2023年7月4日 |
||||
|
* @description |
||||
|
*/ |
||||
|
@SpringBootApplication |
||||
|
@EnableAdminServer |
||||
|
public class Application { |
||||
|
|
||||
|
public static void main(String[] args) { |
||||
|
SpringApplication.run(Application.class, args); |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
@ -0,0 +1,108 @@ |
|||||
|
package com.bfd.manager.alter; |
||||
|
|
||||
|
import java.util.Arrays; |
||||
|
|
||||
|
import lombok.extern.slf4j.Slf4j; |
||||
|
|
||||
|
import org.springframework.stereotype.Component; |
||||
|
|
||||
|
import com.alibaba.fastjson.JSONObject; |
||||
|
|
||||
|
import reactor.core.publisher.Mono; |
||||
|
import de.codecentric.boot.admin.server.domain.entities.Instance; |
||||
|
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository; |
||||
|
import de.codecentric.boot.admin.server.domain.events.InstanceEvent; |
||||
|
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent; |
||||
|
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier; |
||||
|
|
||||
|
@Component |
||||
|
@Slf4j |
||||
|
public class AdminNotifier extends AbstractStatusChangeNotifier { |
||||
|
|
||||
|
/** |
||||
|
* 消息模板 |
||||
|
*/ |
||||
|
private static final String template = "<<<%s>>> \n 【服务名】: %s(%s) \n 【状态】: %s(%s) \n 【服务ip】: %s \n 【详情】: %s"; |
||||
|
|
||||
|
private String titleAlarm = "系统告警"; |
||||
|
|
||||
|
private String titleNotice = "系统通知"; |
||||
|
|
||||
|
private String[] ignoreChanges = new String[]{"UNKNOWN:UP","DOWN:UP","OFFLINE:UP"}; |
||||
|
|
||||
|
public AdminNotifier(InstanceRepository repository) { |
||||
|
super(repository); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected boolean shouldNotify(InstanceEvent event, Instance instance) { |
||||
|
if (!(event instanceof InstanceStatusChangedEvent)) { |
||||
|
return false; |
||||
|
} else { |
||||
|
InstanceStatusChangedEvent statusChange = (InstanceStatusChangedEvent)event; |
||||
|
String from = this.getLastStatus(event.getInstance()); |
||||
|
String to = statusChange.getStatusInfo().getStatus(); |
||||
|
return Arrays.binarySearch(this.ignoreChanges, from + ":" + to) < 0 && Arrays.binarySearch(this.ignoreChanges, "*:" + to) < 0 && Arrays.binarySearch(this.ignoreChanges, from + ":*") < 0; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
|
||||
|
@Override |
||||
|
protected Mono<Void> doNotify(InstanceEvent event, Instance instance) { |
||||
|
|
||||
|
return Mono.fromRunnable(() -> { |
||||
|
|
||||
|
if (event instanceof InstanceStatusChangedEvent) { |
||||
|
log.info("Instance {} ({}) is {}", instance.getRegistration().getName(), |
||||
|
event.getInstance(), |
||||
|
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus()); |
||||
|
|
||||
|
String status = ((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(); |
||||
|
String messageText = null; |
||||
|
switch (status) { |
||||
|
// 健康检查没通过 |
||||
|
case "DOWN": |
||||
|
log.info("发送 健康检查没通过 的通知!"); |
||||
|
messageText = String |
||||
|
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
||||
|
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "健康检查没通过通知", |
||||
|
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
||||
|
log.info(messageText); |
||||
|
break; |
||||
|
// 服务离线 |
||||
|
case "OFFLINE": |
||||
|
log.info("发送 服务离线 的通知!"); |
||||
|
messageText = String |
||||
|
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
||||
|
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务离线通知", |
||||
|
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
||||
|
log.info(messageText); |
||||
|
break; |
||||
|
//服务上线 |
||||
|
case "UP": |
||||
|
log.info("发送 服务上线 的通知!"); |
||||
|
messageText = String |
||||
|
.format(template,titleNotice, instance.getRegistration().getName(), event.getInstance(), |
||||
|
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务上线通知", |
||||
|
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
||||
|
log.info(messageText); |
||||
|
break; |
||||
|
// 服务未知异常 |
||||
|
case "UNKNOWN": |
||||
|
log.info("发送 服务未知异常 的通知!"); |
||||
|
messageText = String |
||||
|
.format(template,titleAlarm, instance.getRegistration().getName(), event.getInstance(), |
||||
|
((InstanceStatusChangedEvent) event).getStatusInfo().getStatus(), "服务未知异常通知", |
||||
|
instance.getRegistration().getServiceUrl(), JSONObject.toJSONString(instance.getStatusInfo().getDetails())); |
||||
|
log.info(messageText); |
||||
|
break; |
||||
|
default: |
||||
|
break; |
||||
|
} |
||||
|
} else { |
||||
|
log.info("Instance {} ({}) {}", instance.getRegistration().getName(), event.getInstance(), |
||||
|
event.getType()); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
@ -0,0 +1,29 @@ |
|||||
|
logging: |
||||
|
level: |
||||
|
root: info |
||||
|
path: ./logs |
||||
|
server: |
||||
|
port: 8000 |
||||
|
|
||||
|
# 邮件服务配置 |
||||
|
spring: |
||||
|
mail: |
||||
|
host: intmail.baifendian.com |
||||
|
username: bfd_crawler_alarm@baifendian.com |
||||
|
password: z26Iyf3vMRb5ejrI |
||||
|
properties: |
||||
|
mail: |
||||
|
smtp: |
||||
|
auth: true |
||||
|
ssl: |
||||
|
enable: true |
||||
|
boot: |
||||
|
admin: |
||||
|
monitor: |
||||
|
default-timeout: 30000 |
||||
|
notify: |
||||
|
mail: |
||||
|
enabled: true |
||||
|
to: jian.mao@percent.cn |
||||
|
from: bfd_crawler_alarm@baifendian.com |
||||
|
|
@ -0,0 +1,36 @@ |
|||||
|
<configuration> |
||||
|
<!-- 属性文件:在properties文件中找到对应的配置项 --> |
||||
|
<springProperty scope="context" name="logging.path" source="logging.path"/> |
||||
|
<springProperty scope="context" name="logging.level" source="logging.level.com.bfd"/> |
||||
|
<!-- 默认的控制台日志输出,一般生产环境都是后台启动,这个没太大作用 --> |
||||
|
<!-- <appender name="STDOUT" |
||||
|
class="ch.qos.logback.core.ConsoleAppender"> |
||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
|
<Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %line %-5level %logger{50} - %msg%n</Pattern> |
||||
|
</encoder> |
||||
|
</appender> --> |
||||
|
|
||||
|
<appender name="GLMAPPER-LOGGERONE" |
||||
|
class="ch.qos.logback.core.rolling.RollingFileAppender"> |
||||
|
<append>true</append> |
||||
|
<filter class="ch.qos.logback.classic.filter.ThresholdFilter"> |
||||
|
<level>${logging.level}</level> |
||||
|
</filter> |
||||
|
<file> |
||||
|
${logging.path}/appManagerInfo.log |
||||
|
</file> |
||||
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
||||
|
<FileNamePattern>${logging.path}/appManagerInfo.log.%d{yyyy-MM-dd}</FileNamePattern> |
||||
|
<MaxHistory>7</MaxHistory> |
||||
|
</rollingPolicy> |
||||
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> |
||||
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %line %-5level %logger{50} - %msg%n</pattern> |
||||
|
<charset>UTF-8</charset> |
||||
|
</encoder> |
||||
|
</appender> |
||||
|
|
||||
|
<root level="info"> |
||||
|
<appender-ref ref="GLMAPPER-LOGGERONE"/> |
||||
|
<!-- <appender-ref ref="STDOUT"/> --> |
||||
|
</root> |
||||
|
</configuration> |
@ -0,0 +1,20 @@ |
|||||
|
package com.bfd; |
||||
|
|
||||
|
import static org.junit.Assert.assertTrue; |
||||
|
|
||||
|
import org.junit.Test; |
||||
|
|
||||
|
/** |
||||
|
* Unit test for simple App. |
||||
|
*/ |
||||
|
public class AppTest |
||||
|
{ |
||||
|
/** |
||||
|
* Rigorous Test :-) |
||||
|
*/ |
||||
|
@Test |
||||
|
public void shouldAnswerWithTrue() |
||||
|
{ |
||||
|
assertTrue( true ); |
||||
|
} |
||||
|
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue