Project

General

Profile

« Previous | Next » 

Revision 0bb7ac8f

Added by Brian Gupta about 12 years ago

  • ID 0bb7ac8f3f071543bcb52c2c214708d8ebfb21a8

Changes to dashboard statistics. Fixes #1617

View differences:

app/controllers/dashboard_controller.rb
def prefetch_data
@hosts = Host.search_for(params[:search])
@report = {
:total_hosts => @hosts.count,
:bad_hosts => @hosts.recent.with_error.count,
:active_hosts => @hosts.recent.with_changes.count,
:active_hosts_ok => @hosts.recent.with_changes.without_error.count,
:ok_hosts => @hosts.recent.successful.count,
:out_of_sync_hosts => @hosts.out_of_sync.count,
:disabled_hosts => @hosts.alerts_disabled.count,
:pending_hosts => @hosts.recent.with_pending_changes.count,
:total_hosts => @hosts.count,
:bad_hosts => @hosts.recent.with_error.count,
:bad_hosts_enabled => @hosts.recent.with_error.alerts_enabled.count,
:active_hosts => @hosts.recent.with_changes.count,
:active_hosts_ok => @hosts.recent.with_changes.without_error.count,
:active_hosts_ok_enabled => @hosts.recent.with_changes.without_error.alerts_enabled.count,
:ok_hosts => @hosts.recent.successful.count,
:ok_hosts_enabled => @hosts.recent.successful.count,
:out_of_sync_hosts => @hosts.out_of_sync.count,
:out_of_sync_hosts_enabled => @hosts.out_of_sync.alerts_enabled.count,
:disabled_hosts => @hosts.alerts_disabled.count,
:pending_hosts => @hosts.recent.with_pending_changes.count,
:pending_hosts_enabled => @hosts.recent.with_pending_changes.alerts_enabled.count,
}
@report[:good_hosts] = @report[:ok_hosts] + @report[:active_hosts_ok]
@report[:good_hosts_enabled] = @report[:ok_hosts_enabled] + @report[:active_hosts_ok_enabled]
@report[:percentage] = (@report[:good_hosts] == 0 or @report[:total_hosts] == 0) ? 0 : @report[:good_hosts]*100 / @report[:total_hosts]
@report[:reports_missing] = @report[:total_hosts] - @report[:good_hosts] - @report[:bad_hosts] - @report[:out_of_sync_hosts] - @report[:pending_hosts]
@report[:reports_missing] = @report[:total_hosts] - @report[:good_hosts_enabled] - @report[:bad_hosts_enabled] - @report[:out_of_sync_hosts_enabled] - @report[:pending_hosts_enabled] - @report[:disabled_hosts]
end
end
app/helpers/dashboard_helper.rb
end
def render_overview report, options = {}
data = [[:Active, report[:active_hosts]],
[:Error, report[:bad_hosts]],
data = [[:Active, report[:active_hosts_ok_enabled]],
[:Error, report[:bad_hosts_enabled]],
[:OK, report[:ok_hosts]],
[:'Pending changes', report[:pending_hosts]],
[:'Out of sync', report[:out_of_sync_hosts]],
[:'Pending changes', report[:pending_hosts_enabled]],
[:'Out of sync', report[:out_of_sync_hosts_enabled]],
[:'No report', report[:reports_missing]],
[:'Notification disabled', report[:disabled_hosts]]]
pie_chart 'overview', 'Puppet Clients Activity Overview', data, options
app/models/host.rb
scope :alerts_disabled, {:conditions => ["enabled = ?", false] }
scope :alerts_enabled, {:conditions => ["enabled = ?", true] }
scope :my_hosts, lambda {
user = User.current
owner_conditions = sanitize_sql_for_conditions(["((hosts.owner_id in (?) AND hosts.owner_type = 'Usergroup') OR (hosts.owner_id = ? AND hosts.owner_type = 'User'))", user.my_usergroups.map(&:id), user.id])
app/views/dashboard/index.html.erb
<th>Data</th>
</tr>
<tr>
<td><%= searchable_links 'Hosts that had performed modifications', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.applied > 0 or status.restarted > 0)" %></td>
<td><%= @report[:active_hosts] %> </td>
<td><%= searchable_links 'Hosts that had performed modifications without error', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.applied > 0 or status.restarted > 0) and (status.failed = 0)" %></td>
<td><%= @report[:active_hosts_ok_enabled] %> </td>
</tr>
<tr>
<td><%= searchable_links 'Hosts in Error State', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.failed > 0 or status.failed_restarts > 0)" %></td>
<td><%= @report[:bad_hosts] %> </td>
<td><%= searchable_links 'Hosts in Error State', "last_report > \"#{Setting[:puppet_interval] + 5} minutes ago\" and (status.failed > 0 or status.failed_restarts > 0) and status.enabled = true" %></td>
<td><%= @report[:bad_hosts_enabled] %> </td>
</tr>
<tr>
<td><%=searchable_links "Good Host Reports in the last #{Setting[:puppet_interval]+5} minutes", "last_report > \"#{Setting[:puppet_interval]+5} minutes ago\" and (status.enabled = true or status.applied =true) and status.failed = 0" %></td>
<td> <%= "#{@report[:good_hosts]} / #{@report[:total_hosts]}" %> hosts (<%= @report[:percentage] %>%)</td>
<td><%=searchable_links "Good Host Reports in the last #{Setting[:puppet_interval]+5} minutes", "last_report > \"#{Setting[:puppet_interval]+5} minutes ago\" and status.enabled = true and status.applied = 0 and status.failed = 0" %></td>
<td> <%= "#{@report[:good_hosts_enabled] - @report[:active_hosts_ok_enabled]} / #{@report[:total_hosts]}" %> hosts (<%= @report[:percentage] %>%)</td>
</tr>
<tr>
<td><%= searchable_links 'Hosts that had pending changes', 'status.pending > 0' %></td>
<td><%= @report[:pending_hosts] %> </td>
<td><%= searchable_links 'Hosts that had pending changes', 'status.pending > 0 and status.enabled = true' %></td>
<td><%= @report[:pending_hosts_enabled] %> </td>
</tr>
<tr>
<td><%= searchable_links 'Out Of Sync Hosts', "last_report < \"#{Setting[:puppet_interval] + 5} minutes ago\" and status.enabled = true" %></td>
<td><%= @report[:out_of_sync_hosts] %> </td>
<td><%= @report[:out_of_sync_hosts_enabled] %> </td>
</tr>
<tr>
<td><%= searchable_links 'Hosts With No Reports', "not has last_report" %></td>
<td><%= searchable_links 'Hosts With No Reports', "not has last_report and status.enabled = true" %></td>
<td><%= @report[:reports_missing] %> </td>
</tr>
<tr>

Also available in: Unified diff