ソースを参照

AMBARI-5009. 'Disk_total' for one host returns 0 and the UI displays -Infinity%.(xiwang)

Xi Wang 11 年 前
コミット
e1d621ce67

+ 14 - 3
ambari-web/app/controllers/main/charts/heatmap_metrics/heatmap_metric_diskspaceused.js

@@ -28,6 +28,7 @@ App.MainChartHeatmapDiskSpaceUsedMetric = App.MainChartHeatmapMetric.extend({
   slotDefinitionLabelSuffix: '%',
   metricMapper: function (json) {
     var hostToValueMap = {};
+    var self = this;
     var metricName = this.get('defaultMetric');
     if (json.items) {
       var props = metricName.split('.');
@@ -41,14 +42,24 @@ App.MainChartHeatmapDiskSpaceUsedMetric = App.MainChartHeatmapMetric.extend({
           }
         });
         if (value != null) {
-          var total = value.disk_total;
-          var free = value.disk_free;
-          value = (((total - free) * 100) / total).toFixed(1);
+          value = self.diskUsageFormatted(value.disk_total - value.disk_free, value.disk_total);
           var hostName = item.Hosts.host_name;
           hostToValueMap[hostName] = value;
         }
       });
     }
     return hostToValueMap;
+  },
+
+  /**
+   * Format percent disk usage to float with 2 digits
+   */
+  diskUsageFormatted: function(diskUsed, diskTotal) {
+    var diskUsage = (diskUsed) / diskTotal * 100;
+    if (isNaN(diskUsage) || diskUsage < 0 || diskUsage > 100) {
+      return Em.I18n.t('charts.heatmap.unknown');
+    }
+    var s = Math.round(diskUsage * Math.pow(10, 2)) / Math.pow(10, 2);
+    return isNaN(s) ? 0 : s;
   }
 });

+ 1 - 0
ambari-web/app/messages.js

@@ -1427,6 +1427,7 @@ Em.I18n.translations = {
 
   'hosts.host.serviceNotAvailable': 'Service not available on this host',
 
+  'hosts.host.metrics.dataUnavailable':'Data Unavailable',
   'hosts.host.metrics.cpu':'CPU Usage',
   'hosts.host.metrics.cpu.displayNames.cpu_wio':'CPU I/O Idle',
   'hosts.host.metrics.cpu.displayNames.cpu_idle':'CPU Idle',

+ 1 - 1
ambari-web/app/models/host.js

@@ -147,7 +147,7 @@ App.Host = DS.Model.extend({
    */
   diskUsageFormatted: function() {
     if (isNaN(this.get('diskUsage')) || this.get('diskUsage') < 0) {
-      return 'Data Unavailable';
+      return Em.I18n.t('hosts.host.metrics.dataUnavailable');
     }
     var s = Math.round(this.get('diskUsage') * Math.pow(10, 2)) / Math.pow(10, 2);
     if (isNaN(s)) {