diff --git a/.gitignore b/.gitignore index 31bfbb1..cb111ad 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ .DS_Store pkg/* *.gem -Gemfile.lock tmp/ -coverage/ \ No newline at end of file +coverage/ diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..17354b3 --- /dev/null +++ b/Gemfile.lock @@ -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 diff --git a/lib/monittr.rb b/lib/monittr.rb index 8f9f262..80120f5 100644 --- a/lib/monittr.rb +++ b/lib/monittr.rb @@ -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|| + self.new url, %Q|| end def inspect @@ -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}" @@ -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 diff --git a/lib/monittr/sinatra/monittr.rb b/lib/monittr/sinatra/monittr.rb index 0797027..a0cba4d 100644 --- a/lib/monittr/sinatra/monittr.rb +++ b/lib/monittr/sinatra/monittr.rb @@ -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 diff --git a/lib/monittr/sinatra/template.erb b/lib/monittr/sinatra/template.erb index 506170a..ada7fb1 100644 --- a/lib/monittr/sinatra/template.erb +++ b/lib/monittr/sinatra/template.erb @@ -55,9 +55,10 @@ - cpu: <%= process.cpu || 'N/A' %> - memory: <%= process.memory || 'N/A' %> - uptime: <%= time_in_words(process.uptime) || 'N/A' %> + children: <%= process.children || 'N/A' %> + cpu: <%= process.cpu || 'N/A' %> / <%= process.cpu_total || 'N/A' %> + memory: <%= process.memory || 'N/A' %> / <%= process.memory_total || 'N/A' %> + uptime: <%= time_in_words(process.uptime) || 'N/A' %> <% end %>