process_monitor 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/Rakefile +1 -1
  2. data/VERSION +1 -1
  3. data/lib/process_monitor.rb +13 -9
  4. metadata +4 -4
data/Rakefile CHANGED
@@ -6,7 +6,7 @@ begin
6
6
  Jeweler::Tasks.new do |gemspec|
7
7
  gemspec.name = "process_monitor"
8
8
  gemspec.summary = "A gem to monitor processes"
9
- gemspec.description = "This gem gets the status(running/sleeping/defunct) based on a pattern you provide to it. For example if you have a service which is running and its a ruby service you would need to pass the type(ruby) and a pattern which would identify the process."
9
+ gemspec.description = "A gem to simplify process/service monitoring."
10
10
  gemspec.email = "sriram.varahan@gmail.com"
11
11
  gemspec.homepage = "http://github.com/sriram/Process-Monitor"
12
12
  gemspec.authors = ["Sriram Varahan"]
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -1,11 +1,13 @@
1
1
  class ProcessMonitor
2
-
2
+
3
3
  ##
4
4
  # This method fetches the process ids of the process matching the process_type and
5
5
  # process_pattern
6
6
  # This method returns an array of hash as [{:process => {:pid => pid,:command => "Command to invoke the process",:status => "Status of the process"},...]
7
7
 
8
8
  def self.get_pid(process_type,process_pattern="",get_status=true)
9
+ return [] if process_type.nil? || process_type.empty?
10
+
9
11
  # Parse the output to fetch the process id.
10
12
  process_id_reg_exp = %r{^(.*)\s*}
11
13
 
@@ -20,16 +22,18 @@ class ProcessMonitor
20
22
  process_id_reg_exp.match(process_line)
21
23
  pid = $1.gsub(/\s*/, "").to_i
22
24
  unless $$ == pid
23
- pid_command = `cat /proc/#{pid}/cmdline`
24
- if get_status
25
- pids << {:process => {:pid => pid, :command => pid_command, :status => get_process_status(pid)}}
26
- else
27
- pids << {:process => {:pid => pid, :command => pid_command}}
25
+ if process_is_up?(pid)
26
+ pid_command = `cat /proc/#{pid}/cmdline`
27
+ if get_status
28
+ pids << {:process => {:pid => pid, :command => pid_command, :status => get_process_status(pid)}}
29
+ else
30
+ pids << {:process => {:pid => pid, :command => pid_command}}
31
+ end
28
32
  end
29
33
  end
30
34
  end
31
35
  end
32
-
36
+
33
37
  pids
34
38
  rescue => e
35
39
  "Exception occurred. Exception => #{e.inspect}. Backtrace => #{e.backtrace} "
@@ -52,7 +56,7 @@ class ProcessMonitor
52
56
  "Exception occurred. Details => #{e}"
53
57
  end
54
58
 
55
-
59
+
56
60
  ##
57
61
  # Fetch the IO details of the process
58
62
 
@@ -97,7 +101,7 @@ class ProcessMonitor
97
101
  "Exception occurred. Details => #{e}"
98
102
  end
99
103
 
100
-
104
+
101
105
  ##
102
106
  # Fetch the limits of the process.
103
107
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: process_monitor
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 2
10
- version: 0.2.2
9
+ - 3
10
+ version: 0.2.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sriram Varahan
@@ -19,7 +19,7 @@ date: 2010-06-25 00:00:00 +05:30
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
22
- description: This gem gets the status(running/sleeping/defunct) based on a pattern you provide to it. For example if you have a service which is running and its a ruby service you would need to pass the type(ruby) and a pattern which would identify the process.
22
+ description: A gem to simplify process/service monitoring.
23
23
  email: sriram.varahan@gmail.com
24
24
  executables: []
25
25