Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
.DS_Store
pkg/*
*.gem
Gemfile.lock
tmp/
coverage/
coverage/
35 changes: 35 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
PATH
remote: .
specs:
monittr (0.0.5)
bundler (~> 1.0.0)
nokogiri
rest-client
sinatra

GEM
remote: http://rubygems.org/
specs:
ansi (1.3.0)
fakeweb (1.3.0)
mime-types (1.16)
nokogiri (1.5.0)
rack (1.3.2)
rest-client (1.6.3)
mime-types (>= 1.16)
shoulda (2.11.3)
sinatra (1.2.6)
rack (~> 1.1)
tilt (>= 1.2.2, < 2.0)
tilt (1.3.2)
turn (0.8.2)
ansi (>= 1.2.2)

PLATFORMS
ruby

DEPENDENCIES
fakeweb
monittr!
shoulda
turn
9 changes: 6 additions & 3 deletions lib/monittr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def self.fetch(url='http://admin:monit@localhost:2812')
monit_url += '_status?format=xml' unless url =~ /_status\?format=xml$/
self.new url, RestClient.get(monit_url)
rescue Exception => e
self.new url, %Q|<error status="3" name="#{e.class}" message="#{e.message}" />|
self.new url, %Q|<error status="3" name="#{e.class}" message="#{url}: #{e.message}" />|
end

def inspect
Expand Down Expand Up @@ -137,8 +137,11 @@ def initialize(xml)
:monitored => value('monitor', :to_i),
:pid => value('pid', :to_i),
:uptime => value('uptime', :to_i),
:children => value('children', :to_i),
:memory => value('memory/percent', :to_f),
:cpu => value('cpu/percent', :to_i)
:memory_total => value('memory/percenttotal', :to_f),
:cpu => value('cpu/percent', :to_f),
:cpu_total => value('cpu/percenttotal', :to_f)
} )
rescue Exception => e
puts "ERROR: #{e.class} -- #{e.message}, In: #{e.backtrace.first}"
Expand All @@ -147,7 +150,7 @@ def initialize(xml)
:message => e.message } )
end
end

# A "host" service in Monit
#
# http://mmonit.com/monit/documentation/monit.html#connection_testing
Expand Down
5 changes: 1 addition & 4 deletions lib/monittr/sinatra/monittr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ def time_in_words(seconds)
when 3600..86400
value = seconds/3600
"#{value} hour#{ value > 1 ? 's' : ''}"
when 86400..604800
when Numeric
value = seconds/86400
"#{value} day#{ value > 1 ? 's' : ''}"
when 604800..2419200
value = seconds/604800
"#{value} week#{ value > 1 ? 's' : ''}"
else
nil
end
Expand Down
7 changes: 4 additions & 3 deletions lib/monittr/sinatra/template.erb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,10 @@
</strong>

<small>
<span class="info"><span class="label">cpu: </span><%= process.cpu || 'N/A' %></span>
<span class="info"><span class="label">memory: </span><%= process.memory || 'N/A' %></span>
<span class="info"><span class="label">uptime: </span><%= time_in_words(process.uptime) || 'N/A' %></span>
<span class="info"><span class="label">children: </span><%= process.children || 'N/A' %></span>
<span class="info"><span class="label">cpu: </span><%= process.cpu || 'N/A' %> / <%= process.cpu_total || 'N/A' %></span>
<span class="info"><span class="label">memory: </span><%= process.memory || 'N/A' %> / <%= process.memory_total || 'N/A' %></span>
<span class="info"><span class="label">uptime: </span><%= time_in_words(process.uptime) || 'N/A' %></span>
</small>
</li>
<% end %>
Expand Down