riemann-aged-process-monitor 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.markdown +19 -0
- data/bin/riemann-aged-process-monitor +71 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c0f0624f742f9536c15641cbb6335185afeb4810
|
4
|
+
data.tar.gz: 1b899315ed6591987bdf07973919572a15dbdd72
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a9b98bde14090de31aae4e4eaafb462de3490b508554c45489ea3cfafba025e16b37f84cf0d779f0bda22dd6eca10c9e9be0ac75cc6844aac8b7ebeb02b5d30e
|
7
|
+
data.tar.gz: b5610bc873129e2642ddc94ffda4e1f9794dac6de0f55855acbec1c5abd734bc2717239668bc708865c66751b695ccb3b62f4db706b9b7954a5ed5bf956385c2
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
|
2
|
+
The MIT License
|
3
|
+
|
4
|
+
Copyright (c) 2015 Andrew Cunningham
|
5
|
+
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
8
|
+
in the Software without restriction, including without limitation the rights
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
11
|
+
furnished to do so, subject to the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be included in
|
14
|
+
all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
22
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Riemann Aged Process Monitoring
|
2
|
+
|
3
|
+
Utility for monitoring processes that have been running too long or are hung.
|
4
|
+
|
5
|
+
The process monitoring was built to keep track of sub processes spawned by our CD tooling that would get hung and then, over time, impede the ability for similar processes to get kicked off (since the tool would 'see' that the same process was already running). It applies three filters on the Process tree and, if any processes match those filters, will then report back the number, a description that includes the details of the processes and mark the setup as 'critical'.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
```bash
|
10
|
+
./riemann-aged-process-monitor --host riemann.server.host --port port --age '5d' --username 'jenkins' --process 'svn'
|
11
|
+
```
|
12
|
+
Where:
|
13
|
+
* host - Riemann server host ip or hostname
|
14
|
+
* port - Riemann server event collection port
|
15
|
+
* age - Process age to filter on
|
16
|
+
* username - Process owner to filter on
|
17
|
+
* process - Process name to filter on
|
18
|
+
|
19
|
+
In the case above, a 'critical' event would be sent if any *svn* processes, owned by *jenkins* that are older than *5 days* were found. Otherwise 'ok' events are sent.
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'riemann/tools'
|
4
|
+
require 'etc'
|
5
|
+
require 'sys/proctable'
|
6
|
+
require 'socket'
|
7
|
+
|
8
|
+
class Riemann::Tools::AgedProcessMonitor
|
9
|
+
include Riemann::Tools
|
10
|
+
include Sys
|
11
|
+
|
12
|
+
opt :username, "Specific User to filter on", :type => String
|
13
|
+
opt :process, "Specific Process Name to filter on", :type => String
|
14
|
+
opt :age, "Age of processes to filter - integer value followed by type indicator (s,m,h,d)", :type => String, :default => '1d'
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
if opts[:username]
|
18
|
+
userid = get_uid opts[:username]
|
19
|
+
process_uid_select = -> proc { proc.uid == userid }
|
20
|
+
end
|
21
|
+
|
22
|
+
if opts[:process]
|
23
|
+
process_name_select = -> proc { proc.name =~ /#{opts[:process]}/ }
|
24
|
+
end
|
25
|
+
|
26
|
+
@age_flag = convert_age opts[:age]
|
27
|
+
process_age_select = -> proc { File.exists?("/proc/#{proc.pid}") && (Time.now - File.ctime("/proc/#{proc.pid}")) > @age_flag }
|
28
|
+
|
29
|
+
@selects = [ process_uid_select, process_age_select, process_name_select ].compact
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_uid username
|
33
|
+
begin
|
34
|
+
Etc.getpwnam(username).uid
|
35
|
+
rescue ArgumentError => e
|
36
|
+
raise "Username provided [#{username}] is invalid"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def convert_age age_string
|
41
|
+
age_string_regex = /^(\d+)([s|m|h|d]{1})$/
|
42
|
+
values = age_string.match(age_string_regex)
|
43
|
+
raise "Invalid age string - must follow convention of a number followed by indicator - s[econds], m[inutes], h[hours], d[days]" unless values
|
44
|
+
|
45
|
+
conversion = { 's' => 1, 'm' => 60, 'h' => 3600, 'd' => 86400}
|
46
|
+
values[1].to_i * conversion[values[2]]
|
47
|
+
end
|
48
|
+
|
49
|
+
# Since: Jan 01, 2015 -> command foobar
|
50
|
+
def description processes
|
51
|
+
desc = processes.count > 0 ? "The following processes were found:\n" : "No processes were found that exceed @age_flag"
|
52
|
+
processes.each do |proc|
|
53
|
+
desc << " Since: #{File.ctime("/proc/#{proc.pid}").asctime} -> #{proc.cmdline}\n"
|
54
|
+
end
|
55
|
+
desc
|
56
|
+
end
|
57
|
+
|
58
|
+
def tick
|
59
|
+
processes = ProcTable.ps
|
60
|
+
monitored_processes = @selects.inject(processes) { |processes, selector| processes.select(&selector) }
|
61
|
+
report({
|
62
|
+
:service => "aged-process-monitor",
|
63
|
+
:state => monitored_processes.count > 0 ? 'critical' : 'ok',
|
64
|
+
:metric => monitored_processes.count,
|
65
|
+
:description => description(monitored_processes),
|
66
|
+
:time => Time.now.to_i
|
67
|
+
})
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
Riemann::Tools::AgedProcessMonitor.run
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: riemann-aged-process-monitor
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Andrew Cunningham
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: riemann-tools
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.2'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.2.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0.2'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.2.6
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: sys-proctable
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - '='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: 0.9.9
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - '='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: 0.9.9
|
47
|
+
description: Sets up monitoring on processes for Linux systems only - can be filtered
|
48
|
+
by user, age and command type
|
49
|
+
email:
|
50
|
+
- old.noakes@gmail.com
|
51
|
+
executables:
|
52
|
+
- riemann-aged-process-monitor
|
53
|
+
extensions: []
|
54
|
+
extra_rdoc_files: []
|
55
|
+
files:
|
56
|
+
- LICENSE
|
57
|
+
- README.markdown
|
58
|
+
- bin/riemann-aged-process-monitor
|
59
|
+
homepage: https://github.com/oldNoakes/riemann-aged-process-monitor
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: 1.8.7
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.4.6
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Detect processes in Linux that have been running too long back to Riemann
|
83
|
+
test_files: []
|