Added printing of histogram json.
authorMisha Zatsman <misha-arvados@zatsman.com>
Tue, 6 May 2014 23:30:26 +0000 (23:30 +0000)
committerMisha Zatsman <misha-arvados@zatsman.com>
Tue, 6 May 2014 23:30:26 +0000 (23:30 +0000)
apps/workbench/app/controllers/keep_disks_controller.rb
apps/workbench/app/views/keep_disks/_content_layout.html.erb

index 0e1a9818ed8d38fc9f8d76d589ccd88ce23a8204..b7bc7c06dcf0f333459e4933be7e5c8f4743c75e 100644 (file)
@@ -5,7 +5,27 @@ class KeepDisksController < ApplicationController
     super
   end
   def index
-    # TODO(misha):Retrieve the histogram info
+
+    # Retrieve cache age histogram info
+    @cache_age_histogram = []
+    @histogram_date = 0
+    histogram_log = Log.
+      filter([[:event_type, '=', 'block-age-free-space-histogram']]).
+      order(:created_at => :desc).
+      limit(1)
+    histogram_log.each do |log_entry|
+      # We expect this block to only execute at most once since we
+      # specified limit(1)
+      @cache_age_histogram = log_entry['properties'][:histogram]
+      # Javascript wants dates in milliseconds.
+      @histogram_date = log_entry['event_at'].to_i * 1000
+
+      total_free_cache = @cache_age_histogram[-1][1]
+      persisted_storage = 1 - total_free_cache
+      @cache_age_histogram.map! { |x| {:age => @histogram_date - x[0]*1000,
+          :cache => total_free_cache - x[1],
+          :persisted => persisted_storage} }
+    end
     super
   end
 end
index 7178b9c419a4ce87fec2af7278d417525737db23..cbad20ab3f58be3df5820aa129531cdd17e0f436 100644 (file)
@@ -1,5 +1,9 @@
 <% content_for :tab_panes do %>
-<div class='cache-age-vs-disk-histogram'>Histogram will go here.</div>
+  <div class='cache-age-vs-disk-histogram'>
+    <%= raw @cache_age_histogram.to_json %>
+    <br>
+    <%= @histogram_date %>
+  </div>
 <% end %>
 <%= content_for :content_top %>
 <%= content_for :tab_line_buttons %>