Skip to content
This repository has been archived by the owner on Oct 24, 2023. It is now read-only.

Commit

Permalink
Fixes for when ES is unconnectable. Rejiggered dashboard a bit. Updat…
Browse files Browse the repository at this point in the history
…ed readme and sample config.ru.
  • Loading branch information
PatrickTulskie committed May 1, 2013
1 parent 5c625eb commit 3924bf4
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 8 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,22 @@ Load it in your `config.ru` file with an instance of `ElasticSearch::Client`

map '/elasticboard' do
run ElasticBoard::Application.new(
:connection => ElasticSearch.new("localhost:9200")
:connection => (ElasticSearch.new("localhost:9200") rescue nil)
)
end

If you use something like Escargot and ActiveRecord in your application, you can re-use the connection like so:

map '/elasticboard' do
run ElasticBoard::Application.new(
:connection => Escargot.connection
:connection => (Escargot.connection rescue nil)
)
end

From there, just go to `/elasticboard` and check it out.

Note: `rescue nil` is a nice safety in the event that your app is unable to connect to ElasticSearch, it will still boot. If you don't leave ES running on your development machine, this will let your app continue to boot regardless of whether or not ES is running. ElasticBoard will handle a nil connection gracefully.

## Contributing

1. Fork it
Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ require "rubberband"
require "elastic_board"

map '/elasticboard' do
run ElasticBoard::Application.new(:connection => ElasticSearch.new("localhost:9200"))
run ElasticBoard::Application.new(:connection => (ElasticSearch.new("localhost:9200") rescue nil))
end
9 changes: 6 additions & 3 deletions lib/elastic_board.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,12 @@ def header_badge(summary)
# ==================

get '/' do
@summary = ElasticBoard::Summary.new(self.connection)

erb :index
if self.connection
@summary = ElasticBoard::Summary.new(self.connection)
erb :index
else
erb :down
end
end

end
Expand Down
8 changes: 8 additions & 0 deletions lib/elastic_board/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,14 @@ def unassigned_shards
cluster_health['unassigned_shards']
end

def cluster_health_notice
if unassigned_shards.to_i > 0
"Unassigned Shards Greater than Zero"
else
return nil
end
end

private

def extract_ip_from_address(address)
Expand Down
48 changes: 48 additions & 0 deletions lib/elastic_board/views/down.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="#">ElasticBoard</a>
<span class="badge badge-important" style="margin-top:11px;">Unable to Connect to ElasticSearch</span>
</div>
</div>
</div>

<div class="container">

<!-- Example row of columns -->
<div class="row">
<div class="span6">
<h2>Cluster Health <span class="badge badge-important">Down</span></h2>
<div class="well well-top">
<table class="summary_table">
<tr><td style="font-weight: bold">Number of Nodes</td><td>0</td></tr>
<tr><td style="font-weight: bold">Active Shards</td><td>0</td></tr>
<tr><td style="font-weight: bold">Active Primary Shards</td><td>0</td></tr>
<tr><td style="font-weight: bold">Unassigned Shards</td><td>0</td></tr>
</table>
</div>
</div>
<div class="span6">
<h2>Nodes in Cluster</h2>
<div class="well well-top">
<table class="summary_table">
</table>
</div>
</div>
</div>

<!-- Main hero unit for a primary marketing message or call to action -->
<div class="container">
<h2>Indexes</h2>
<div class="well">
<h2>Unable to connect to ElasticSearch</h2>
</div>
</div>

<hr>

<footer>
<p>&copy; ElasticBoard 2013</p>
</footer>

</div>
4 changes: 2 additions & 2 deletions lib/elastic_board/views/index.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<!-- Example row of columns -->
<div class="row">
<div class="span6">
<h2>Cluster Health <span class="badge badge-<%= @summary.nodes_info['ok'] ? 'success' : 'important' %>"><%= @summary.nodes_info['ok'] ? 'Healthy' : 'Problem' %></span></h2>
<h2>Cluster Health <span class="badge badge-<%= @summary.cluster_health_notice.nil? ? 'success' : 'warning' %>"><%= @summary.cluster_health_notice.nil? ? 'Healthy' : @summary.cluster_health_notice %></span></h2>
<div class="well well-top">
<table class="summary_table">
<tr><td style="font-weight: bold">Number of Nodes</td><td><%= @summary.number_of_nodes %></td></tr>
Expand All @@ -23,7 +23,7 @@
</div>
</div>
<div class="span6">
<h2>Nodes in Cluster</h2>
<h2>Nodes in Cluster <span class="badge badge-<%= @summary.nodes_info['ok'] ? 'success' : 'important' %>"><%= @summary.nodes_info['ok'] ? 'Healthy' : 'Problem' %></span></h2>
<div class="well well-top">
<table class="summary_table">
<% @summary.nodes.each do |node| %>
Expand Down

0 comments on commit 3924bf4

Please sign in to comment.