feat(check): 增加环境检验工具
This commit is contained in:
4
bin/build-check.sh
Executable file
4
bin/build-check.sh
Executable file
@@ -0,0 +1,4 @@
|
||||
#!/bin/bash
|
||||
mvn -pl service-dependencies,service-configuration clean deploy -D skipTests -P local -s ~/.m2/settings-development.xml
|
||||
mvn -pl service-check clean package spring-boot:repackage -D skipTests -s ~/.m2/settings-development.xml
|
||||
ytp-transfer2 /Users/lanyuanxiaoyao/Project/IdeaProjects/hudi-service/service-check/target/service-check-1.0.0-SNAPSHOT.jar
|
||||
7
bin/check
Normal file
7
bin/check
Normal file
@@ -0,0 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
root_path=/apps/zone_scfp/hudi/cloud
|
||||
jdk_path=/opt/jdk8u252-b09/bin/java
|
||||
|
||||
curl ftp://yyy:QeY\!68\)4nH1@132.121.122.15:2222/service-check-1.0.0-SNAPSHOT.jar -o ${root_path}/service-check.jar
|
||||
${jdk_path} -jar ${root_path}/service-check.jar
|
||||
1
pom.xml
1
pom.xml
@@ -27,6 +27,7 @@
|
||||
<module>service-executor</module>
|
||||
<module>service-cloud-query</module>
|
||||
<module>service-exporter</module>
|
||||
<module>service-check</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
||||
78
service-check/pom.xml
Normal file
78
service-check/pom.xml
Normal file
@@ -0,0 +1,78 @@
|
||||
<?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>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>hudi-service</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>service-check</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.collections</groupId>
|
||||
<artifactId>eclipse-collections</artifactId>
|
||||
<scope>runtime</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.collections</groupId>
|
||||
<artifactId>eclipse-collections-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.ulisesbocchio</groupId>
|
||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.pulsar</groupId>
|
||||
<artifactId>pulsar-client</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.pulsar</groupId>
|
||||
<artifactId>pulsar-client-admin</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>mysql</groupId>
|
||||
<artifactId>mysql-connector-java</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>service-configuration</artifactId>
|
||||
<version>1.0.0-SNAPSHOT</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.lanyuanxiaoyao</groupId>
|
||||
<artifactId>service-dependencies</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.lanyuanxiaoyao.service.check;
|
||||
|
||||
import com.lanyuanxiaoyao.service.check.actions.Checker;
|
||||
import java.util.Map;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.boot.ApplicationArguments;
|
||||
import org.springframework.boot.ApplicationRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
/**
|
||||
* 启动类
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-02-22
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class CheckApplication implements ApplicationRunner {
|
||||
private static final Logger logger = LoggerFactory.getLogger(CheckApplication.class);
|
||||
private final ApplicationContext applicationContext;
|
||||
|
||||
public CheckApplication(ApplicationContext applicationContext) {this.applicationContext = applicationContext;}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(CheckApplication.class, args);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(ApplicationArguments args) throws Exception {
|
||||
Map<String, Checker> beans = applicationContext.getBeansOfType(Checker.class);
|
||||
for (Checker checker : beans.values()) {
|
||||
logger.info("Execute checker: {}", checker.description());
|
||||
checker.check();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.lanyuanxiaoyao.service.check.actions;
|
||||
|
||||
import cn.hutool.core.net.NetUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* 检查
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-02-22
|
||||
*/
|
||||
public abstract class Checker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(Checker.class);
|
||||
|
||||
public abstract void check() throws Exception;
|
||||
|
||||
public abstract String description();
|
||||
|
||||
protected boolean ping(String url) {
|
||||
String[] split = url.split(":");
|
||||
if (split.length != 2) {
|
||||
logger.error("Error url {}", url);
|
||||
return false;
|
||||
}
|
||||
InetSocketAddress address = NetUtil.createAddress(split[0], Integer.parseInt(split[1]));
|
||||
try {
|
||||
String command = StrUtil.format("ping {} -c 2 -w 2 -q", address.getHostString());
|
||||
Process exec = Runtime.getRuntime().exec(command);
|
||||
if (exec.waitFor(5, TimeUnit.SECONDS)) {
|
||||
return exec.exitValue() == 0;
|
||||
}
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.lanyuanxiaoyao.service.check.actions;
|
||||
|
||||
import com.lanyuanxiaoyao.service.check.configuration.MysqlConfigurationProperties;
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-02-22
|
||||
*/
|
||||
@Component
|
||||
public class MysqlChecker extends Checker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(MysqlChecker.class);
|
||||
|
||||
private final MysqlConfigurationProperties mysqlConfigurationProperties;
|
||||
|
||||
public MysqlChecker(MysqlConfigurationProperties mysqlConfigurationProperties) {this.mysqlConfigurationProperties = mysqlConfigurationProperties;}
|
||||
|
||||
@Override
|
||||
public void check() throws Exception {
|
||||
Class.forName("com.mysql.cj.jdbc.Driver");
|
||||
for (MysqlConfigurationProperties.MysqlInfo target : mysqlConfigurationProperties.getTargets()) {
|
||||
try (Connection connection = DriverManager.getConnection(target.getUrl(), target.getUsername(), target.getPassword())) {
|
||||
if (connection.isClosed()) {
|
||||
logger.warn("Database connect failure {}", target.getUrl());
|
||||
continue;
|
||||
}
|
||||
try (Statement statement = connection.createStatement()) {
|
||||
try (ResultSet resultSet = statement.executeQuery("select version()")) {
|
||||
if (resultSet.next()) {
|
||||
logger.info("Database version {}", resultSet.getString(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Check mysql";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
package com.lanyuanxiaoyao.service.check.actions;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.lanyuanxiaoyao.service.configuration.entity.pulsar.PulsarInfo;
|
||||
import org.apache.pulsar.client.admin.PulsarAdmin;
|
||||
import org.apache.pulsar.client.api.PulsarClient;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 主机相关检查
|
||||
*
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-02-22
|
||||
*/
|
||||
@Component
|
||||
public class PulsarChecker extends Checker {
|
||||
private static final Logger logger = LoggerFactory.getLogger(PulsarChecker.class);
|
||||
|
||||
private void checkConnect(String url) {
|
||||
if (!ping(url)) {
|
||||
logger.warn("{} ping failure", url);
|
||||
}
|
||||
}
|
||||
|
||||
private String adminUrl(PulsarInfo info) {
|
||||
return StrUtil.format("http://{}/admin/v2", info.getAdmin());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check() throws Exception {
|
||||
for (PulsarInfo pulsarInfo : PulsarInfo.DEFAULT_INFOS) {
|
||||
logger.info("Check pulsar {}", pulsarInfo.getName());
|
||||
if (StrUtil.isNotBlank(pulsarInfo.getAdmin())) {
|
||||
logger.info("Check pulsar admin {}", pulsarInfo.getAdmin());
|
||||
if (ping(pulsarInfo.getAdmin())) {
|
||||
// noinspection EmptyTryBlock
|
||||
try (PulsarAdmin ignored = PulsarAdmin.builder().serviceHttpUrl(adminUrl(pulsarInfo)).build()) {
|
||||
} catch (Exception exception) {
|
||||
logger.warn("Pulsar admin login failure", exception);
|
||||
}
|
||||
} else {
|
||||
logger.warn("{} ping failure", pulsarInfo.getAdmin());
|
||||
}
|
||||
} else {
|
||||
logger.warn("Pulsar {} admin is empty", pulsarInfo.getName());
|
||||
}
|
||||
logger.info("Check pulsar nodes");
|
||||
for (String broker : pulsarInfo.getBrokers()) {
|
||||
if (!ping(broker)) {
|
||||
logger.warn("{} ping failure", broker);
|
||||
}
|
||||
}
|
||||
String brokerUrl = "pulsar://" + pulsarInfo.getBrokers().makeString(",");
|
||||
try (PulsarClient client = PulsarClient.builder()
|
||||
.serviceUrl(brokerUrl)
|
||||
.build()) {
|
||||
if (client.isClosed()) {
|
||||
logger.warn("Pulsar client failure connect {}", brokerUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "Check Pulsar";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.lanyuanxiaoyao.service.check.configuration;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author lanyuanxiaoyao
|
||||
* @date 2024-02-22
|
||||
*/
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "checker.mysql")
|
||||
public class MysqlConfigurationProperties {
|
||||
private List<MysqlInfo> targets;
|
||||
|
||||
public List<MysqlInfo> getTargets() {
|
||||
return targets;
|
||||
}
|
||||
|
||||
public void setTargets(List<MysqlInfo> targets) {
|
||||
this.targets = targets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MysqlConfigurationProperties{" +
|
||||
"targets=" + targets +
|
||||
'}';
|
||||
}
|
||||
|
||||
public static final class MysqlInfo {
|
||||
private String url;
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "MysqlInfo{" +
|
||||
"url='" + url + '\'' +
|
||||
", username='" + username + '\'' +
|
||||
", password='" + password + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
}
|
||||
11
service-check/src/main/resources/application.yml
Normal file
11
service-check/src/main/resources/application.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
application:
|
||||
name: service-check
|
||||
profiles:
|
||||
include: common
|
||||
checker:
|
||||
mysql:
|
||||
targets:
|
||||
- url: jdbc:mysql://132.121.204.217:17906/hudi_collect_build_2?useSSL=false
|
||||
username: odcp
|
||||
password: wFg_fR492#&
|
||||
17
service-check/src/main/resources/logback-spring.xml
Normal file
17
service-check/src/main/resources/logback-spring.xml
Normal file
@@ -0,0 +1,17 @@
|
||||
<configuration>
|
||||
<conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter" />
|
||||
<conversionRule conversionWord="wex" converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter" />
|
||||
<conversionRule conversionWord="wEx" converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter" />
|
||||
|
||||
<appender name="Console" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<encoder>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %clr(%5p) %clr([${HOSTNAME}]){yellow} %clr([%t]){magenta} %clr(%logger{40}){cyan} #@# %m%n%wEx</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<logger name="org.apache.pulsar.client" level="WARN"/>
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="Console"/>
|
||||
</root>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user