Browse Source

dashboard: fix the problem that dashboard could not correctly display the SystemRule in CPU usage strategy (#927)

master
田阳 Eric Zhao 5 years ago
parent
commit
5e85965754
7 changed files with 158 additions and 52 deletions
  1. +75
    -12
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java
  2. +30
    -9
      sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java
  3. +21
    -10
      sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js
  4. +7
    -2
      sentinel-dashboard/src/main/webapp/resources/app/scripts/services/systemservice.js
  5. +17
    -16
      sentinel-dashboard/src/main/webapp/resources/app/views/dialog/system-rule-dialog.html
  6. +4
    -2
      sentinel-dashboard/src/main/webapp/resources/app/views/system.html
  7. +4
    -1
      sentinel-dashboard/src/main/webapp/resources/dist/js/app.js

+ 75
- 12
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/controller/SystemController.java View File

@@ -88,10 +88,33 @@ public class SystemController {
return notNullCount;
}

/**
* @modify
* 目前代码里做了如下几点修改:
* 1】修改属性名称avgLoad 修改为highestSystemLoad
* 2】修改属性名称avgCpu 修改为highestCpuUsage
* 3】调用countNotNullAndNotNegative非空校验方法里增加参数highestCpuUsage,
* 4】修改notNullCount部分判断错误提示语,因为目前countNotNullAndNotNegative里针对=0的情况也做了限制
* 5】对于highestSystemLoad、highestCpuUsage增加>1 的这个判断
* @author tianyang5@yeah.net
* @time 2019年7月17日 18:30:32
* @modify
*
* @param request
* @param app
* @param ip
* @param port
* @param highestSystemLoad
* @param highestCpuUsage
* @param avgRt
* @param maxThread
* @param qps
* @return
*/
@ResponseBody
@RequestMapping("/new.json")
Result<?> add(HttpServletRequest request,
String app, String ip, Integer port, Double avgLoad, Long avgRt, Long maxThread, Double qps) {
String app, String ip, Integer port, Double highestSystemLoad,Double highestCpuUsage, Long avgRt, Long maxThread, Double qps) {
AuthUser authUser = authService.getAuthUser(request);
authUser.authTarget(app, PrivilegeType.WRITE_RULE);
if (StringUtil.isBlank(app)) {
@@ -103,21 +126,32 @@ public class SystemController {
if (port == null) {
return Result.ofFail(-1, "port can't be null");
}
int notNullCount = countNotNullAndNotNegative(avgLoad, avgRt, maxThread, qps);

int notNullCount = countNotNullAndNotNegative(highestSystemLoad, avgRt, maxThread, qps,highestCpuUsage);
if (notNullCount != 1) {
return Result.ofFail(-1, "only one of [avgLoad, avgRt, maxThread, qps] "
+ "value must be set >= 0, but " + notNullCount + " values get");
return Result.ofFail(-1, "only one of [highestSystemLoad, avgRt, maxThread, qps,highestCpuUsage] "
+ "value must be set > 0, but " + notNullCount + " values get");
}
if ( null!=highestCpuUsage && 1 < highestCpuUsage ) {
return Result.ofFail(-1, "highestCpuUsage must <= 1");
}
SystemRuleEntity entity = new SystemRuleEntity();
entity.setApp(app.trim());
entity.setIp(ip.trim());
entity.setPort(port);
// -1 is a fake value
if (avgLoad != null) {
entity.setAvgLoad(avgLoad);
if ( null != highestSystemLoad ) {
entity.setHighestSystemLoad(highestSystemLoad);
} else {
entity.setHighestSystemLoad(-1D);
}

if ( null != highestCpuUsage ) {
entity.setHighestCpuUsage(highestCpuUsage);
} else {
entity.setAvgLoad(-1D);
entity.setHighestCpuUsage(-1D);
}

if (avgRt != null) {
entity.setAvgRt(avgRt);
} else {
@@ -148,10 +182,30 @@ public class SystemController {
return Result.ofSuccess(entity);
}

/**
* @modify
* 目前代码里做了如下几点修改:
* 1】修改属性名称avgLoad 修改为highestSystemLoad
* 2】修改属性名称avgCpu 修改为highestCpuUsage
* 1】对于highestSystemLoad、highestCpuUsage增加>1 的这个判断,调整原先<0的判断,调整为<=0 等于0的这种规则设置了也没有意义
* @author tianyang5@yeah.net
* @time 2019年7月17日 18:30:32
* @modify
*
* @param request
* @param id
* @param app
* @param highestSystemLoad
* @param highestCpuUsage
* @param avgRt
* @param maxThread
* @param qps
* @return
*/
@ResponseBody
@RequestMapping("/save.json")
Result<?> updateIfNotNull(HttpServletRequest request,
Long id, String app, Double avgLoad, Long avgRt, Long maxThread, Double qps) {
Long id, String app, Double highestSystemLoad,Double highestCpuUsage, Long avgRt, Long maxThread, Double qps) {
AuthUser authUser = authService.getAuthUser(request);
if (id == null) {
return Result.ofFail(-1, "id can't be null");
@@ -164,11 +218,20 @@ public class SystemController {
if (StringUtil.isNotBlank(app)) {
entity.setApp(app.trim());
}
if (avgLoad != null) {
if (avgLoad < 0) {
return Result.ofFail(-1, "avgLoad must >= 0");
if (highestSystemLoad != null) {
if (highestSystemLoad <= 0) {
return Result.ofFail(-1, "highestSystemLoad must >= 0");
}
entity.setHighestSystemLoad(highestSystemLoad);
}
if (highestCpuUsage != null) {
if (highestCpuUsage < 0) {
return Result.ofFail(-1, "highestCpuUsage must >= 0");
}
if (highestCpuUsage > 1) {
return Result.ofFail(-1, "highestCpuUsage must <= 1");
}
entity.setAvgLoad(avgLoad);
entity.setHighestCpuUsage(highestCpuUsage);
}
if (avgRt != null) {
if (avgRt < 0) {


+ 30
- 9
sentinel-dashboard/src/main/java/com/alibaba/csp/sentinel/dashboard/datasource/entity/rule/SystemRuleEntity.java View File

@@ -15,10 +15,10 @@
*/
package com.alibaba.csp.sentinel.dashboard.datasource.entity.rule;

import java.util.Date;

import com.alibaba.csp.sentinel.slots.system.SystemRule;

import java.util.Date;

/**
* @author leyou
*/
@@ -29,10 +29,21 @@ public class SystemRuleEntity implements RuleEntity {
private String app;
private String ip;
private Integer port;
private Double avgLoad;
/**
* 对应SystemRule 里的属性highestSystemLoad,这里做下调整
* @author tianyang5@yeah.net
* @time 2019年7月17日 18:30:32
*/
private Double highestSystemLoad;
private Long avgRt;
private Long maxThread;
private Double qps;
/**
* 对应SystemRule 里的属性highestCpuUsage
* @author tianyang5@yeah.net
* @time 2019年7月17日 18:30:32
*/
private Double highestCpuUsage;

private Date gmtCreate;
private Date gmtModified;
@@ -42,7 +53,8 @@ public class SystemRuleEntity implements RuleEntity {
entity.setApp(app);
entity.setIp(ip);
entity.setPort(port);
entity.setAvgLoad(rule.getHighestSystemLoad());
entity.setHighestSystemLoad(rule.getHighestSystemLoad());
entity.setHighestCpuUsage(rule.getHighestCpuUsage());
entity.setAvgRt(rule.getAvgRt());
entity.setMaxThread(rule.getMaxThread());
entity.setQps(rule.getQps());
@@ -86,12 +98,12 @@ public class SystemRuleEntity implements RuleEntity {
this.app = app;
}

public Double getAvgLoad() {
return avgLoad;
public Double getHighestSystemLoad() {
return highestSystemLoad;
}

public void setAvgLoad(Double avgLoad) {
this.avgLoad = avgLoad;
public void setHighestSystemLoad(Double highestSystemLoad) {
this.highestSystemLoad = highestSystemLoad;
}

public Long getAvgRt() {
@@ -118,6 +130,14 @@ public class SystemRuleEntity implements RuleEntity {
this.qps = qps;
}

public Double getHighestCpuUsage() {
return highestCpuUsage;
}

public void setHighestCpuUsage(Double highestCpuUsage) {
this.highestCpuUsage = highestCpuUsage;
}

@Override
public Date getGmtCreate() {
return gmtCreate;
@@ -138,10 +158,11 @@ public class SystemRuleEntity implements RuleEntity {
@Override
public SystemRule toRule() {
SystemRule rule = new SystemRule();
rule.setHighestSystemLoad(avgLoad);
rule.setHighestSystemLoad(highestSystemLoad);
rule.setAvgRt(avgRt);
rule.setMaxThread(maxThread);
rule.setQps(qps);
rule.setHighestCpuUsage(highestCpuUsage);
return rule;
}
}

+ 21
- 10
sentinel-dashboard/src/main/webapp/resources/app/scripts/controllers/system.js View File

@@ -38,7 +38,7 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
$scope.rules = data.data;
$.each($scope.rules, function (idx, rule) {
// rule.orginEnable = rule.enable;
if (rule.avgLoad >= 0) {
if (rule.highestSystemLoad >= 0) {
rule.grade = 0;
} else if (rule.avgRt >= 0) {
rule.grade = 1;
@@ -46,6 +46,8 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
rule.grade = 2;
} else if (rule.qps >= 0) {
rule.grade = 3;
}else if (rule.highestCpuUsage >= 0) {
rule.grade = 4;
}
});
$scope.rulesPageConfig.totalCount = $scope.rules.length;
@@ -107,9 +109,9 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
$scope.currentRule = rule;
var ruleTypeDesc = '';
var ruleTypeCount = null;
if (rule.avgLoad != -1) {
ruleTypeDesc = 'LOAD';
ruleTypeCount = rule.avgLoad;
if (rule.highestSystemLoad != -1) {
ruleTypeDesc = '系统LOAD';
ruleTypeCount = rule.highestSystemLoad;
} else if (rule.avgRt != -1) {
ruleTypeDesc = 'RT';
ruleTypeCount = rule.avgRt;
@@ -119,6 +121,9 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
} else if (rule.qps != -1) {
ruleTypeDesc = 'QPS';
ruleTypeCount = rule.qps;
}else if (rule.highestCpuUsage != -1) {
ruleTypeDesc = 'CPU 使用率';
ruleTypeCount = rule.highestCpuUsage;
}

$scope.confirmDialog = {
@@ -159,8 +164,10 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
if (data.code == 0) {
getMachineRules();
confirmDialog.close();
} else {
alert
} else if(data.msg!=null){
alert(data.msg);
} else{
alert('失败!');
}
});
};
@@ -170,8 +177,10 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
if (data.code == 0) {
getMachineRules();
systemRuleDialog.close();
} else {
alert('失败!');
} else if(data.msg!=null){
alert(data.msg);
}else{
alert('失败!');
}
});
};
@@ -190,8 +199,10 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
} else {
confirmDialog.close();
}
} else {
alert('失败!');
} else if(data.msg!=null){
alert(data.msg);
}else{
alert('失败!');
}
});
}


+ 7
- 2
sentinel-dashboard/src/main/webapp/resources/app/scripts/services/systemservice.js View File

@@ -21,13 +21,15 @@ app.service('SystemService', ['$http', function ($http) {
port: rule.port
};
if (rule.grade == 0) {// avgLoad
param.avgLoad = rule.avgLoad;
param.highestSystemLoad = rule.highestSystemLoad;
} else if (rule.grade == 1) {// avgRt
param.avgRt = rule.avgRt;
} else if (rule.grade == 2) {// maxThread
param.maxThread = rule.maxThread;
} else if (rule.grade == 3) {// qps
param.qps = rule.qps;
}else if (rule.grade == 4) {// cpu
param.highestCpuUsage = rule.highestCpuUsage;
}

return $http({
@@ -42,14 +44,17 @@ app.service('SystemService', ['$http', function ($http) {
id: rule.id,
};
if (rule.grade == 0) {// avgLoad
param.avgLoad = rule.avgLoad;
param.highestSystemLoad = rule.highestSystemLoad;
} else if (rule.grade == 1) {// avgRt
param.avgRt = rule.avgRt;
} else if (rule.grade == 2) {// maxThread
param.maxThread = rule.maxThread;
} else if (rule.grade == 3) {// qps
param.qps = rule.qps;
}else if (rule.grade == 4) {// cpu
param.highestCpuUsage = rule.highestCpuUsage;
}

return $http({
url: '/system/save.json',
params: param,


+ 17
- 16
sentinel-dashboard/src/main/webapp/resources/app/views/dialog/system-rule-dialog.html View File

@@ -9,40 +9,41 @@
<label class="col-sm-2 control-label">阈值类型</label>
<div class="col-sm-9">
<div class="form-control" ng-if="systemRuleDialog.type == 'edit'" align="center">
<!--avgLoad -->
<input type="radio" name="grade" value="0" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;LOAD&nbsp;&nbsp;
<!--highestSystemLoad -->
<input type="radio" name="grade" value="0" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;系统LOAD&nbsp;&nbsp;
<!--avgRt -->
<input type="radio" name="grade" value="1" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;RT&nbsp;&nbsp;
<!--maxThread -->
<input type="radio" name="grade" value="2" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;线程数&nbsp;&nbsp;
<!--qps -->
<input type="radio" name="grade" value="3" checked ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'"
/>&nbsp;入口 QPS
<input type="radio" name="grade" value="3" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'"/>&nbsp;入口 QPS
<!--highestCpuUsage -->
<input type="radio" name="grade" value="4" checked ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;CPU 使用率&nbsp;&nbsp;

</div>
<div class="form-control highlight-border" ng-if="systemRuleDialog.type == 'add'" align="center">
<!--avgLoad -->
<input type="radio" name="grade" value="0" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;LOAD&nbsp;&nbsp;
<!--highestSystemLoad -->
<input type="radio" name="grade" value="0" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;系统LOAD&nbsp;&nbsp;
<!--avgRt -->
<input type="radio" name="grade" value="1" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;RT&nbsp;&nbsp;
<!--maxThread -->
<input type="radio" name="grade" value="2" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;线程数&nbsp;&nbsp;
<!--qps -->
<input type="radio" name="grade" value="3" checked ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'"
/>&nbsp;入口 QPS
<input type="radio" name="grade" value="3" ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'"/>&nbsp;入口 QPS
<!--highestCpuUsage -->
<input type="radio" name="grade" value="4" checked ng-model='currentRule.grade' ng-disabled="systemRuleDialog.type == 'edit'" />&nbsp;CPU 使用率&nbsp;&nbsp;

</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">阈值</label>
<div class="col-sm-9">
<input type='number' class="form-control highlight-border" ng-model='currentRule.avgLoad' placeholder="[0, ~)的小数" ng-if="currentRule.grade == 0"
/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.avgRt' placeholder="[0, ~)的整数" ng-if="currentRule.grade == 1"
/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.maxThread' placeholder="[0, ~)的整数" ng-if="currentRule.grade == 2"
/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.qps' placeholder="[0, ~)的小数" ng-if="currentRule.grade == 3"
/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.highestSystemLoad' placeholder="[0, ~)的正整数" ng-if="currentRule.grade == 0"/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.avgRt' placeholder="[0, ~)的正整数" ng-if="currentRule.grade == 1"/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.maxThread' placeholder="[0, ~)的正整数" ng-if="currentRule.grade == 2"/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.qps' placeholder="[0, ~)的正整数" ng-if="currentRule.grade == 3"/>
<input type='number' class="form-control highlight-border" ng-model='currentRule.highestCpuUsage' placeholder="[0, 1)的小数" ng-if="currentRule.grade == 4"/>
</div>
</div>
</form>


+ 4
- 2
sentinel-dashboard/src/main/webapp/resources/app/views/system.html View File

@@ -45,16 +45,18 @@
<tr dir-paginate="rule in rules | filter : searchKey | itemsPerPage: rulesPageConfig.pageSize " current-page="rulesPageConfig.currentPageIndex"
pagination-id="entriesPagination">
<td style="word-wrap:break-word;word-break:break-all;">
<span ng-if="rule.avgLoad >= 0">LOAD</span>
<span ng-if="rule.highestSystemLoad >= 0">系统LOAD</span>
<span ng-if="rule.avgRt >= 0">RT</span>
<span ng-if="rule.maxThread >= 0">线程数</span>
<span ng-if="rule.qps >= 0">QPS</span>
<span ng-if="rule.highestCpuUsage >= 0">CPU使用率</span>
</td>
<td style="word-wrap:break-word;word-break:break-all;">
<span ng-if="rule.avgLoad >= 0">{{rule.avgLoad}}</span>
<span ng-if="rule.highestSystemLoad >= 0">{{rule.highestSystemLoad}}</span>
<span ng-if="rule.avgRt >= 0">{{rule.avgRt}}</span>
<span ng-if="rule.maxThread >= 0">{{rule.maxThread}}</span>
<span ng-if="rule.qps >= 0">{{rule.qps}}</span>
<span ng-if="rule.highestCpuUsage >= 0">{{rule.highestCpuUsage}}</span>
</td>
<td>
<button class="btn btn-xs btn-default" type="button" ng-click="editRule(rule)" style="font-size: 12px; height:25px;">编辑</button>


+ 4
- 1
sentinel-dashboard/src/main/webapp/resources/dist/js/app.js
File diff suppressed because it is too large
View File


Loading…
Cancel
Save