Permalink
Browse files

Detailed information about failed checks.

  • Loading branch information...
1 parent d41e873 commit ace8f3b4ae6caf792303b95b607d0e33fda6477e @sibprogrammer committed May 26, 2012
Showing with 39 additions and 4 deletions.
  1. +22 −2 index.rb
  2. +17 −2 views/details.haml
View
@@ -17,9 +17,14 @@ def human_time(timestamp)
def get_checks_result(host)
checks = {
:total => @db.collection('checks').find({ 'host_id' => host['_id'] }).count,
- :failed => @db.collection('checks').find({ 'host_id' => host['_id'], 'status' => false }).count
+ :failed => @db.collection('checks').find({ 'host_id' => host['_id'], 'status' => false }).count,
+ :uptime => 0,
}
- checks[:uptime] = 0 == checks[:total] ? 0 : (checks[:total] - checks[:failed]) * 100 / checks[:total]
+
+ if checks[:total] > 0
+ checks[:uptime] = "%.2f" % ((checks[:total].to_f - checks[:failed]) * 100 / checks[:total])
+ end
+
checks
end
@@ -52,5 +57,20 @@ def get_checks_result(host)
get '/details' do
@host = @db.collection('hosts').find_one({ 'ip' => params[:ip] })
@checks = get_checks_result(@host)
+
+ failed_checks = @db.collection('checks').find({ 'host_id' => @host['_id'], 'status' => false }).sort(['timestamp', 'descending']).limit(100)
+ @failures = []
+ failed_check = failed_checks.first
+ failure = { :from => failed_check['timestamp'], :to => failed_check['timestamp'], :duration => 10 }
+ failed_checks.each do |failed_check|
+ if failure[:from] - failed_check['timestamp'] < 60
+ failure[:duration] += failure[:from] - failed_check['timestamp']
+ failure[:from] = failed_check['timestamp']
+ else
+ @failures << failure
+ failure = { :from => failed_check['timestamp'], :to => failed_check['timestamp'], :duration => 10 }
+ end
+ end
+
haml :details, :format => :html5
end
View
@@ -1,12 +1,27 @@
%h1.page-header= "Host #{@host['host']}"
+%h3 Overview
+
%table.table.table-striped.table-bordered
%tr
- %th Total
- %th Failed
+ %th Total Checks
+ %th Failed Checks
%th Uptime
%tr
%td= @checks[:total]
%td= @checks[:failed]
%td= "#{@checks[:uptime]}%"
+%h3 Failures longer than 1 min
+
+%table.table.table-striped.table-bordered
+ %tr
+ %th From Time
+ %th To Time
+ %th Duration
+ - @failures.each do |failure|
+ - next if failure[:duration] < 60
+ %tr
+ %td= Time.at(failure[:from]).strftime('%Y.%m.%d %H:%M:%S')
+ %td= Time.at(failure[:to]).strftime('%Y.%m.%d %H:%M:%S')
+ %td= "%d min" % (failure[:duration] / 60)

0 comments on commit ace8f3b

Please sign in to comment.