administrator dashboard for observing the Docker container pool

This commit is contained in:
Hauke Klement
2015-02-10 12:23:26 +01:00
parent 7ab57403df
commit 59ca0a57c3
10 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,35 @@
$(function() {
var REFRESH_INTERVAL = 5000;
var refreshData = function() {
var jqxhr = $.ajax({
dataType: 'json',
method: 'GET'
});
jqxhr.done(updateView);
};
var updateProgressBar = function(progress_bar, data) {
var percentage = Math.round(data.quantity / data.pool_size * 100);
progress_bar.attr({
'aria-valuemax': data.pool_size,
'aria-valuenow': data.quantity,
style: 'width: ' + percentage + '%'
});
progress_bar.html(data.quantity);
};
var updateView = function(response) {
_.each(response.docker, function(data) {
var row = $('tbody tr[data-id=' + data.id + ']');
$('.pool-size', row).html(data.pool_size);
var progress_bar = $('.quantity .progress .progress-bar', row);
updateProgressBar(progress_bar, data);
});
};
if ($.isController('dashboard')) {
refreshData();
setInterval(refreshData, REFRESH_INTERVAL);
}
});

View File

@ -0,0 +1,17 @@
module Admin
class DashboardController < ApplicationController
include DashboardHelper
def policy_class
DashboardPolicy
end
def show
authorize(self)
respond_to do |format|
format.html
format.json { render(json: dashboard_data) }
end
end
end
end

View File

@ -0,0 +1,13 @@
module Admin
module DashboardHelper
def dashboard_data
{docker: docker_data}
end
def docker_data
ExecutionEnvironment.order(:id).select(:id, :permitted_execution_time, :pool_size).map do |execution_environment|
execution_environment.attributes.merge(quantity: DockerContainerPool.quantities[execution_environment.id])
end
end
end
end

View File

@ -0,0 +1,4 @@
module Admin
class DashboardPolicy < AdminOnlyPolicy
end
end

View File

@ -0,0 +1,20 @@
h1 = t('breadcrumbs.dashboard.show')
h2 Docker
- if DockerContainerPool.config[:active]
.table-responsive
table.table
thead
tr
th = t('activerecord.models.execution_environment.one')
th = t('activerecord.attributes.execution_environment.pool_size')
th = t('.quantity')
tbody
- ExecutionEnvironment.order(:name).each do |execution_environment|
tr data-id=execution_environment.id
td = link_to(execution_environment, execution_environment)
td.pool-size
td.quantity = progress_bar(0)
- else
p = t('.inactive')