diff --git a/README.md b/README.md
index 63c21e0..d64ed4f 100644
--- a/README.md
+++ b/README.md
@@ -24,7 +24,7 @@ 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
@@ -32,12 +32,14 @@ If you use something like Escargot and ActiveRecord in your application, you can
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
diff --git a/config.ru b/config.ru
index 5491a8a..a5432be 100644
--- a/config.ru
+++ b/config.ru
@@ -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
\ No newline at end of file
diff --git a/lib/elastic_board.rb b/lib/elastic_board.rb
index 99128c2..1487ee7 100644
--- a/lib/elastic_board.rb
+++ b/lib/elastic_board.rb
@@ -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
diff --git a/lib/elastic_board/summary.rb b/lib/elastic_board/summary.rb
index 58c4261..ab5078f 100644
--- a/lib/elastic_board/summary.rb
+++ b/lib/elastic_board/summary.rb
@@ -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)
diff --git a/lib/elastic_board/views/down.erb b/lib/elastic_board/views/down.erb
new file mode 100644
index 0000000..d676b72
--- /dev/null
+++ b/lib/elastic_board/views/down.erb
@@ -0,0 +1,48 @@
+
+
+
+
+
+
+
+
Cluster Health Down
+
+
+ Number of Nodes | 0 |
+ Active Shards | 0 |
+ Active Primary Shards | 0 |
+ Unassigned Shards | 0 |
+
+
+
+
+
+
+
+
+
Indexes
+
+
Unable to connect to ElasticSearch
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/lib/elastic_board/views/index.erb b/lib/elastic_board/views/index.erb
index b656cb3..52dfeeb 100644
--- a/lib/elastic_board/views/index.erb
+++ b/lib/elastic_board/views/index.erb
@@ -12,7 +12,7 @@
-
Cluster Health <%= @summary.nodes_info['ok'] ? 'Healthy' : 'Problem' %>
+
Cluster Health <%= @summary.cluster_health_notice.nil? ? 'Healthy' : @summary.cluster_health_notice %>
Number of Nodes | <%= @summary.number_of_nodes %> |
@@ -23,7 +23,7 @@
-
Nodes in Cluster
+
Nodes in Cluster <%= @summary.nodes_info['ok'] ? 'Healthy' : 'Problem' %>
<% @summary.nodes.each do |node| %>