diff --git a/RequestDemo.json b/RequestDemo.json deleted file mode 100644 index 6a29452..0000000 --- a/RequestDemo.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "detected": true, - "monitor": { - "app": "TanCloud", - "creator": "tom", - "description": "对SAAS网站TanCloud的可用性监控", - "gmtCreate": "2021-11-18T14:18:11.968Z", - "gmtUpdate": "2021-11-18T14:18:11.968Z", - "host": "139.198.109.64", - "id": 87584674384, - "intervals": 600, - "jobId": 43243543543, - "modifier": "tom", - "name": "Api-TanCloud.cn", - "status": 1 - }, - "params": [ - { - "field": "port", - "gmtCreate": "2021-11-18T14:18:11.968Z", - "gmtUpdate": "2021-11-18T14:18:11.968Z", - "id": 87584674384, - "monitorId": 875846754543, - "type": 1, - "value": "8088" - }, - { - "field": "host", - "gmtCreate": "2021-11-18T14:18:11.968Z", - "gmtUpdate": "2021-11-18T14:18:11.968Z", - "id": 87584674384, - "monitorId": 875846754543, - "type": 1, - "value": "139.198.109.64" - } - ] -} \ No newline at end of file diff --git a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java index 7a471fb..357f106 100644 --- a/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java +++ b/alerter/src/main/java/com/usthe/alert/calculate/CalculateAlarm.java @@ -75,8 +75,8 @@ public class CalculateAlarm { // 采集异常 Alert.AlertBuilder alertBuilder = Alert.builder() .monitorId(monitorId) - .priority((byte) 0) - .status((byte) 0) + .priority(CommonConstants.ALERT_PRIORITY_CODE_EMERGENCY) + .status(CommonConstants.ALERT_STATUS_CODE_PENDING) .times(1); if (metricsData.getCode() == CollectRep.Code.UN_REACHABLE) { // UN_REACHABLE 对端不可达(网络层icmp) @@ -101,7 +101,8 @@ public class CalculateAlarm { if (stateCode != null) { // 发送告警恢复 Alert resumeAlert = Alert.builder() - .monitorId(monitorId).status((byte) 2).build(); + .monitorId(monitorId) + .status(CommonConstants.ALERT_STATUS_CODE_RESTORED).build(); dataQueue.addAlertData(resumeAlert); } } @@ -167,7 +168,7 @@ public class CalculateAlarm { .monitorId(monitorId) .alertDefineId(define.getId()) .priority(define.getPriority()) - .status((byte) 0) + .status(CommonConstants.ALERT_STATUS_CODE_PENDING) .target(app + "." + metrics + "." + define.getField()) .times(times) // 模板中关键字匹配替换 diff --git a/assembly/server/assembly.xml b/assembly/server/assembly.xml new file mode 100644 index 0000000..038731d --- /dev/null +++ b/assembly/server/assembly.xml @@ -0,0 +1,65 @@ + + + 1.0 + + + tar.gz + zip + + + + + + true + lib + + + + + + + + ../assembly/server/bin + bin + + + + + src/main/resources + + application.yml + logback-spring.xml + + true + ${file.separator}config + + + + + src/main/resources + + define/** + + true + ${file.separator} + + + + + target + / + + *.jar + + + + + + ../web-app/dist + dist + + + diff --git a/assembly/server/bin/shutdown.sh b/assembly/server/bin/shutdown.sh new file mode 100644 index 0000000..e69de29 diff --git a/assembly/server/bin/startup.sh b/assembly/server/bin/startup.sh new file mode 100644 index 0000000..e69de29 diff --git a/common/src/main/java/com/usthe/common/util/CommonConstants.java b/common/src/main/java/com/usthe/common/util/CommonConstants.java index 0ee2964..58a340e 100644 --- a/common/src/main/java/com/usthe/common/util/CommonConstants.java +++ b/common/src/main/java/com/usthe/common/util/CommonConstants.java @@ -62,6 +62,40 @@ public interface CommonConstants { */ byte SUSPENDING_CODE = 0x04; + /** + * 告警状态: 0-正常告警(待处理) + */ + byte ALERT_STATUS_CODE_PENDING = 0x00; + + /** + * 告警状态: 1-阈值触发但未达到告警次数 + */ + byte ALERT_STATUS_CODE_NOT_REACH = 0x01; + + /** + * 告警状态: 2-恢复告警 + */ + byte ALERT_STATUS_CODE_RESTORED = 0x02; + + /** + * 告警状态: 3-已处理 + */ + byte ALERT_STATUS_CODE_SOLVED = 0x03; + + /** + * 告警级别: 0:高-emergency-紧急告警-红色 + */ + byte ALERT_PRIORITY_CODE_EMERGENCY = 0x00; + + /** + * 告警级别: 1:中-critical-严重告警-橙色 + */ + byte ALERT_PRIORITY_CODE_CRITICAL = 0x01; + + /** + * 告警级别: 2:低-warning-警告告警-黄色 + */ + byte ALERT_PRIORITY_CODE_WARNING = 0x02; /** * 字段参数类型: 数字 diff --git a/manager/pom.xml b/manager/pom.xml index 492e7a9..d6da03c 100644 --- a/manager/pom.xml +++ b/manager/pom.xml @@ -113,16 +113,63 @@ + hertz-beat + + + src/main/resources + true + + application.yml + sureness.yml + banner.txt + db/** + + + - org.springframework.boot - spring-boot-maven-plugin - 2.4.13 + org.apache.maven.plugins + maven-jar-plugin + 3.2.0 + + target/classes/ + + + false + + + com.usthe.manager.Manager + false + + true + + lib/ + + + . config + + + + + + + org.apache.maven.plugins + maven-assembly-plugin + 3.3.0 + make-zip + + package + - repackage + single + + + ../assembly/server/assembly.xml + + diff --git a/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java b/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java index faad533..bfd5070 100644 --- a/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java +++ b/manager/src/main/java/com/usthe/manager/component/alerter/DispatchAlarm.java @@ -94,7 +94,7 @@ public class DispatchAlarm { } } else { // 若是恢复告警 需对监控状态进行恢复 - if (alert.getStatus() == 2) { + if (alert.getStatus() == CommonConstants.ALERT_STATUS_CODE_RESTORED) { monitorService.updateMonitorStatus(alert.getMonitorId(), CommonConstants.AVAILABLE_CODE); } } diff --git a/manager/src/main/java/com/usthe/manager/config/AngularErrorViewResolver.java b/manager/src/main/java/com/usthe/manager/config/AngularErrorViewResolver.java new file mode 100644 index 0000000..4e2e8ab --- /dev/null +++ b/manager/src/main/java/com/usthe/manager/config/AngularErrorViewResolver.java @@ -0,0 +1,128 @@ +package com.usthe.manager.config; + +import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; +import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProviders; +import org.springframework.boot.autoconfigure.web.WebProperties; +import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.Ordered; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.util.Assert; +import org.springframework.util.FileCopyUtils; +import org.springframework.web.servlet.ModelAndView; +import org.springframework.web.servlet.View; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.Collections; +import java.util.EnumMap; +import java.util.Map; + +/** + * 同DefaultErrorViewResolver 解决angular静态网站资源前端路由问题 把404的网站请求给angular前端进行路由 + * @author tom + * @date 2021/12/24 21:07 + */ +@Configuration +public class AngularErrorViewResolver implements ErrorViewResolver, Ordered { + + private static final Map SERIES_VIEWS; + private static final String NOT_FOUND_CODE = "404"; + + static { + Map views = new EnumMap<>(HttpStatus.Series.class); + views.put(HttpStatus.Series.CLIENT_ERROR, "4xx"); + views.put(HttpStatus.Series.SERVER_ERROR, "5xx"); + SERIES_VIEWS = Collections.unmodifiableMap(views); + } + + private ApplicationContext applicationContext; + + private final WebProperties.Resources resources; + + private final TemplateAvailabilityProviders templateAvailabilityProviders; + + private int order = Ordered.LOWEST_PRECEDENCE; + + public AngularErrorViewResolver(ApplicationContext applicationContext, WebProperties.Resources resources) { + Assert.notNull(applicationContext, "ApplicationContext must not be null"); + Assert.notNull(resources, "Resources must not be null"); + this.applicationContext = applicationContext; + this.resources = resources; + this.templateAvailabilityProviders = new TemplateAvailabilityProviders(applicationContext); + } + + @Override + public ModelAndView resolveErrorView(HttpServletRequest request, HttpStatus status, Map model) { + ModelAndView modelAndView = resolve(String.valueOf(status.value()), model); + if (modelAndView == null && SERIES_VIEWS.containsKey(status.series())) { + modelAndView = resolve(SERIES_VIEWS.get(status.series()), model); + } + return modelAndView; + } + + private ModelAndView resolve(String viewName, Map model) { + String errorViewName = "error/" + viewName; + if (NOT_FOUND_CODE.equals(viewName)) { + errorViewName = "index"; + } + TemplateAvailabilityProvider provider = this.templateAvailabilityProviders.getProvider(errorViewName, + this.applicationContext); + if (provider != null) { + return new ModelAndView(errorViewName, model); + } + return resolveResource(errorViewName, model); + } + + private ModelAndView resolveResource(String viewName, Map model) { + for (String location : this.resources.getStaticLocations()) { + try { + Resource resource = this.applicationContext.getResource(location); + resource = resource.createRelative(viewName + ".html"); + if (resource.exists()) { + return new ModelAndView(new HtmlResourceView(resource), model); + } + } + catch (Exception ex) { + } + } + return null; + } + + @Override + public int getOrder() { + return this.order; + } + + public void setOrder(int order) { + this.order = order; + } + + /** + * {@link View} backed by an HTML resource. + */ + private static class HtmlResourceView implements View { + + private Resource resource; + + HtmlResourceView(Resource resource) { + this.resource = resource; + } + + @Override + public String getContentType() { + return MediaType.TEXT_HTML_VALUE; + } + + @Override + public void render(Map model, HttpServletRequest request, HttpServletResponse response) + throws Exception { + response.setContentType(getContentType()); + FileCopyUtils.copy(this.resource.getInputStream(), response.getOutputStream()); + } + + } +} diff --git a/manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java b/manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java index fcd95f8..6508304 100644 --- a/manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java +++ b/manager/src/main/java/com/usthe/manager/service/impl/AppServiceImpl.java @@ -8,7 +8,6 @@ import com.usthe.manager.pojo.dto.ParamDefineDto; import com.usthe.manager.pojo.entity.ParamDefine; import com.usthe.manager.service.AppService; import lombok.extern.slf4j.Slf4j; -import org.apache.kafka.common.protocol.types.Field; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.CommandLineRunner; import org.springframework.stereotype.Service; @@ -18,7 +17,6 @@ import org.yaml.snakeyaml.Yaml; import java.io.File; import java.io.FileInputStream; import java.io.IOException; -import java.net.URL; import java.util.Collections; import java.util.HashMap; import java.util.LinkedList; @@ -123,12 +121,11 @@ public class AppServiceImpl implements AppService, CommandLineRunner { public void run(String... args) throws Exception { // 读取app定义配置加载到内存中 define/app/*.yml Yaml yaml = new Yaml(); - String defineAppPath = "define" + File.separator + "app"; - URL url = Thread.currentThread().getContextClassLoader().getResource(defineAppPath); - assert url != null; - File directory = new File(url.toURI()); + String classpath = this.getClass().getResource(File.separator).getPath(); + String defineAppPath = classpath + File.separator + "define" + File.separator + "app"; + File directory = new File(defineAppPath); if (!directory.exists() || directory.listFiles() == null) { - throw new IllegalArgumentException("define app directory not exist"); + throw new IllegalArgumentException("define app directory not exist: " + defineAppPath); } for (File appFile : Objects.requireNonNull(directory.listFiles())) { if (appFile.exists()) { @@ -142,12 +139,10 @@ public class AppServiceImpl implements AppService, CommandLineRunner { } } // 读取监控参数定义配置加载到数据库中 define/param/*.yml - String defineParamPath = "define" + File.separator + "param"; - url = Thread.currentThread().getContextClassLoader().getResource(defineParamPath); - assert url != null; - directory = new File(url.toURI()); + 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"); + throw new IllegalArgumentException("define param directory not exist: " + defineParamPath); } for (File appFile : Objects.requireNonNull(directory.listFiles())) { if (appFile.exists()) { diff --git a/manager/src/main/resources/sureness.yml b/manager/src/main/resources/sureness.yml index 496710d..81fb504 100644 --- a/manager/src/main/resources/sureness.yml +++ b/manager/src/main/resources/sureness.yml @@ -12,6 +12,8 @@ resourceRole: excludedResource: - /account/auth/form===post - /i18n/**===get + # web ui 静态资源 + - /console/**===get - /**/*.html===get - /**/*.js===get - /**/*.css===get @@ -19,10 +21,11 @@ excludedResource: - /**/*.ttf===get - /**/*.png===get - /**/*.gif===get + - /**/*.png===* + # swagger ui 资源 - /swagger-resources/**===get - /v2/api-docs===get - /v3/api-docs===get - - /**/*.png===* # account info # there are three account: admin, root, tom diff --git a/pom.xml b/pom.xml index 26cb2b3..ab68842 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ rulesets/java/ali-comment.xml - rulesets/java/ali-concurrent.xml + rulesets/java/ali-constant.xml diff --git a/warehouse/src/main/java/com/usthe/warehouse/controller/MetricsDataController.java b/warehouse/src/main/java/com/usthe/warehouse/controller/MetricsDataController.java index 0f02219..809c1a9 100644 --- a/warehouse/src/main/java/com/usthe/warehouse/controller/MetricsDataController.java +++ b/warehouse/src/main/java/com/usthe/warehouse/controller/MetricsDataController.java @@ -33,6 +33,8 @@ import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; @Api(tags = "监控指标数据API") public class MetricsDataController { + private static final Integer METRIC_FULL_LENGTH = 3; + @Autowired private RedisDataStorage redisDataStorage; @@ -77,7 +79,7 @@ public class MetricsDataController { @RequestParam(required = false) String history ) { String[] names = metricFull.split("."); - if (names.length != 3) { + if (names.length != METRIC_FULL_LENGTH) { throw new IllegalArgumentException("metrics full name: " + metricFull + " is illegal."); } String app = names[0]; diff --git a/web-app/README.md b/web-app/README.md index a42a848..bd40f03 100644 --- a/web-app/README.md +++ b/web-app/README.md @@ -2,4 +2,9 @@ > 前端工程 -**面向开发者,易用友好的高性能监控云服务** +**面向开发者,易用友好的高性能监控云服务** + + +## 编译打包 + +```ng build --prod --base-href /console/``` diff --git a/web-app/angular.json b/web-app/angular.json index 76b1434..c87afb3 100644 --- a/web-app/angular.json +++ b/web-app/angular.json @@ -52,7 +52,7 @@ "build": { "builder": "@angular-devkit/build-angular:browser", "options": { - "outputPath": "dist/web-app", + "outputPath": "dist", "index": "src/index.html", "main": "src/main.ts", "polyfills": "src/polyfills.ts", diff --git a/web-app/src/environments/environment.prod.ts b/web-app/src/environments/environment.prod.ts index ef7e136..a32e33f 100644 --- a/web-app/src/environments/environment.prod.ts +++ b/web-app/src/environments/environment.prod.ts @@ -2,9 +2,9 @@ import { Environment } from '@delon/theme'; export const environment = { production: true, - useHash: true, + useHash: false, api: { - baseUrl: './', + baseUrl: '/', refreshTokenEnabled: true } } as Environment; diff --git a/web-app/src/environments/environment.ts b/web-app/src/environments/environment.ts index c3b74a9..27ba195 100644 --- a/web-app/src/environments/environment.ts +++ b/web-app/src/environments/environment.ts @@ -9,7 +9,7 @@ import * as MOCK_DATA from '../../_mock'; export const environment = { production: false, - useHash: true, + useHash: false, api: { baseUrl: 'http://localhost:8080/', refreshTokenEnabled: true