Project

General

Profile

Download (2.37 KB) Statistics
| Branch: | Tag: | Revision:
90b70658 Ohad Levy
class DashboardController < ApplicationController
ef14965b Ohad Levy
before_filter :prefetch_data, :graphs, :only => :index
16cb7742 Ohad Levy
helper :hosts
90b70658 Ohad Levy
def index
16cb7742 Ohad Levy
end

def errors
ef14965b Ohad Levy
@search = Host.recent.with_error.search(params[:search])
hosts = @search.paginate :page => params[:page]
16cb7742 Ohad Levy
render :partial => "hosts/minilist", :layout => true, :locals => {
4e42b118 Ohad Levy
:hosts => hosts,
16cb7742 Ohad Levy
:header => "Hosts with errors" }
end

def active
ef14965b Ohad Levy
@search = Host.recent.with_changes.search(params[:search])
hosts = @search.paginate :page => params[:page]
16cb7742 Ohad Levy
render :partial => "hosts/minilist", :layout => true, :locals => {
4e42b118 Ohad Levy
:hosts => hosts,
16cb7742 Ohad Levy
:header => "Active Hosts" }
end

def OutOfSync
ef14965b Ohad Levy
@search = Host.out_of_sync.search(params[:search])
hosts = @search.paginate :page => params[:page]
16cb7742 Ohad Levy
render :partial => "hosts/minilist", :layout => true, :locals => {
4e42b118 Ohad Levy
:hosts => hosts,
e386628a Ohad Levy
:header => "Hosts which didnt run puppet in the last #{SETTINGS[:puppet_interval]} minutes" }
90b70658 Ohad Levy
end

private
c6f1b718 Ohad Levy
def graphs

data ={
:labels => [ ['string', "State"], ['number', "Number of Hosts"] ],
:values => [ ["Active", @active_hosts],["Error", @bad_hosts ], ["Out Of Sync", @out_of_sync_hosts ], ["OK", @good_hosts] ]
}
options = { :title => "Puppet Clients Activity Overview"}#,
# :colors =>['#0000FF','#FF0000','#00FF00','#41A317'] }
@overview = setgraph(GoogleVisualr::PieChart.new, data, options)

data = {
:labels => [ ['datetime', "Time Ago In Minutes" ],['number', "Number Of Clients"]],
:values => Report.count_puppet_runs()
}
options = { :title => "Run Distribution in the last #{SETTINGS[:puppet_interval]} minutes", :min => 0 }
@run_distribution = setgraph(GoogleVisualr::ColumnChart.new, data, options)

end

def prefetch_data

@total_hosts = Host.count
# hosts with errors in the last puppet run
@bad_hosts = Host.recent.with_error.count
# hosts with changes in the last puppet run
@active_hosts = Host.recent.with_changes.count
@good_hosts = Host.recent.successful.count

@percentage = (@good_hosts == 0 or @total_hosts == 0) ? 0 : @good_hosts *100 / @total_hosts

# all hosts with didn't run puppet in the <time interval> - regardless of their status
@out_of_sync_hosts = Host.out_of_sync.count
@intersting_reports = Report.with_changes.count
# the run interval to show in the dashboard graph
90b70658 Ohad Levy
end

e386628a Ohad Levy
end