diff --git a/rition-center/api/src/main/java/rition/backend/api/v1/panel/AlertRuleController.java b/rition-center/api/src/main/java/rition/backend/api/v1/panel/AlertRuleController.java index bccb079..00897f7 100644 --- a/rition-center/api/src/main/java/rition/backend/api/v1/panel/AlertRuleController.java +++ b/rition-center/api/src/main/java/rition/backend/api/v1/panel/AlertRuleController.java @@ -27,11 +27,11 @@ public class AlertRuleController { for (RuleEntity ruleEntity : ruleEntityList) { RuleResponse response = new RuleResponse(); response.setId(ruleEntity.getId()); - response.setExpression(ruleEntity.getExpression()); - response.setCondition(ruleEntity.getCondition()); + response.setExpression(ruleEntity.getExpr()); + response.setCondition(ruleEntity.getCond()); response.setThreshold(ruleEntity.getThreshold()); - response.setTrigger(ruleEntity.getTrigger()); - response.setDescription(ruleEntity.getDescription()); + response.setTrigger(ruleEntity.getTrig()); + response.setDescription(ruleEntity.getComment()); response.setCreateTime(ruleEntity.getCreateTime()); response.setUpdateTime(ruleEntity.getUpdateTime()); diff --git a/rition-center/common/src/main/java/rition/common/data/entity/RuleEntity.java b/rition-center/common/src/main/java/rition/common/data/entity/RuleEntity.java index 7795bfa..311a6ad 100644 --- a/rition-center/common/src/main/java/rition/common/data/entity/RuleEntity.java +++ b/rition-center/common/src/main/java/rition/common/data/entity/RuleEntity.java @@ -23,14 +23,14 @@ public class RuleEntity { private Long id; /** - * 需要计算的指标项或者表达式 + * 需要计算的指标项或者表达式(expression) */ - private String expression; + private String expr; /** - * 触发条件 + * 触发条件(condition) */ - private Integer condition; + private Integer cond; /** * 阈值 @@ -38,14 +38,14 @@ public class RuleEntity { private Double threshold; /** - * 触发方法,实时计算或定时计算 + * 触发方法,实时计算或定时计算(trigger) */ - private Integer trigger; + private Integer trig; /** * 规则描述 */ - private String description; + private String comment; /** * create_time diff --git a/rition-center/common/src/main/resources/mapper/MetricRecordMapper.xml b/rition-center/common/src/main/resources/mapper/MetricRecordMapper.xml index c27b7d2..6a7c115 100644 --- a/rition-center/common/src/main/resources/mapper/MetricRecordMapper.xml +++ b/rition-center/common/src/main/resources/mapper/MetricRecordMapper.xml @@ -67,7 +67,10 @@ avg(JSON_EXTRACT(metric_data, "$.${metricItem}")) as ${metricItem}, - DATE_FORMAT(time,'%Y-%m-%d %H:%i:00') as t + DATE_FORMAT( + concat( date( TimeStart ), ' ', HOUR ( TimeStart ), ':', floor( MINUTE ( TimeStart ) / #{minutes} ) * ${minutes} ), + '%Y-%m-%d %H:%i' + ) as t FROM record WHERE `time` BETWEEN #{startTime} and #{endTime} and `instance_id` = #{instanceId} GROUP BY t ORDER BY t ) AS tab; diff --git a/rition-center/service/panel/src/main/java/rition/service/panel/AlertRuleService.java b/rition-center/service/panel/src/main/java/rition/service/panel/AlertRuleService.java index bc0cad9..d7b25e2 100644 --- a/rition-center/service/panel/src/main/java/rition/service/panel/AlertRuleService.java +++ b/rition-center/service/panel/src/main/java/rition/service/panel/AlertRuleService.java @@ -29,11 +29,11 @@ public class AlertRuleService { public void addAlertRule(AlertRuleAddDto alertRuleAddDto) { RuleEntity ruleEntity = new RuleEntity(); ruleEntity.setId(YitIdHelper.nextId()); - ruleEntity.setExpression(alertRuleAddDto.getExpression()); - ruleEntity.setCondition(alertRuleAddDto.getCondition()); + ruleEntity.setExpr(alertRuleAddDto.getExpression()); + ruleEntity.setCond(alertRuleAddDto.getCondition()); ruleEntity.setThreshold(alertRuleAddDto.getThreshold()); - ruleEntity.setTrigger(alertRuleAddDto.getTrigger()); - ruleEntity.setDescription(alertRuleAddDto.getDescription()); + ruleEntity.setTrig(alertRuleAddDto.getTrigger()); + ruleEntity.setComment(alertRuleAddDto.getDescription()); var now = Instant.now(); ruleEntity.setCreateTime(now); @@ -44,15 +44,15 @@ public class AlertRuleService { AlertRuleDto alertRuleDto = new AlertRuleDto(); alertRuleDto.setId(ruleEntity.getId()); - alertRuleDto.setExpression(ruleEntity.getExpression()); - alertRuleDto.setCondition(ruleEntity.getCondition()); + alertRuleDto.setExpression(ruleEntity.getExpr()); + alertRuleDto.setCondition(ruleEntity.getCond()); alertRuleDto.setThreshold(ruleEntity.getThreshold()); - alertRuleDto.setTrigger(ruleEntity.getTrigger()); - alertRuleDto.setDescription(ruleEntity.getDescription()); + alertRuleDto.setTrigger(ruleEntity.getTrig()); + alertRuleDto.setDescription(ruleEntity.getComment()); alertRuleDto.setCreateTime(now); // 规则缓存到redis - redisTemplate.opsForHash().put(Constants.RedisKeys.RULE_CACHE, alertRuleDto.getId(), alertRuleDto); + redisTemplate.opsForHash().put(Constants.RedisKeys.RULE_CACHE, alertRuleDto.getId().toString(), alertRuleDto); } public List getRule() { diff --git a/rition-center/service/panel/src/main/java/rition/service/panel/MetricService.java b/rition-center/service/panel/src/main/java/rition/service/panel/MetricService.java index 426c834..2912fb6 100644 --- a/rition-center/service/panel/src/main/java/rition/service/panel/MetricService.java +++ b/rition-center/service/panel/src/main/java/rition/service/panel/MetricService.java @@ -1,6 +1,5 @@ package rition.service.panel; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import rition.common.data.dao.mapper.MetricRecordMapper; @@ -35,17 +34,17 @@ public class MetricService { public List getMetricDataRange(String instanceId, List metricItems, Instant start, Instant end) { - // 时间跨度小于1小时:不按时间粒度获取 - // 时间跨度大于1小时:时间粒度为1分钟 - // 时间跨度超过一天:时间粒度为小时 + // 时间跨度小于6小时:时间粒度为1分钟 + // 时间跨度大于6小时:时间粒度为5分钟 + // 时间跨度大于12小时:时间粒度为10分钟 + // 时间跨度超过15天:时间粒度为小时 var diff = end.minusMillis(start.toEpochMilli()).toEpochMilli(); - if (diff < HOUR) { - var query = new LambdaQueryWrapper() - .eq(MetricRecordEntity::getInstanceId, instanceId) - .between(MetricRecordEntity::getTime, start, end); - return metricRecordMapper.selectList(query); - } else if (diff < DAY) { + if (diff < HOUR * 6) { return metricRecordMapper.getMetricDataGroupByMinute(instanceId, metricItems, start, end); + } else if (diff < HOUR * 12) { + return metricRecordMapper.getMetricDataGroupBySomeMinute(5, instanceId, metricItems, start, end); + } else if (diff < DAY * 15) { + return metricRecordMapper.getMetricDataGroupBySomeMinute(10, instanceId, metricItems, start, end); } else { return metricRecordMapper.getMetricDataGroupByHour(instanceId, metricItems, start, end); } diff --git a/rition-panel/quasar.config.js b/rition-panel/quasar.config.js index 9be71c4..2a267b9 100644 --- a/rition-panel/quasar.config.js +++ b/rition-panel/quasar.config.js @@ -82,7 +82,15 @@ module.exports = configure(function (/* ctx */) { // Full list of options: https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#devServer devServer: { // https: true - open: false // opens browser window automatically + open: false, // opens browser window automatically + proxy: { + // with options + '/api': { + target: 'http://127.0.0.1:8000', + changeOrigin: true, + // rewrite: (path) => path.replace(/^\/api/, '/api') + } + } }, // https://v2.quasar.dev/quasar-cli-vite/quasar-config-js#framework diff --git a/rition-panel/src/boot/axios.js b/rition-panel/src/boot/axios.js index 9dbc942..2462db0 100644 --- a/rition-panel/src/boot/axios.js +++ b/rition-panel/src/boot/axios.js @@ -7,7 +7,7 @@ import axios from 'axios' // good idea to move this instance creation inside of the // "export default () => {}" function below (which runs individually // for each client) -const api = axios.create({ baseURL: 'https://api.example.com' }) +const api = axios.create({ baseURL: window.location.origin + "/api" }) export default boot(({ app }) => { // for use inside Vue files (Options API) through this.$axios and this.$api diff --git a/rition-panel/src/css/app.scss b/rition-panel/src/css/app.scss index d8bc147..5007ade 100644 --- a/rition-panel/src/css/app.scss +++ b/rition-panel/src/css/app.scss @@ -2,3 +2,7 @@ @tailwind base; @tailwind components; @tailwind utilities; + +html, body, #q-app { + height: 100%; +} diff --git a/rition-panel/src/layouts/MainLayout.vue b/rition-panel/src/layouts/MainLayout.vue index a21ca30..af1d46e 100644 --- a/rition-panel/src/layouts/MainLayout.vue +++ b/rition-panel/src/layouts/MainLayout.vue @@ -24,7 +24,7 @@ - + diff --git a/rition-panel/src/pages/AlertListPage.vue b/rition-panel/src/pages/AlertListPage.vue index 4c42ba1..40848b1 100644 --- a/rition-panel/src/pages/AlertListPage.vue +++ b/rition-panel/src/pages/AlertListPage.vue @@ -6,7 +6,7 @@ import {ref} from "vue";