Display correct Power Consumption & Cap values
Current values are hard coded to '000 W'.
This fix is to do REST calls and display the correct values.
Resolves openbmc/openbmc#2735
Change-Id: I2f6766f1685a2bd52da62cda19998794f80270ec
Signed-off-by: CamVan Nguyen <ctnguyen@us.ibm.com>
diff --git a/app/common/services/api-utils.js b/app/common/services/api-utils.js
index f73a584..431c7ce 100644
--- a/app/common/services/api-utils.js
+++ b/app/common/services/api-utils.js
@@ -12,6 +12,18 @@
angular
.module('app.common.services')
.factory('APIUtils', ['$http', 'Constants', '$q', 'dataService',function($http, Constants, $q, DataService){
+ var getScaledValue = function(value, scale){
+ scale = scale + "";
+ scale = parseInt(scale, 10);
+ var power = Math.abs(parseInt(scale,10));
+
+ if(scale > 0){
+ value = value * Math.pow(10, power);
+ }else if(scale < 0){
+ value = value / Math.pow(10, power);
+ }
+ return value;
+ };
var SERVICE = {
API_CREDENTIALS: Constants.API_CREDENTIALS,
API_RESPONSE: Constants.API_RESPONSE,
@@ -523,19 +535,6 @@
var order = 0;
var customOrder = 0;
- function getScaledValue(value, scale){
- scale = scale + "";
- scale = parseInt(scale, 10);
- var power = Math.abs(parseInt(scale,10));
-
- if(scale > 0){
- value = value * Math.pow(10, power);
- }else if(scale < 0){
- value = value / Math.pow(10, power);
- }
- return value;
- }
-
function getSensorStatus(reading){
var severityFlags = {critical: false, warning: false, normal: false}, severityText = '', order = 0;
@@ -1060,6 +1059,50 @@
return defer.promise;
},
+ getPowerConsumption: function(){
+ return $http({
+ method: 'GET',
+ url: DataService.getHost() + "/xyz/openbmc_project/sensors/power/total_power",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
+ var content = JSON.parse(json);
+
+ return getScaledValue(content.data.Value,
+ content.data.Scale) + ' ' +
+ Constants.POWER_CONSUMPTION_TEXT[content.data.Unit];
+ }, function(error){
+ if ('Not Found' == error.statusText) {
+ return Constants.POWER_CONSUMPTION_TEXT.notavailable;
+ } else {
+ console.log(error);
+ }
+ });
+ },
+ getPowerCap: function(){
+ return $http({
+ method: 'GET',
+ url: DataService.getHost() + "/xyz/openbmc_project/control/host0/power_cap",
+ headers: {
+ 'Accept': 'application/json',
+ 'Content-Type': 'application/json'
+ },
+ withCredentials: true
+ }).then(function(response){
+ var json = JSON.stringify(response.data);
+ var content = JSON.parse(json);
+
+ return (false == content.data.PowerCapEnable) ?
+ Constants.POWER_CAP_TEXT.disabled :
+ content.data.PowerCap + ' ' + Constants.POWER_CAP_TEXT.unit;
+ }, function(error){
+ console.log(error);
+ });
+ },
};
return SERVICE;
}]);
diff --git a/app/common/services/constants.js b/app/common/services/constants.js
index af0965d..0bb2123 100644
--- a/app/common/services/constants.js
+++ b/app/common/services/constants.js
@@ -122,7 +122,15 @@
CRITICAL_NO_SENSOR_DATA: 'There are no sensors in Critical state.',
WARNING_NO_SENSOR_DATA: 'There are no sensors in Warning state.'
}
- }
+ },
+ POWER_CAP_TEXT: {
+ unit: 'W',
+ disabled: 'Not Enabled'
+ },
+ POWER_CONSUMPTION_TEXT: {
+ 'xyz.openbmc_project.Sensor.Value.Unit.Watts': 'W',
+ notavailable: 'Not Available'
+ },
};
});
diff --git a/app/overview/controllers/system-overview-controller.html b/app/overview/controllers/system-overview-controller.html
index 094fac0..346e6e1 100644
--- a/app/overview/controllers/system-overview-controller.html
+++ b/app/overview/controllers/system-overview-controller.html
@@ -67,11 +67,11 @@
<ul class="overview__metadata-wrapper">
<li class="overview__metadata-block">
<p class="content-label">Power Consumption</p>
- <p class="courier-bold">000 W</p>
+ <p class="courier-bold">{{power_consumption}}</p>
</li>
<li class="overview__metadata-block">
<p class="content-label">Power Cap</p>
- <p class="courier-bold">000 W</p>
+ <p class="courier-bold">{{power_cap}}</p>
</li>
</ul>
</div>
diff --git a/app/overview/controllers/system-overview-controller.js b/app/overview/controllers/system-overview-controller.js
index 2382a2a..af70d15 100644
--- a/app/overview/controllers/system-overview-controller.js
+++ b/app/overview/controllers/system-overview-controller.js
@@ -28,6 +28,8 @@
$scope.bmc_info = {};
$scope.bmc_firmware = "";
$scope.server_firmware = "";
+ $scope.power_consumption = "";
+ $scope.power_cap = "";
$scope.loading = false;
loadOverviewData();
@@ -38,7 +40,9 @@
firmware: APIUtils.getFirmwares(),
led: APIUtils.getLEDState(),
ethernet: APIUtils.getBMCEthernetInfo(),
- bmc_info: APIUtils.getBMCInfo()
+ bmc_info: APIUtils.getBMCInfo(),
+ power_consumption: APIUtils.getPowerConsumption(),
+ power_cap: APIUtils.getPowerCap(),
};
$q.all(promises)
.then(function(data){
@@ -51,6 +55,8 @@
$scope.displayLEDState(data.led);
$scope.displayBMCEthernetInfo(data.ethernet);
$scope.displayBMCInfo(data.bmc_info);
+ $scope.displayPowerConsumption(data.power_consumption);
+ $scope.displayPowerCap(data.power_cap);
})
.finally(function(){
$scope.loading = false;
@@ -92,6 +98,14 @@
});
}
+ $scope.displayPowerConsumption = function(data){
+ $scope.power_consumption = data;
+ }
+
+ $scope.displayPowerCap = function(data){
+ $scope.power_cap = data;
+ }
+
var refreshDataListener = $rootScope.$on('refresh-data', function(event, args) {
loadOverviewData();
});