processwatch 3.0.8
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.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +52 -0
- data/Rakefile +1 -0
- data/lib/processwatch.rb +3 -0
- data/lib/processwatch/pw_linux.rb +110 -0
- data/lib/processwatch/pw_setup.rb +109 -0
- data/lib/processwatch/version.rb +3 -0
- data/processwatch.gemspec +23 -0
- data/setup.rb +5 -0
- metadata +89 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Process Watch by Phil Chen
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Processwatch
|
2
|
+
|
3
|
+
License: (MIT) Copyright (C) 2013 Phil Chen.
|
4
|
+
|
5
|
+
## DESCRIPTION:
|
6
|
+
|
7
|
+
Process Watch monitors processes and workflows in your Linux system for anomalies or situations which when arise trigger predetermined actions you designate.
|
8
|
+
|
9
|
+
This is useful for systems issues, automating troubleshooting, provisioning, scaling, and much more.
|
10
|
+
|
11
|
+
## CURRENT FEATURES:
|
12
|
+
|
13
|
+
Seeing if a daemon/process is running and if not execute some combination of notify and starting it
|
14
|
+
|
15
|
+
Detecting if a process is a runaway if so execute some combination of notify and killing it
|
16
|
+
|
17
|
+
## PREREQUISITES:
|
18
|
+
|
19
|
+
Linux, Ruby, Cron (Or some other scheduler)
|
20
|
+
|
21
|
+
## INSTALLATION:
|
22
|
+
|
23
|
+
```bash
|
24
|
+
$ gem install processwatch
|
25
|
+
```
|
26
|
+
|
27
|
+
Create a file setup.rb
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'processwatch'
|
31
|
+
include Processwatch_setup
|
32
|
+
setup
|
33
|
+
```
|
34
|
+
|
35
|
+
Run the setup.rb
|
36
|
+
|
37
|
+
```bash
|
38
|
+
ruby setup.rb
|
39
|
+
```
|
40
|
+
|
41
|
+
## CONFIGURATION:
|
42
|
+
|
43
|
+
Configure the configuration files locate in /usr/local/processwatch/conf/
|
44
|
+
|
45
|
+
Note you can have multiple services monitored for restart.
|
46
|
+
Sample restart configuration file begins with prefix restart_ naming convention looks like restart_uniqueappname
|
47
|
+
|
48
|
+
## USING PROCESSWATCH:
|
49
|
+
|
50
|
+
The processwatch executable is /usr/local/processwatch/processwatch.rb you will want to set it on a cron like:
|
51
|
+
|
52
|
+
*/5 * * * * /usr/bin/ruby /usr/local/processwatch/processwatch.rb
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/processwatch.rb
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
#License: (MIT), Copyright (C) 2013 Process Watch Author Phil Chen.
|
2
|
+
|
3
|
+
module Processwatch
|
4
|
+
|
5
|
+
def restart
|
6
|
+
|
7
|
+
ps_list = `ps h -eo cmd`
|
8
|
+
require 'socket'
|
9
|
+
host = Socket.gethostname
|
10
|
+
dir = File.dirname("/usr/local/processwatch/conf")
|
11
|
+
load File.expand_path("#{dir}/conf/general_restart_contact")
|
12
|
+
|
13
|
+
Dir[File.expand_path("#{dir}/conf/restart_*")]. uniq. each do |file|
|
14
|
+
load file
|
15
|
+
|
16
|
+
list = ps_list.split(/\n/)
|
17
|
+
|
18
|
+
restart_msgstr = <<END_OF_MESSAGE
|
19
|
+
From: #$restart_from <#$restart_from_email>
|
20
|
+
To: #$restart_to <#$restart_to_email>
|
21
|
+
Subject: Dead Process Detected On #{host}
|
22
|
+
|
23
|
+
Process Watch has detected #{$restart_process} has died.
|
24
|
+
|
25
|
+
We have started #{$restart_process} again.
|
26
|
+
|
27
|
+
-Process Watch
|
28
|
+
|
29
|
+
END_OF_MESSAGE
|
30
|
+
|
31
|
+
dead_process_msgstr = <<END_OF_MESSAGE
|
32
|
+
From: #$restart_from <#$restart_from_email>
|
33
|
+
To: #$restart_to <#$restart_to_email>
|
34
|
+
Subject: Dead Process Detected On #{host}
|
35
|
+
|
36
|
+
Process Watch has detected #{$restart_process} has died.
|
37
|
+
|
38
|
+
-Process Watch
|
39
|
+
|
40
|
+
END_OF_MESSAGE
|
41
|
+
|
42
|
+
occurances = list.grep(/.*#$restart_process.*/)
|
43
|
+
if occurances.length == 0 && $restart_mail == "yes" && $restart_start == "yes"
|
44
|
+
system $restart_action
|
45
|
+
require 'net/smtp'
|
46
|
+
Net::SMTP.start("#$restart_smtp_host", "#$restart_smtp_port") do |smtp|
|
47
|
+
smtp.send_message(restart_msgstr, "#$restart_from_email", "#$restart_to_email")
|
48
|
+
end
|
49
|
+
elsif occurances.length == 0 && $restart_mail == "yes" && $restart_start == "no"
|
50
|
+
require 'net/smtp'
|
51
|
+
Net::SMTP.start("#$restart_smtp_host", "#$restart_smtp_port") do |smtp|
|
52
|
+
smtp.send_message(dead_process_msgstr, "#$restart_from_email", "#$restart_to_email")
|
53
|
+
end
|
54
|
+
elsif occurances.length == 0 && $restart_mail == "no" && $restart_start == "yes"
|
55
|
+
system $restart_action
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def runaway
|
61
|
+
|
62
|
+
ps_list = `ps h -eo cputime,pcpu,pid,user,cmd`
|
63
|
+
|
64
|
+
dir = File.dirname("/usr/local/processwatch/conf")
|
65
|
+
|
66
|
+
Dir[File.expand_path("#{dir}/conf/runaway")]. uniq. each do |file|
|
67
|
+
load file
|
68
|
+
|
69
|
+
list = ps_list.split(/\n/)
|
70
|
+
list.each do |p|
|
71
|
+
process = p.split
|
72
|
+
process[0] =~ /(\d+):(\d+):(\d+)/
|
73
|
+
|
74
|
+
cpu_time = ($1.to_i*3600.to_i + $2.to_i*60.to_i + $3.to_i)
|
75
|
+
next if cpu_time.to_i < $runaway_max_time.to_i
|
76
|
+
begin
|
77
|
+
|
78
|
+
msgstr = <<END_OF_MESSAGE
|
79
|
+
From: #$runaway_from <#$runaway_from_email>
|
80
|
+
To: #$runaway_to <#$runaway_to_email>
|
81
|
+
Subject: Runaway Process Detected
|
82
|
+
|
83
|
+
#{process[4]}
|
84
|
+
|
85
|
+
END_OF_MESSAGE
|
86
|
+
|
87
|
+
if $runaway_mail == "yes" && $runaway_kill == "yes"
|
88
|
+
require 'net/smtp'
|
89
|
+
Net::SMTP.start("#$runaway_smtp_host", "#$runaway_smtp_port") do |smtp|
|
90
|
+
smtp.send_message(msgstr, "#$runaway_from_email", "#$runaway_to_email")
|
91
|
+
system("/bin/kill" + " " + "-9" + " " + "#{process[2]}")
|
92
|
+
end
|
93
|
+
elsif $runaway_mail == "yes" && $runaway_kill == "no"
|
94
|
+
require 'net/smtp'
|
95
|
+
Net::SMTP.start("#$runaway_smtp_host", "#$runaway_smtp_port") do |smtp|
|
96
|
+
smtp.send_message(msgstr, "#$runaway_from_email", "#$runaway_to_email")
|
97
|
+
end
|
98
|
+
elsif $runaway_mail == "no" && $runaway_kill == "yes"
|
99
|
+
system("/bin/kill" + " " + "-9" + " " + "#{process[2]}")
|
100
|
+
else
|
101
|
+
exit
|
102
|
+
end
|
103
|
+
rescue
|
104
|
+
puts "Error Killing the process"
|
105
|
+
retry
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#License: (MIT), Copyright (C) 2013 Process Watch Author Phil Chen.
|
2
|
+
|
3
|
+
module Processwatch_setup
|
4
|
+
|
5
|
+
def setup
|
6
|
+
if File.directory?("/usr/local/processwatch")
|
7
|
+
|
8
|
+
puts "Process Watch Is Already Been Installed In /usr/local/processwatch"
|
9
|
+
|
10
|
+
else
|
11
|
+
|
12
|
+
`mkdir -p /usr/local/processwatch/conf`
|
13
|
+
general_restart_contact = "/usr/local/processwatch/conf/general_restart_contact"
|
14
|
+
restart_ssh = "/usr/local/processwatch/conf/restart_ssh"
|
15
|
+
runaway = "/usr/local/processwatch/conf/runaway"
|
16
|
+
processwatch = "/usr/local/processwatch/processwatch.rb"
|
17
|
+
|
18
|
+
grc = <<END_OF_MESSAGE
|
19
|
+
#CONFIGURATION KEY
|
20
|
+
##$restart_smtp_host = SMTP Server To Send Email From
|
21
|
+
##$restart_smtp_port = SMTP Server Port To Send Email From
|
22
|
+
##$restart_from = Name of the Email From Field
|
23
|
+
##$restart_to = Name of the Email To Field
|
24
|
+
##$restart_from_email = Email Address the Notification Comes From
|
25
|
+
##$restart_to_email = Email Address the Notification Goes To
|
26
|
+
#
|
27
|
+
$restart_smtp_host = "127.0.0.1"
|
28
|
+
$restart_smtp_port = "25"
|
29
|
+
$restart_from = "FromName"
|
30
|
+
$restart_to = "ToName"
|
31
|
+
$restart_from_email = "from@email.com"
|
32
|
+
$restart_to_email = "to@email.com"
|
33
|
+
|
34
|
+
END_OF_MESSAGE
|
35
|
+
|
36
|
+
rs = <<END_OF_MESSAGE
|
37
|
+
#CONFIGURATION KEY
|
38
|
+
##$restart_mail = yes or no send email notifying of dead process
|
39
|
+
##$restart_start = yes or no start the dead process
|
40
|
+
##$restart_process = name of process try to be unique, you can find the names of processes by running: ps h -eo cm
|
41
|
+
##$restart_action = command to start the process try to use full paths for everything
|
42
|
+
#
|
43
|
+
$restart_mail = "no"
|
44
|
+
$restart_start = "no"
|
45
|
+
$restart_process = '/usr/sbin/sshd'
|
46
|
+
$restart_action = '/etc/init.d/sshd start'
|
47
|
+
|
48
|
+
END_OF_MESSAGE
|
49
|
+
|
50
|
+
r = <<END_OF_MESSAGE
|
51
|
+
#CONFIGURATION KEY
|
52
|
+
##$runaway_max_time = Maximum CPU Time in Seconds That Defines a Run Away Process
|
53
|
+
##$runaway_smtp_host = SMTP Server To Send Email From
|
54
|
+
##$runaway_smtp_port = SMTP Server Port To Send Email From
|
55
|
+
##$runaway_from = Name of the Email From Field
|
56
|
+
##$runaway_to = Name of the Email To Field
|
57
|
+
##$runaway_from_email = Email Address the Notification Comes From
|
58
|
+
##$runaway_to_email = Email Address the Notification Goes To
|
59
|
+
##$runaway_mail = yes or no send email notifying the runaway process
|
60
|
+
##$runaway_kill = yes or no kill the runaway process **NOTE BE CAREFUL THIS WILL KILL THE PROCESS
|
61
|
+
#
|
62
|
+
$runaway_max_time = "6000"
|
63
|
+
$runaway_smtp_host = "127.0.0.1"
|
64
|
+
$runaway_smtp_port = "25"
|
65
|
+
$runaway_from = "FromName"
|
66
|
+
$runaway_to = "ToName"
|
67
|
+
$runaway_from_email = "from@email.com"
|
68
|
+
$runaway_to_email = "to@email.com"
|
69
|
+
$runaway_mail = "no"
|
70
|
+
$runaway_kill = "no"
|
71
|
+
|
72
|
+
END_OF_MESSAGE
|
73
|
+
|
74
|
+
pw = <<END_OF_MESSAGE
|
75
|
+
#!/usr/bin/ruby
|
76
|
+
|
77
|
+
require 'processwatch'
|
78
|
+
|
79
|
+
include Processwatch
|
80
|
+
|
81
|
+
restart
|
82
|
+
runaway
|
83
|
+
|
84
|
+
END_OF_MESSAGE
|
85
|
+
|
86
|
+
output = File.open(general_restart_contact, 'w')
|
87
|
+
output.puts grc
|
88
|
+
output.close
|
89
|
+
|
90
|
+
output = File.open(restart_ssh, 'w')
|
91
|
+
output.puts rs
|
92
|
+
output.close
|
93
|
+
|
94
|
+
output = File.open(runaway, 'w')
|
95
|
+
output.puts r
|
96
|
+
output.close
|
97
|
+
|
98
|
+
output = File.open(processwatch, 'w')
|
99
|
+
output.puts pw
|
100
|
+
output.close
|
101
|
+
|
102
|
+
puts ""
|
103
|
+
puts "Installation of Directory Structure and Configuration Files Successful!"
|
104
|
+
puts ""
|
105
|
+
puts "Go to /usr/local/processwatch/conf to edit configuration files"
|
106
|
+
puts ""
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'processwatch/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "processwatch"
|
8
|
+
spec.version = Processwatch::VERSION
|
9
|
+
spec.authors = ["Phil Chen"]
|
10
|
+
spec.email = ["nethacker@gmail.com"]
|
11
|
+
spec.description = %q{Process Watch monitors processes and workflows in your Linux system for anomalies or situations which when arise trigger predetermined actions you designate.}
|
12
|
+
spec.summary = %q{Linux Process Monitoring}
|
13
|
+
spec.homepage = "https://github.com/nethacker/processwatch"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
data/setup.rb
ADDED
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: processwatch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.8
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Phil Chen
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-07-20 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: bundler
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '1.3'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '1.3'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Process Watch monitors processes and workflows in your Linux system for
|
47
|
+
anomalies or situations which when arise trigger predetermined actions you designate.
|
48
|
+
email:
|
49
|
+
- nethacker@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- Gemfile
|
55
|
+
- LICENSE.txt
|
56
|
+
- README.md
|
57
|
+
- Rakefile
|
58
|
+
- lib/processwatch.rb
|
59
|
+
- lib/processwatch/pw_linux.rb
|
60
|
+
- lib/processwatch/pw_setup.rb
|
61
|
+
- lib/processwatch/version.rb
|
62
|
+
- processwatch.gemspec
|
63
|
+
- setup.rb
|
64
|
+
homepage: https://github.com/nethacker/processwatch
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
requirements: []
|
84
|
+
rubyforge_project:
|
85
|
+
rubygems_version: 1.8.23
|
86
|
+
signing_key:
|
87
|
+
specification_version: 3
|
88
|
+
summary: Linux Process Monitoring
|
89
|
+
test_files: []
|