DRILL-6224: Publish metrics gauge values correctly

The `metrics.ftl` page had gauges incorrectly set to near zero values. The 
commit for metrics.ftl fixes that, and also provides an estimate of the current 
direct memory actively in use (based on the `drill.allocator.root.used` value 
reported by the Drillbit)

closes #1160


Project: http://git-wip-us.apache.org/repos/asf/drill/repo
Commit: http://git-wip-us.apache.org/repos/asf/drill/commit/3167771f
Tree: http://git-wip-us.apache.org/repos/asf/drill/tree/3167771f
Diff: http://git-wip-us.apache.org/repos/asf/drill/diff/3167771f

Branch: refs/heads/master
Commit: 3167771fa666af5dae3b839000fabddfb814f8e3
Parents: 590a72b
Author: Kunal Khatua <[email protected]>
Authored: Thu Mar 22 22:03:27 2018 -0700
Committer: Vitalii Diravka <[email protected]>
Committed: Sat Mar 24 20:35:32 2018 +0200

----------------------------------------------------------------------
 .../src/main/resources/rest/metrics/metrics.ftl | 39 +++++++++++++++-----
 1 file changed, 29 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/drill/blob/3167771f/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
----------------------------------------------------------------------
diff --git a/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl 
b/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
index fbd2f4e..dfa5ece 100644
--- a/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
+++ b/exec/java-exec/src/main/resources/rest/metrics/metrics.ftl
@@ -43,6 +43,11 @@
         <div id="totalUsage" class="progress-bar" role="progressbar" 
aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: 50%;">
         </div>
       </div>
+      Actively Used Direct (Estimate)
+      <div class="progress">
+        <div id="estDirectUsage" class="progress-bar" role="progressbar" 
aria-valuenow="50" aria-valuemin="0" aria-valuemax="100" style="width: 50%;">
+        </div>
+      </div>
     </div>
 
     <div id="mainDiv" class="col-md-9" role="main">
@@ -77,6 +82,15 @@
     var round = function(val, n) {
       return Math.round(val * Math.pow(10, n)) / Math.pow(10, n);
     };
+    var isAllocator = function(metricName) {
+      return (metricName.startsWith("drill.allocator"));
+    };
+    function getGBUsageText(val, perc) {
+      if (isNaN(perc)) {
+        perc = 0;
+      }
+      return round((val / 1073741824), 2) + "GB (" + Math.max(0, perc) + "%)";
+    }
 
     function updateGauges(gauges) {
       $("#gaugesTable").html(function() {
@@ -109,18 +123,23 @@
     };
 
     function updateBars(gauges) {
-      $.each(["heap","non-heap","total"], function(i, key) {
-        var used    = gauges[key + ".used"].value;
-        var max     = gauges[key + ".max"].value;
-        var usage   = round((used / 1073741824), 2) + "GB";
-        var percent = round((used / max), 2);
-
-        var styleVal = "width: " + percent + "%;"
-        $("#" + key + "Usage").attr({
+      $.each(["heap","non-heap","total","drill.allocator.root"], function(i, 
key) {
+        var used = gauges[key + ".used"].value;
+        var max;
+        if (isAllocator(key)) {
+          max = gauges[key + ".peak"].value;
+        } else {
+          max = gauges[key + ".max"].value;
+        }
+        var percent = round((100 * used / max), 2);
+        var usage = getGBUsageText(used, percent);
+
+        var styleVal = "width: " + percent + "%;color: #202020;white-space: 
nowrap"
+        $("#" + (isAllocator(key) ? "estDirect" : key) + "Usage").attr({
           "aria-valuenow" : percent,
           "style" : styleVal
         });
-        $("#" + key + "Usage").html(usage);
+        $("#" + (isAllocator(key) ? "estDirect" : key) + "Usage").html(usage);
       });
     };
 
@@ -159,7 +178,7 @@
     };
 
     update();
-    setInterval(update, 2000);
+    setInterval(update, 3000);
   </script>
 </#macro>
 

Reply via email to