From 9a92273d683859dcf2b2efc8d13649c939612670 Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Thu, 16 Dec 2010 15:46:10 +0800 Subject: [PATCH 1/5] fix #3, add child processes information --- lib/monittr.rb | 5 ++++- lib/monittr/sinatra/template.erb | 7 ++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/monittr.rb b/lib/monittr.rb index 8f9f262..3da5999 100644 --- a/lib/monittr.rb +++ b/lib/monittr.rb @@ -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}" 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 %> From c3252ccc201797d529b8d9b9455dc16ee11fb741 Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Thu, 28 Jul 2011 09:22:08 +0800 Subject: [PATCH 2/5] add Gemfile.lock --- .gitignore | 3 +-- Gemfile.lock | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 Gemfile.lock 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 From d57fa0c878b9a68bb8d736c214a81e0e04662c31 Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Thu, 28 Jul 2011 09:28:34 +0800 Subject: [PATCH 3/5] add more info when error --- lib/monittr.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/monittr.rb b/lib/monittr.rb index 3da5999..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 @@ -150,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 From 7b381280ac2019d094817c8572f11628bd94c38c Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Wed, 10 Aug 2011 09:34:36 +0800 Subject: [PATCH 4/5] already show days --- lib/monittr/sinatra/monittr.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/monittr/sinatra/monittr.rb b/lib/monittr/sinatra/monittr.rb index 0797027..d6f0e88 100644 --- a/lib/monittr/sinatra/monittr.rb +++ b/lib/monittr/sinatra/monittr.rb @@ -42,14 +42,9 @@ def time_in_words(seconds) when 3600..86400 value = seconds/3600 "#{value} hour#{ value > 1 ? 's' : ''}" - when 86400..604800 + else value = seconds/86400 "#{value} day#{ value > 1 ? 's' : ''}" - when 604800..2419200 - value = seconds/604800 - "#{value} week#{ value > 1 ? 's' : ''}" - else - nil end end From 8a54b6f1702d1bef468c532926ac69473b0e90f5 Mon Sep 17 00:00:00 2001 From: LI Daobing Date: Wed, 10 Aug 2011 09:46:33 +0800 Subject: [PATCH 5/5] fix error when seconds is not numeric, like nil --- lib/monittr/sinatra/monittr.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/monittr/sinatra/monittr.rb b/lib/monittr/sinatra/monittr.rb index d6f0e88..a0cba4d 100644 --- a/lib/monittr/sinatra/monittr.rb +++ b/lib/monittr/sinatra/monittr.rb @@ -42,9 +42,11 @@ def time_in_words(seconds) when 3600..86400 value = seconds/3600 "#{value} hour#{ value > 1 ? 's' : ''}" - else + when Numeric value = seconds/86400 "#{value} day#{ value > 1 ? 's' : ''}" + else + nil end end