[doc,manager,webapp]support deploy with osrc.com

This commit is contained in:
tomsun28
2022-04-19 20:18:01 +08:00
parent 81896f9ba1
commit 0b82096ff7
4 changed files with 81 additions and 26 deletions

View File

@@ -21,6 +21,8 @@
**官网: [hertzbeat.com](https://hertzbeat.com) | [tancloud.cn](https://tancloud.cn)**
在开源运行时社区[OSCR.COM](https://osrc.com)快速运行HertzBeat - [部署流程](https://osrc.com/user/articles/wiki_776513931985080320)
## 🎡 <font color="green">介绍</font>
> [HertzBeat赫兹跳动](https://github.com/dromara/hertzbeat) 是由[Dromara](https://dromara.org)孵化,[TanCloud](https://tancloud.cn)开源的一个支持网站APIPING端口数据库操作系统等监控类型拥有易用友好的可视化操作界面的开源监控告警项目。

View File

@@ -22,6 +22,8 @@
**Home: [hertzbeat.com](https://hertzbeat.com) | [tancloud.cn](https://tancloud.cn)**
Running HertzBeat in [OSCR.COM](https://osrc.com) Open Source Runtime Community - [Doc](https://osrc.com/user/articles/wiki_776513931985080320)
## 🎡 <font color="green">Introduction</font>
> [HertzBeat](https://github.com/dromara/hertzbeat) is an opensource monitoring and alarm project incubated by [Dromara](https://dromara.org) and open sourced by [TanCloud](https://tancloud.cn), which supports Website, API, PING, Port, Database, OS Monitor etc.

View File

@@ -11,6 +11,9 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.core.annotation.Order;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yaml.snakeyaml.Yaml;
@@ -18,6 +21,7 @@ import org.yaml.snakeyaml.Yaml;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedList;
@@ -122,6 +126,8 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
@Override
public void run(String... args) throws Exception {
boolean loadFromFile = true;
final List<InputStream> inputStreams = new LinkedList<>();
// 读取app定义配置加载到内存中 define/app/*.yml
Yaml yaml = new Yaml();
String classpath = this.getClass().getClassLoader().getResource("").getPath();
@@ -132,37 +138,82 @@ public class AppServiceImpl implements AppService, CommandLineRunner {
defineAppPath = classpath + File.separator + "define" + File.separator + "app";
directory = new File(defineAppPath);
if (!directory.exists() || directory.listFiles() == null) {
throw new IllegalArgumentException("define app directory not exist: " + defineAppPath);
}
}
log.info("query define path {}", defineAppPath);
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(appFile)) {
Job app = yaml.loadAs(fileInputStream, Job.class);
appDefines.put(app.getApp().toLowerCase(), app);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new IOException(e);
// load define app yml in jar
log.info("load define app yml in internal jar");
loadFromFile = false;
try {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:define/app/*.yml");
for (Resource resource : resources) {
inputStreams.add(resource.getInputStream());
}
} catch (Exception e) {
log.error("define app yml not exist");
throw e;
}
}
}
if (loadFromFile) {
log.info("load define path {}", defineAppPath);
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(appFile)) {
Job app = yaml.loadAs(fileInputStream, Job.class);
appDefines.put(app.getApp().toLowerCase(), app);
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new IOException(e);
}
}
}
} else {
if (inputStreams.isEmpty()) {
throw new IllegalArgumentException("define app directory not exist");
} else {
inputStreams.forEach(stream -> {
try {
Job app = yaml.loadAs(stream, Job.class);
appDefines.put(app.getApp().toLowerCase(), app);
stream.close();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
});
}
}
// 读取监控参数定义配置加载到数据库中 define/param/*.yml
String defineParamPath = classpath + File.separator + "define" + File.separator + "param";
directory = new File(defineParamPath);
if (!directory.exists() || directory.listFiles() == null) {
throw new IllegalArgumentException("define param directory not exist: " + defineParamPath);
}
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(appFile)) {
ParamDefineDto paramDefine = yaml.loadAs(fileInputStream, ParamDefineDto.class);
paramDefines.put(paramDefine.getApp().toLowerCase(), paramDefine.getParam());
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new IOException(e);
if (loadFromFile) {
String defineParamPath = classpath + File.separator + "define" + File.separator + "param";
directory = new File(defineParamPath);
if (!directory.exists() || directory.listFiles() == null) {
throw new IllegalArgumentException("define param directory not exist: " + defineParamPath);
}
for (File appFile : Objects.requireNonNull(directory.listFiles())) {
if (appFile.exists()) {
try (FileInputStream fileInputStream = new FileInputStream(appFile)) {
ParamDefineDto paramDefine = yaml.loadAs(fileInputStream, ParamDefineDto.class);
paramDefines.put(paramDefine.getApp().toLowerCase(), paramDefine.getParam());
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new IOException(e);
}
}
}
} else {
try {
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath:define/param/*.yml");
for (Resource resource : resources) {
InputStream stream = resource.getInputStream();
ParamDefineDto paramDefine = yaml.loadAs(stream, ParamDefineDto.class);
paramDefines.put(paramDefine.getApp().toLowerCase(), paramDefine.getParam());
stream.close();
}
} catch (Exception e) {
log.error("define param yml not exist");
throw e;
}
}
}
}

View File

@@ -1,5 +1,5 @@
{
"name": "web-app",
"name": "hertzbeat-web-app",
"version": "0.0.0",
"scripts": {
"ng": "ng",