Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the problem that dashboard do not correctly show the SystemRule in CPU usage strategy #922

Closed
wants to merge 6 commits into from
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -33,6 +33,7 @@ public class SystemRuleEntity implements RuleEntity {
private Long avgRt;
private Long maxThread;
private Double qps;
private Double avgCpu;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's better to be maxCpuUsage?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I saw properties in SystemRule named highestSystemLoad and it named avgLoad in SystemRuleEntity ,so i just do like to name highestCpuUsage in SystemRule to avgCpu in SystemRuleEntity

Copy link
Member

@sczyh30 sczyh30 Jul 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other legacy fields might not be good enough... For CPU usage it's an instantaneous value rather than average value.


private Date gmtCreate;
private Date gmtModified;
Expand All @@ -43,6 +44,7 @@ public static SystemRuleEntity fromSystemRule(String app, String ip, Integer por
entity.setIp(ip);
entity.setPort(port);
entity.setAvgLoad(rule.getHighestSystemLoad());
entity.setAvgCpu(rule.getHighestCpuUsage());
entity.setAvgRt(rule.getAvgRt());
entity.setMaxThread(rule.getMaxThread());
entity.setQps(rule.getQps());
Expand Down Expand Up @@ -118,6 +120,14 @@ public void setQps(Double qps) {
this.qps = qps;
}

public Double getAvgCpu() {
return avgCpu;
}

public void setAvgCpu(Double avgCpu) {
this.avgCpu = avgCpu;
}

@Override
public Date getGmtCreate() {
return gmtCreate;
Expand All @@ -142,6 +152,7 @@ public SystemRule toRule() {
rule.setAvgRt(avgRt);
rule.setMaxThread(maxThread);
rule.setQps(qps);
rule.setHighestCpuUsage(avgCpu);
return rule;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.avgCpu >= 0) {
rule.grade = 4;
}
});
$scope.rulesPageConfig.totalCount = $scope.rules.length;
Expand Down Expand Up @@ -119,6 +121,9 @@ app.controller('SystemCtl', ['$scope', '$stateParams', 'SystemService', 'ngDialo
} else if (rule.qps != -1) {
ruleTypeDesc = 'QPS';
ruleTypeCount = rule.qps;
}else if (rule.avgCpu != -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto (maxCpuUsage)

ruleTypeDesc = 'CPU';
ruleTypeCount = rule.avgCpu;
}

$scope.confirmDialog = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ app.service('SystemService', ['$http', function ($http) {
param.maxThread = rule.maxThread;
} else if (rule.grade == 3) {// qps
param.qps = rule.qps;
}else if (rule.grade == 4) {// cpu
param.avgCpu = rule.avgCpu;
}

return $http({
Expand All @@ -49,6 +51,8 @@ app.service('SystemService', ['$http', function ($http) {
param.maxThread = rule.maxThread;
} else if (rule.grade == 3) {// qps
param.qps = rule.qps;
}else if (rule.grade == 4) {// cpu
param.avgCpu = rule.avgCpu;
}
return $http({
url: '/system/save.json',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@
<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.avgCpu >= 0">CPU</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CPU 使用率 可能更合适些?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i know it's much better but i just confused by the AvgLoad ,i can fix both two of them

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's indeed confusing. You could fix that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image
I left a problem that i am not good at,while i try to choose another ,it does not show like i want
image

</td>
<td style="word-wrap:break-word;word-break:break-all;">
<span ng-if="rule.avgLoad >= 0">{{rule.avgLoad}}</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.avgCpu >= 0">{{rule.avgCpu}}</span>
</td>
<td>
<button class="btn btn-xs btn-default" type="button" ng-click="editRule(rule)" style="font-size: 12px; height:25px;">编辑</button>
Expand Down