Project

General

Profile

« Previous | Next » 

Revision bf59cec1

Added by Tomer Brisker over 9 years ago

Fixes #2232 - speed up Host view via AJAX

View differences:

app/assets/javascripts/charts.js
flot_time_chart(target, data, {show: false});
}
function updateChart(item, status) {
if (status == 'success')
$(item).find(".statistics-chart").flot_chart();
else
$(item).text(__("Failed to load chart"));
}
$(function() {
$(".statistics-pie").flot_pie();
$(".statistics-bar").flot_bar();
app/assets/stylesheets/charts.scss
font-size: 14px;
}
#host-show .statistics-chart{
height: 230px;
#host-show{
.statistics-chart{
height: 230px;
}
.chart{
height: 250px;
}
}
.reset-zoom{
app/controllers/hosts_controller.rb
add_puppetmaster_filters PUPPETMASTER_ACTIONS
before_filter :ajax_request, :only => AJAX_REQUESTS
before_filter :find_by_name, :only => [:show, :clone, :edit, :update, :destroy, :puppetrun,
:setBuild, :cancelBuild, :power, :bmc, :vm, :ipmi_boot,
:console, :toggle_manage, :pxe_config,
:storeconfig_klasses, :disassociate]
:setBuild, :cancelBuild, :power, :overview, :bmc, :vm,
:runtime, :resources, :templates, :ipmi_boot, :console,
:toggle_manage, :pxe_config, :storeconfig_klasses, :disassociate]
before_filter :taxonomy_scope, :only => [:new, :edit] + AJAX_REQUESTS
before_filter :set_host_type, :only => [:update]
before_filter :find_multiple, :only => MULTIPLE_ACTIONS
......
process_error :redirect => :back, :error_msg => _("Failed to %{action} %{host}: %{e}") % { :action => _(params[:power_action]), :host => @host, :e => e }
end
def overview
render :partial => 'overview', :locals => { :host => @host }
rescue ActionView::Template::Error => exception
process_ajax_error exception, 'fetch overview information'
end
def bmc
render :partial => 'bmc', :locals => { :host => @host }
rescue ActionView::Template::Error => exception
......
process_ajax_error exception, 'fetch vm information'
end
def runtime
render :partial => 'runtime'
rescue ActionView::Template::Error => exception
process_ajax_error exception, 'fetch runtime chart information'
end
def resources
render :partial => 'resources'
rescue ActionView::Template::Error => exception
process_ajax_error exception, 'fetch resources chart information'
end
def templates
render :text => view_context.show_templates
rescue ActionView::Template::Error => exception
process_ajax_error exception, 'fetch templates information'
end
def ipmi_boot
device = params[:ipmi_device]
device_id = BOOT_DEVICES.stringify_keys[device.downcase] || device
......
def action_permission
case params[:action]
when 'clone', 'externalNodes', 'bmc', 'vm', 'pxe_config', 'storeconfig_klasses',
'active', 'errors', 'out_of_sync', 'pending', 'disabled'
when 'clone', 'externalNodes', 'overview', 'bmc', 'vm', 'runtime', 'resources', 'templates',
'pxe_config', 'storeconfig_klasses', 'active', 'errors', 'out_of_sync', 'pending', 'disabled'
:view
when 'puppetrun', 'multiple_puppetrun', 'update_multiple_puppetrun'
:puppetrun
app/services/foreman/access_permissions.rb
tasks_ajax_actions = [:show]
map.permission :view_hosts, {:hosts => [:index, :show, :errors, :active, :out_of_sync, :disabled, :pending, :vm,
:externalNodes, :pxe_config, :storeconfig_klasses, :auto_complete_search, :bmc],
:externalNodes, :pxe_config, :storeconfig_klasses, :auto_complete_search, :bmc,
:runtime, :resources, :templates, :overview],
:dashboard => [:OutOfSync, :errors, :active],
:unattended => [:template, :provision],
:"api/v1/hosts" => [:index, :show, :status],
app/views/hosts/_resources.html.erb
<%= flot_chart('resource_graph', '', _("Number of Events"), resources_chart(params["range"].to_i.days.ago)) %>
app/views/hosts/_runtime.html.erb
<%= flot_chart('runtime_graph','', _('Time in Seconds'), runtime_chart(params["range"].to_i.days.ago), :class=>"statistics-chart stack") %>
app/views/hosts/show.html.erb
<% end %>
</ul>
<div id="myTabContent" class="tab-content">
<div class="tab-pane active in" id="properties">
<%= render :partial => "hosts/overview", :locals => { :host => @host } %>
<div class="tab-pane active in" id="properties" data-ajax-url='<%= overview_host_path(@host)%>'>
<p id="spinner">
<%= image_tag 'spinner.gif' %>
<%= _('Loading host information ...') %>
</p>
</div>
<div class="tab-pane" id="metrics">
<% if @report_summary.size == 0 %>
......
<%= render :partial => "hosts/metrics", :locals => { :report_summary => @report_summary[@host.name][:metrics] } %>
<% end %>
</div>
<div class="tab-pane" id="template">
<%= show_templates %>
<div class="tab-pane" id="template" data-ajax-url='<%= templates_host_path(@host)%>'>
<p id="spinner">
<%= image_tag 'spinner.gif' %>
<%= _('Loading template information ...') %>
</p>
</div>
<% if @host.compute_resource_id %>
<div class="tab-pane" id="vm" data-ajax-url='<%= vm_host_path(@host)%>' data-on-complete='setPowerState'>
......
<div class="stats-well">
<h4 class="ca"><%= _("Runtime") %></h4>
<h6 class="ca"><%= n_("last %s day", "last %s days", @range) % @range %></h6>
<%= flot_chart 'runtime_graph','', _('Time in Seconds'), runtime_chart(@range.days.ago), :class=>"statistics-chart stack" %>
<div class="chart" data-ajax-url='<%= runtime_host_path(@host, :range => @range) %>' data-on-complete='updateChart'>
<p id="spinner">
<%= image_tag 'spinner.gif' %>
<%= _('Loading runtime information ...') %>
</p>
</div>
</div>
<div class="stats-well">
<h4 class="ca"><%= _("Resources") %></h4>
<h6 class="ca"><%= n_("last %s day", "last %s days", @range) % @range %></h6>
<%= flot_chart 'resource_graph', '', _("Number of Events"), resources_chart(@range.days.ago) %>
<div class="chart" data-ajax-url='<%= resources_host_path(@host, :range => @range) %>' data-on-complete='updateChart'>
<p id="spinner">
<%= image_tag 'spinner.gif' %>
<%= _('Loading resources information ...') %>
</p>
</div>
</div>
</div>
</div>
config/routes.rb
post 'environment_selected'
put 'power'
get 'console'
get 'overview'
get 'bmc'
get 'vm'
get 'runtime'
get 'resources'
get 'templates'
put 'ipmi_boot'
put 'disassociate'
end

Also available in: Unified diff