Permalink
Browse files

Overall stats in home page

  • Loading branch information...
1 parent aa6eecf commit efee55849ad6a7fa2545ab4953bd600aa09f7c13 Luca Guidi committed Jun 13, 2009
Showing with 67 additions and 11 deletions.
  1. +38 −2 app/models/server.rb
  2. +1 −1 app/web.rb
  3. +4 −2 public/stylesheets/application.css
  4. +24 −6 views/index.erb
View
@@ -1,5 +1,13 @@
class Server
- PONG = "PONG".freeze
+ BLANK_STATS = {
+ :servers_count => 0,
+ :servers_alive => 0,
+ :used_memory => 0,
+ :total_connections => 0,
+ :current_connections => 0,
+ :total_commands_processed => 0
+ }.freeze
+
include DataMapper::Resource
property :id, Serial
@@ -9,13 +17,41 @@ class Server
validates_present :name, :host, :port
+ class << self
+ def overall_stats
+ all.inject(BLANK_STATS.dup) do |result, server|
+ result[:servers_count] += 1
+ if server.alive?
+ result[:servers_alive] += 1
+ result[:used_memory] += server.used_memory.to_i
+ result[:total_connections] += server.total_connections_received.to_i
+ result[:current_connections] += server.connected_clients.to_i
+ result[:total_commands_processed] += server.total_commands_processed.to_i
+ end
+ result
+ end
+ end
+ end
+
def alive?
- connection.ping == PONG
+ return true if stats
rescue
@connection = nil
false
end
+ def stats
+ @stats ||= connection.info
+ end
+
+ def method_missing(method_name, *args)
+ if result = stats[method_name.to_sym]
+ result
+ else
+ super
+ end
+ end
+
private
def connection
@connection ||= Redis.new :host => host, :port => port
View
@@ -1,5 +1,5 @@
get "/" do
- @servers = Server.all
+ @stats = Server.overall_stats
erb :index
end
@@ -1,14 +1,14 @@
* { margin: 0; padding: 0; }
body { font-family: Helvetica,Arial,sans-serif; color: #333; background-color: #ccc; font-size: 16px; line-height: 24px; }
h1 { margin: 0; font-size: 60px; line-height: 100px; text-align: center; }
-h2 { margin: 0; font-size: 20px; line-height: 20px; }
+h2 { margin: 0; font-size: 30px; line-height: 20px; }
h3 { margin: 24px 0 6px 0; font-size: 18px; line-height: 18px; border-bottom: 1px solid #ccc; }
h1 img { vertical-align: middle; }
p { margin: 0 0 24px 0; }
p.example { margin: 0 0 12px 0; }
p.how, p.last { margin: 0; }
ul { margin: 0 24px 24px; }
-li { line-height: 24px; }
+li { line-height: 24px; list-style-type: none;}
pre { background-color: #333; color: #fff; margin: 12px 0; font-size: 12px; padding: 0 6px; }
pre em { font-style: normal; background-color: #554; }
pre, tt { font-family: monaco,"courier new",mono; }
@@ -20,3 +20,5 @@ a:hover { background-color: #06c; color: #fff; text-decoration: none; }
#content { margin:0 auto; padding: 24px; width:700px; background-color:#fff; border: 1px solid #999; border-width: 0 1px 1px 1px; }
#footer { margin:0 auto 24px; padding: 12px; width:700px; line-height: 24px; }
.help { font-size: 14px; color: #888; }
+.oblique { font-size: 14px; font-style: oblique; }
+.right { text-align: right; }
View
@@ -1,10 +1,28 @@
<h1>Redis servers</h1>
+<h2>Overview</h2>
+<p class="oblique">for all the servers</p>
<div id="servers">
- <% if @servers && @servers.any? %>
- <% for server in @servers %>
- <h2><%= server.name %> <%= server.host %>:<%= server.port %></h2>
- <% end %>
+ <% unless @stats[:servers_count].zero? %>
+ <h3>Servers</h3>
+ <p>
+ <strong>alive:</strong> <%= @stats[:servers_alive] %><br />
+ <strong>total:</strong> <%= @stats[:servers_count] %>
+ </p>
+ <h3>Connections</h3>
+ <p>
+ <strong>alive:</strong> <%= @stats[:current_connections] %><br />
+ <strong>total:</strong> <%= @stats[:total_connections] %>
+ </p>
+ <h3>Memory</h3>
+ <p>
+ <strong>usage:</strong> <%= @stats[:used_memory] %>
+ </p>
+ <h3>Commands</h3>
+ <p>
+ <strong>processed:</strong> <%= @stats[:total_commands_processed] %>
+ </p>
<% else %>
- <p>No servers there. <a href="/servers/new">Add first</a></p>
- <% end %>
+ <p>No servers there.</p>
+ <% end %>
</div>
+<p class="right"><a href="/servers/new">Add a server</a></p>

0 comments on commit efee558

Please sign in to comment.