process-monitor 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. data/README +5 -0
  2. data/Rakefile +16 -0
  3. data/VERSION +1 -0
  4. data/lib/process_monitor.rb +38 -0
  5. metadata +70 -0
data/README ADDED
@@ -0,0 +1,5 @@
1
+ Process Monitor
2
+
3
+ A simple utility to get the process id and it status.
4
+
5
+ The input required are the process type i.e. ruby,java or so on and a pattern to identify the process.
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gemspec|
7
+ gemspec.name = "process-monitor"
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."
10
+ gemspec.email = "sriram.varahan@gmail.com"
11
+ gemspec.authors = ["Sriram Varahan"]
12
+ end
13
+ Jeweler::GemcutterTasks.new
14
+ rescue LoadError
15
+ p "Jeweler not available. Install it with: gem install jeweler"
16
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
@@ -0,0 +1,38 @@
1
+ class ProcessMonitor
2
+
3
+ def get_pid(process_type,process_pattern)
4
+ # Parse the output to fetch the process id.
5
+ process_id_reg_exp = %r{^(.*)\s*}
6
+
7
+ process_information_lines = `pgrep #{process_type}|xargs ps`.split("\n")
8
+ pid = nil
9
+
10
+ process_information_lines.each do |process_line|
11
+ # The name of the process will be verity-spider
12
+ # This is to make sure we don't kill any other ruby process other than spider.
13
+ if process_line =~ /#{process_pattern}/
14
+ process_id_reg_exp.match(process_line)
15
+ pid = $1.gsub(/\s*/, "").to_i
16
+ end
17
+ end
18
+ pid
19
+ end
20
+
21
+
22
+ def self.get_process_status(process_type,process_pattern)
23
+ pid = get_pid(process_type,process_pattern)
24
+ `cat /proc/#{pid}/status|grep State`
25
+ end
26
+
27
+
28
+ def self.process_is_up?(process_type,process_pattern)
29
+ pid = get_pid(process_type,process_pattern)
30
+ # The folder /proc/<pid>/ contains information about the process
31
+ # The file /proc/<pid>/status gives information about the process as to if it is sleeping and so on.
32
+ # If the folder exists it would mean the process exists.
33
+ (pid.nil? || !File.exists?("/proc/#{pid}"))? false : true
34
+ end
35
+
36
+ end
37
+
38
+
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: process-monitor
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 0
10
+ version: 0.0.0
11
+ platform: ruby
12
+ authors:
13
+ - Sriram Varahan
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-24 00:00:00 +05:30
19
+ default_executable:
20
+ dependencies: []
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.
23
+ email: sriram.varahan@gmail.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - README
32
+ - Rakefile
33
+ - VERSION
34
+ - lib/process_monitor.rb
35
+ has_rdoc: true
36
+ homepage:
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options:
41
+ - --charset=UTF-8
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 3
59
+ segments:
60
+ - 0
61
+ version: "0"
62
+ requirements: []
63
+
64
+ rubyforge_project:
65
+ rubygems_version: 1.3.7
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: A gem to monitor processes
69
+ test_files: []
70
+