sensu-plugins-process-checks 0.0.1.alpha.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -0
- data/CHANGELOG.md +16 -0
- data/LICENSE +22 -0
- data/README.md +34 -0
- data/bin/check-cmd.rb +78 -0
- data/bin/check-process-restart.rb +112 -0
- data/bin/check-process.rb +292 -0
- data/lib/sensu-plugins-process-checks.rb +7 -0
- metadata +230 -0
- metadata.gz.sig +0 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 071af3578f3552a745775f7149260bb198c90e75
|
4
|
+
data.tar.gz: 38dd2e98f441b0c06959e64cfc82dadb4a6e3d3d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ad09deaa500d3fd5f8dc5dcf97797a8b7d04924cb13c6dbc867cef7ddccd118b2626e5c0ff3fe46fa87432fe49043258919f2d3369389aaf1b501ac7a1659a64
|
7
|
+
data.tar.gz: cf7f201d4e09eb229cbbc9295bda7095eaf903faccedd741de16d319acde1ddce96ce1bbe0421fa0801f892cf8245774300f5a76d731e839bc9b7e718863ecf6
|
checksums.yaml.gz.sig
ADDED
Binary file
|
data.tar.gz.sig
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
�˝4Iy˓U��K�+ʷ f86�:�+H"��z��n�� ʡW Z��#l�^�t�߸p�v{�J�n`'%[�C�YHL�2(���D����]p�������C�v��>Im����#c�d�|�S l�8v�*�d�D�#�>� ��� :�`��#��Ǝ�b���]b��]�oNj�VB|�.�����6��'���ԣ�)��c}�}iJ7�>��F�Zŀ>c;�@L�着P�QI^�'�`l
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#### 0.1.0-alpha.1
|
2
|
+
|
3
|
+
* baseline release identical to **sensu-community-plugins** repo
|
4
|
+
* changed *check-procs* to *check-process* to better reflect its use
|
5
|
+
* basic yard coverage
|
6
|
+
* pinned dependencies
|
7
|
+
* built against 1.9.3, 2.0, 2.1
|
8
|
+
* cryptographically signed
|
9
|
+
|
10
|
+
#### 0.0.1-alpha.2
|
11
|
+
|
12
|
+
* bump Vagrant to Chef 6.6
|
13
|
+
* update LICENSE and gemspec authors
|
14
|
+
* update README
|
15
|
+
* add required Ruby version *>= 1.9.3*
|
16
|
+
* add test/spec_help.rb
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 devsops@yieldbot.com
|
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,34 @@
|
|
1
|
+
## Sensu-Plugins-Process-Checks
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-process-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-process-checks)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-process-checks.svg)](http://badge.fury.io/rb/sensu-plugins-process-checks)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks)
|
6
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks)
|
7
|
+
|
8
|
+
## Functionality
|
9
|
+
|
10
|
+
**check-processs** and **check-process-restart** will check processes on a system and alert if specific conditions exist based upon a set of filters that each has implemented.
|
11
|
+
|
12
|
+
**check-cmd** will run a specific user designated command and parse the output with a regex or check for a specific status code. If either of these conditions is not what is expected it will alert.
|
13
|
+
|
14
|
+
## Files
|
15
|
+
* bin/check-cmd.rb
|
16
|
+
* bin/check-process-restart.rb
|
17
|
+
* bin/check-process.rb
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add the public key (if you haven’t already) as a trusted certificate
|
22
|
+
|
23
|
+
```
|
24
|
+
gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
|
25
|
+
gem install <gem> -P MediumSecurity
|
26
|
+
```
|
27
|
+
|
28
|
+
You can also download the key from /certs/ within each repository.
|
29
|
+
|
30
|
+
`gem install sensu-plugins-process-checks`
|
31
|
+
|
32
|
+
Add *sensu-plugins-process-checks* to your Gemfile, manifest, cookbook, etc
|
33
|
+
|
34
|
+
## Notes
|
data/bin/check-cmd.rb
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-cmd
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Generic check raising an error if exit code of command is not N.
|
7
|
+
#
|
8
|
+
# OUTPUT:
|
9
|
+
# plain text
|
10
|
+
#
|
11
|
+
# PLATFORMS:
|
12
|
+
# Linux
|
13
|
+
#
|
14
|
+
# DEPENDENCIES:
|
15
|
+
# gem: sensu-plugin
|
16
|
+
# gem: english
|
17
|
+
#
|
18
|
+
# USAGE:
|
19
|
+
#
|
20
|
+
# NOTES:
|
21
|
+
#
|
22
|
+
# LICENSE:
|
23
|
+
# Jean-Francois Theroux <failshell@gmail.com>
|
24
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
25
|
+
# for details.
|
26
|
+
#
|
27
|
+
|
28
|
+
require 'sensu-plugin/check/cli'
|
29
|
+
require 'english'
|
30
|
+
|
31
|
+
#
|
32
|
+
# Check Command Status
|
33
|
+
#
|
34
|
+
class CheckCmdStatus < Sensu::Plugin::Check::CLI
|
35
|
+
option :command,
|
36
|
+
description: 'command to run (might need quotes)',
|
37
|
+
short: '-c',
|
38
|
+
long: '--command COMMAND',
|
39
|
+
required: true
|
40
|
+
|
41
|
+
option :status,
|
42
|
+
description: 'exit status code the check should get',
|
43
|
+
short: '-s',
|
44
|
+
long: '--status STATUS',
|
45
|
+
default: '0'
|
46
|
+
|
47
|
+
option :check_output,
|
48
|
+
description: 'Optionally check the process stdout against a regex',
|
49
|
+
short: '-o',
|
50
|
+
long: '--check_output REGEX'
|
51
|
+
|
52
|
+
# Acquire the exit code and/or output of a command and alert if it is not
|
53
|
+
# what is expected.
|
54
|
+
#
|
55
|
+
def acquire_cmd_status
|
56
|
+
stdout = `#{config[:command]}`
|
57
|
+
# #YELLOW
|
58
|
+
unless $CHILD_STATUS.exitstatus.to_s == config[:status] # rubocop:disable UnlessElse
|
59
|
+
critical "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
|
60
|
+
else
|
61
|
+
if config[:check_output]
|
62
|
+
if Regexp.new(config[:check_output]).match(stdout)
|
63
|
+
ok "#{config[:command]} matched #{config[:check_output]} and exited with #{$CHILD_STATUS.exitstatus}"
|
64
|
+
else
|
65
|
+
critical "#{config[:command]} output didn't match #{config[:check_output]} (exit #{$CHILD_STATUS.exitstatus})"
|
66
|
+
end
|
67
|
+
else
|
68
|
+
ok "#{config[:command]} exited with #{$CHILD_STATUS.exitstatus}"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# main function
|
74
|
+
#
|
75
|
+
def run
|
76
|
+
acquire_cmd_status
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# check-process-restart
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
# This will check if a running process requires a restart if a
|
8
|
+
# dependent package/library has changed (i.e upgraded)
|
9
|
+
#
|
10
|
+
# OUTPUT:
|
11
|
+
# plain text
|
12
|
+
# Defaults: CRITICAL if 2 or more process require a restart
|
13
|
+
# WARNING if 1 process requires a restart
|
14
|
+
#
|
15
|
+
# PLATFORMS:
|
16
|
+
# Linux (Debian based distributions)
|
17
|
+
#
|
18
|
+
# DEPENDENCIES:
|
19
|
+
# gem: sensu-plugin
|
20
|
+
# gem: json
|
21
|
+
# deb: debian-goodies
|
22
|
+
# gem: english
|
23
|
+
#
|
24
|
+
# USAGE:
|
25
|
+
# check-process-restart.rb # Uses defaults
|
26
|
+
# check-process-restart.rb -w 2 -c 5
|
27
|
+
#
|
28
|
+
# NOTES:
|
29
|
+
# This will only work on Debian based distributions and requires the
|
30
|
+
# debian-goodies package.
|
31
|
+
#
|
32
|
+
# Also make sure the user "sensu" can sudo without password
|
33
|
+
#
|
34
|
+
# LICENSE:
|
35
|
+
# Yasser Nabi yassersaleemi@gmail.com
|
36
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
37
|
+
# for details.
|
38
|
+
|
39
|
+
require 'sensu-plugin/check/cli'
|
40
|
+
require 'json'
|
41
|
+
require 'English'
|
42
|
+
|
43
|
+
# Use to see if any processes require a restart
|
44
|
+
class CheckProcessRestart < Sensu::Plugin::Check::CLI
|
45
|
+
option :warn,
|
46
|
+
short: '-w WARN',
|
47
|
+
description: 'the number of processes to need restart before warn',
|
48
|
+
default: 1
|
49
|
+
|
50
|
+
option :crit,
|
51
|
+
short: '-c CRIT',
|
52
|
+
description: 'the number of processes to need restart before critical',
|
53
|
+
default: 2
|
54
|
+
|
55
|
+
# Debian command to run
|
56
|
+
CHECK_RESTART = '/usr/sbin/checkrestart'
|
57
|
+
|
58
|
+
# Set path for the checkrestart script
|
59
|
+
#
|
60
|
+
def initialize
|
61
|
+
super
|
62
|
+
end
|
63
|
+
|
64
|
+
# Check if we can run checkrestart script
|
65
|
+
# @return [Boolean]
|
66
|
+
#
|
67
|
+
def checkrestart?
|
68
|
+
File.exist?('/etc/debian_version') && File.exist?(CHECK_RESTART)
|
69
|
+
end
|
70
|
+
|
71
|
+
# Run checkrestart and parse process(es) and pid(s)
|
72
|
+
# @return [Hash]
|
73
|
+
def run_checkrestart
|
74
|
+
checkrestart_hash = { found: '', pids: [] }
|
75
|
+
|
76
|
+
out = `sudo #{CHECK_RESTART} 2>&1`
|
77
|
+
if $CHILD_STATUS.to_i != 0
|
78
|
+
checkrestart_hash[:found] = "Failed to run checkrestart: #{out}"
|
79
|
+
else
|
80
|
+
out.lines do |l|
|
81
|
+
m = /^Found\s(\d+)/.match(l)
|
82
|
+
if m
|
83
|
+
checkrestart_hash[:found] = m[1]
|
84
|
+
end
|
85
|
+
|
86
|
+
m = /^\s+(\d+)\s+([ \w\/\-\.]+)$/.match(l)
|
87
|
+
if m
|
88
|
+
checkrestart_hash[:pids] << { m[1] => m[2] }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
checkrestart_hash
|
93
|
+
end
|
94
|
+
|
95
|
+
# Main run method for the check
|
96
|
+
#
|
97
|
+
def run
|
98
|
+
unless checkrestart?
|
99
|
+
unknown "Can't seem to find checkrestart. This check only works in a Debian based distribution and you need debian-goodies package installed"
|
100
|
+
end
|
101
|
+
|
102
|
+
checkrestart_out = run_checkrestart
|
103
|
+
if /^Failed/.match(checkrestart_out[:found])
|
104
|
+
unknown checkrestart_out[:found]
|
105
|
+
end
|
106
|
+
message JSON.generate(checkrestart_out)
|
107
|
+
found = checkrestart_out[:found].to_i
|
108
|
+
warning if found >= config[:warn] && found < config[:crit]
|
109
|
+
critical if found >= config[:crit]
|
110
|
+
ok
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,292 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-process
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Finds processes matching various filters (name, state, etc). Will not
|
7
|
+
# match itself by default. The number of processes found will be tested
|
8
|
+
# against the Warning/critical thresholds. By default, fails with a
|
9
|
+
# CRITICAL if more than one process matches -- you must specify values
|
10
|
+
# for -w and -c to override this.
|
11
|
+
#
|
12
|
+
# Attempts to work on Cygwin (where ps does not have the features we
|
13
|
+
# need) by calling Windows' tasklist.exe, but this is not well tested.#
|
14
|
+
#
|
15
|
+
# OUTPUT:
|
16
|
+
# plain text
|
17
|
+
#
|
18
|
+
# PLATFORMS:
|
19
|
+
# Linux
|
20
|
+
#
|
21
|
+
# DEPENDENCIES:
|
22
|
+
# gem: sensu-plugin
|
23
|
+
# gem: english
|
24
|
+
#
|
25
|
+
# USAGE:
|
26
|
+
# # chef-client is running
|
27
|
+
# check-procs -p chef-client -W 1
|
28
|
+
#
|
29
|
+
# # there are not too many zombies
|
30
|
+
# check-procs -s Z -w 5 -c 10
|
31
|
+
#
|
32
|
+
# NOTES:
|
33
|
+
#
|
34
|
+
# LICENSE:
|
35
|
+
# Copyright 2011 Sonian, Inc <chefs@sonian.net>
|
36
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
37
|
+
# for details.
|
38
|
+
#
|
39
|
+
|
40
|
+
require 'sensu-plugin/check/cli'
|
41
|
+
require 'English'
|
42
|
+
|
43
|
+
#
|
44
|
+
# Check Processes
|
45
|
+
#
|
46
|
+
class CheckProcess < Sensu::Plugin::Check::CLI
|
47
|
+
option :warn_over,
|
48
|
+
short: '-w N',
|
49
|
+
long: '--warn-over N',
|
50
|
+
description: 'Trigger a warning if over a number',
|
51
|
+
proc: proc(&:to_i)
|
52
|
+
|
53
|
+
option :crit_over,
|
54
|
+
short: '-c N',
|
55
|
+
long: '--critical-over N',
|
56
|
+
description: 'Trigger a critical if over a number',
|
57
|
+
proc: proc(&:to_i)
|
58
|
+
|
59
|
+
option :warn_under,
|
60
|
+
short: '-W N',
|
61
|
+
long: '--warn-under N',
|
62
|
+
description: 'Trigger a warning if under a number',
|
63
|
+
proc: proc(&:to_i),
|
64
|
+
default: 1
|
65
|
+
|
66
|
+
option :crit_under,
|
67
|
+
short: '-C N',
|
68
|
+
long: '--critical-under N',
|
69
|
+
description: 'Trigger a critial if under a number',
|
70
|
+
proc: proc(&:to_i),
|
71
|
+
default: 1
|
72
|
+
|
73
|
+
option :metric,
|
74
|
+
short: '-t METRIC',
|
75
|
+
long: '--metric METRIC',
|
76
|
+
description: 'Trigger a critical if there are METRIC procs',
|
77
|
+
proc: proc(&:to_sym)
|
78
|
+
|
79
|
+
option :match_self,
|
80
|
+
short: '-m',
|
81
|
+
long: '--match-self',
|
82
|
+
description: 'Match itself',
|
83
|
+
boolean: true,
|
84
|
+
default: false
|
85
|
+
|
86
|
+
option :match_parent,
|
87
|
+
short: '-M',
|
88
|
+
long: '--match-parent',
|
89
|
+
description: 'Match parent process it uses ruby {process.ppid}',
|
90
|
+
boolean: true,
|
91
|
+
default: false
|
92
|
+
|
93
|
+
option :cmd_pat,
|
94
|
+
short: '-p PATTERN',
|
95
|
+
long: '--pattern PATTERN',
|
96
|
+
description: 'Match a command against this pattern'
|
97
|
+
|
98
|
+
option :file_pid,
|
99
|
+
short: '-f PID',
|
100
|
+
long: '--file-pid PID',
|
101
|
+
description: 'Check against a specific PID'
|
102
|
+
|
103
|
+
option :vsz,
|
104
|
+
short: '-z VSZ',
|
105
|
+
long: '--virtual-memory-size VSZ',
|
106
|
+
description: 'Trigger on a Virtual Memory size is bigger than this',
|
107
|
+
proc: proc(&:to_i)
|
108
|
+
|
109
|
+
option :rss,
|
110
|
+
short: '-r RSS',
|
111
|
+
long: '--resident-set-size RSS',
|
112
|
+
description: 'Trigger on a Resident Set size is bigger than this',
|
113
|
+
proc: proc(&:to_i)
|
114
|
+
|
115
|
+
option :pcpu,
|
116
|
+
short: '-P PCPU',
|
117
|
+
long: '--proportional-set-size PCPU',
|
118
|
+
description: 'Trigger on a Proportional Set Size is bigger than this',
|
119
|
+
proc: proc(&:to_f)
|
120
|
+
|
121
|
+
option :thcount,
|
122
|
+
short: '-T THCOUNT',
|
123
|
+
long: '--thread-count THCOUNT',
|
124
|
+
description: 'Trigger on a Thread Count is bigger than this',
|
125
|
+
proc: proc(&:to_i)
|
126
|
+
|
127
|
+
option :state,
|
128
|
+
short: '-s STATE',
|
129
|
+
long: '--state STATE',
|
130
|
+
description: 'Trigger on a specific state, example: Z for zombie',
|
131
|
+
proc: proc { |a| a.split(',') }
|
132
|
+
|
133
|
+
option :user,
|
134
|
+
short: '-u USER',
|
135
|
+
long: '--user USER',
|
136
|
+
description: 'Trigger on a specific user',
|
137
|
+
proc: proc { |a| a.split(',') }
|
138
|
+
|
139
|
+
option :esec_over,
|
140
|
+
short: '-e SECONDS',
|
141
|
+
long: '--esec-over SECONDS',
|
142
|
+
proc: proc(&:to_i),
|
143
|
+
description: 'Match processes that older that this, in SECONDS'
|
144
|
+
|
145
|
+
option :esec_under,
|
146
|
+
short: '-E SECONDS',
|
147
|
+
long: '--esec-under SECONDS',
|
148
|
+
proc: proc(&:to_i),
|
149
|
+
description: 'Match process that are younger than this, in SECONDS'
|
150
|
+
|
151
|
+
option :cpu_over,
|
152
|
+
short: '-i SECONDS',
|
153
|
+
long: '--cpu-over SECONDS',
|
154
|
+
proc: proc(&:to_i),
|
155
|
+
description: 'Match processes cpu time that is older than this, in SECONDS'
|
156
|
+
|
157
|
+
option :cpu_under,
|
158
|
+
short: '-I SECONDS',
|
159
|
+
long: '--cpu-under SECONDS',
|
160
|
+
proc: proc(&:to_i),
|
161
|
+
description: 'Match processes cpu time that is younger than this, in SECONDS'
|
162
|
+
|
163
|
+
# Read the pid file
|
164
|
+
# @param path [String] the path to the pid file, including the file
|
165
|
+
def read_pid(path)
|
166
|
+
if File.exist?(path)
|
167
|
+
File.read(path).strip.to_i
|
168
|
+
else
|
169
|
+
unknown "Could not read pid file #{path}"
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
# read the output of a command
|
174
|
+
# @param cmd [String] the command to read the output from
|
175
|
+
def read_lines(cmd)
|
176
|
+
IO.popen(cmd + ' 2>&1') do |child|
|
177
|
+
child.read.split("\n")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
# create a hash from the output of each line of a command
|
182
|
+
# @param line [String]
|
183
|
+
# @param cols
|
184
|
+
#
|
185
|
+
def line_to_hash(line, *cols)
|
186
|
+
Hash[cols.zip(line.strip.split(/\s+/, cols.size))]
|
187
|
+
end
|
188
|
+
|
189
|
+
# Is this running on cygwin
|
190
|
+
#
|
191
|
+
#
|
192
|
+
def on_cygwin?
|
193
|
+
# #YELLOW
|
194
|
+
`ps -W 2>&1`; $CHILD_STATUS.exitstatus == 0 # rubocop:disable Semicolon
|
195
|
+
end
|
196
|
+
|
197
|
+
# Acquire all the proceeses on a system for further analysis
|
198
|
+
#
|
199
|
+
def acquire_procs
|
200
|
+
if on_cygwin?
|
201
|
+
read_lines('ps -aWl').drop(1).map do |line|
|
202
|
+
# Horrible hack because cygwin's ps has no o option, every
|
203
|
+
# format includes the STIME column (which may contain spaces),
|
204
|
+
# and the process state (which isn't actually a column) can be
|
205
|
+
# blank. As of revision 1.35, the format is:
|
206
|
+
# const char *lfmt = "%c %7d %7d %7d %10u %4s %4u %8s %s\n";
|
207
|
+
state = line.slice!(0..0)
|
208
|
+
_stime = line.slice!(45..53)
|
209
|
+
line_to_hash(line, :pid, :ppid, :pgid, :winpid, :tty, :uid, :etime, :command, :time).merge(state: state)
|
210
|
+
end
|
211
|
+
else
|
212
|
+
read_lines('ps axwwo user,pid,vsz,rss,pcpu,nlwp,state,etime,time,command').drop(1).map do |line|
|
213
|
+
line_to_hash(line, :user, :pid, :vsz, :rss, :pcpu, :thcount, :state, :etime, :time, :command)
|
214
|
+
end
|
215
|
+
end
|
216
|
+
end
|
217
|
+
|
218
|
+
# Match to a time
|
219
|
+
#
|
220
|
+
def etime_to_esec(etime)
|
221
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(etime)
|
222
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
223
|
+
end
|
224
|
+
|
225
|
+
# Match to a time
|
226
|
+
#
|
227
|
+
def cputime_to_csec(time)
|
228
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(time)
|
229
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
230
|
+
end
|
231
|
+
|
232
|
+
# The main function
|
233
|
+
#
|
234
|
+
def run
|
235
|
+
procs = acquire_procs
|
236
|
+
|
237
|
+
if config[:file_pid] && (file_pid = read_pid(config[:file_pid]))
|
238
|
+
procs.reject! { |p| p[:pid].to_i != file_pid }
|
239
|
+
end
|
240
|
+
procs.reject! { |p| p[:pid].to_i == $PROCESS_ID } unless config[:match_self]
|
241
|
+
procs.reject! { |p| p[:pid].to_i == Process.ppid } unless config[:match_parent]
|
242
|
+
procs.reject! { |p| p[:command] !~ /#{config[:cmd_pat]}/ } if config[:cmd_pat]
|
243
|
+
procs.reject! { |p| p[:vsz].to_f > config[:vsz] } if config[:vsz]
|
244
|
+
procs.reject! { |p| p[:rss].to_f > config[:rss] } if config[:rss]
|
245
|
+
procs.reject! { |p| p[:pcpu].to_f > config[:pcpu] } if config[:pcpu]
|
246
|
+
procs.reject! { |p| p[:thcount].to_i > config[:thcount] } if config[:thcount]
|
247
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) >= config[:esec_under] } if config[:esec_under]
|
248
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) <= config[:esec_over] } if config[:esec_over]
|
249
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) >= config[:cpu_under] } if config[:cpu_under]
|
250
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) <= config[:cpu_over] } if config[:cpu_over]
|
251
|
+
procs.reject! { |p| !config[:state].include?(p[:state]) } if config[:state]
|
252
|
+
procs.reject! { |p| !config[:user].include?(p[:user]) } if config[:user]
|
253
|
+
|
254
|
+
msg = "Found #{procs.size} matching processes"
|
255
|
+
msg += "; cmd /#{config[:cmd_pat]}/" if config[:cmd_pat]
|
256
|
+
msg += "; state #{config[:state].join(',')}" if config[:state]
|
257
|
+
msg += "; user #{config[:user].join(',')}" if config[:user]
|
258
|
+
msg += "; vsz < #{config[:vsz]}" if config[:vsz]
|
259
|
+
msg += "; rss < #{config[:rss]}" if config[:rss]
|
260
|
+
msg += "; pcpu < #{config[:pcpu]}" if config[:pcpu]
|
261
|
+
msg += "; thcount < #{config[:thcount]}" if config[:thcount]
|
262
|
+
msg += "; esec < #{config[:esec_under]}" if config[:esec_under]
|
263
|
+
msg += "; esec > #{config[:esec_over]}" if config[:esec_over]
|
264
|
+
msg += "; csec < #{config[:cpu_under]}" if config[:cpu_under]
|
265
|
+
msg += "; csec > #{config[:cpu_over]}" if config[:cpu_over]
|
266
|
+
msg += "; pid #{config[:file_pid]}" if config[:file_pid]
|
267
|
+
|
268
|
+
if config[:metric]
|
269
|
+
# #YELLOW
|
270
|
+
count = procs.map { |p| p[config[:metric]].to_i }.reduce { |a, b| a + b } # rubocop:disable SingleLineBlockParams
|
271
|
+
msg += "; #{config[:metric]} == #{count}"
|
272
|
+
else
|
273
|
+
count = procs.size
|
274
|
+
end
|
275
|
+
|
276
|
+
# #YELLOW
|
277
|
+
if !!config[:crit_under] && count < config[:crit_under] # rubocop:disable Style/DoubleNegation
|
278
|
+
critical msg
|
279
|
+
# #YELLOW
|
280
|
+
elsif !!config[:crit_over] && count > config[:crit_over] # rubocop:disable Style/DoubleNegation
|
281
|
+
critical msg
|
282
|
+
# #YELLOW
|
283
|
+
elsif !!config[:warn_under] && count < config[:warn_under] # rubocop:disable Style/DoubleNegation
|
284
|
+
warning msg
|
285
|
+
# #YELLOW
|
286
|
+
elsif !!config[:warn_over] && count > config[:warn_over] # rubocop:disable Style/DoubleNegation
|
287
|
+
warning msg
|
288
|
+
else
|
289
|
+
ok msg
|
290
|
+
end
|
291
|
+
end
|
292
|
+
end
|
metadata
ADDED
@@ -0,0 +1,230 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-process-checks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1.alpha.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Yieldbot, Inc, and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain:
|
11
|
+
- |
|
12
|
+
-----BEGIN CERTIFICATE-----
|
13
|
+
MIIDgDCCAmigAwIBAgIBATANBgkqhkiG9w0BAQUFADBDMRIwEAYDVQQDDAltYXR0
|
14
|
+
am9uZXMxGDAWBgoJkiaJk/IsZAEZFgh5aWVsZGJvdDETMBEGCgmSJomT8ixkARkW
|
15
|
+
A2NvbTAeFw0xNTAxMjgyMTAyNTFaFw0xNjAxMjgyMTAyNTFaMEMxEjAQBgNVBAMM
|
16
|
+
CW1hdHRqb25lczEYMBYGCgmSJomT8ixkARkWCHlpZWxkYm90MRMwEQYKCZImiZPy
|
17
|
+
LGQBGRYDY29tMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAyTSzVYnO
|
18
|
+
CLgyrIyT1mBQakArQyW8xhi6MlDqyzXHJGeERT790U6EgoBVeS4XoK0ptFZNR8Tf
|
19
|
+
zko0w+Nv47TarSCgkPOaxY+mxWnAVR10dOmfeLr7huiMyps+YD56/EF2FqQ3jf/+
|
20
|
+
qohENfKD91qy1ieEy+Fn7Pf74ltbNKUdkb9a9eFXQ0DQ4ip5vik7DzjQkUTj4lca
|
21
|
+
k6ArwnmHX4YDhZoYtrQJ8jVktN0/+NtA40M5qkCYHNe5tUW25b/tKVYuioxG6b2Z
|
22
|
+
oIzaZxRLxf6HVAWpCVRT/F5+/yjigkX4u++eYacfLGleXQzoK7BL65vHGMJygWEE
|
23
|
+
0TKGqFOrl/L0AQIDAQABo38wfTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNV
|
24
|
+
HQ4EFgQUEf6a8Td7MrSZc8ImbLFZAENPbz0wIQYDVR0RBBowGIEWbWF0dGpvbmVz
|
25
|
+
QHlpZWxkYm90LmNvbTAhBgNVHRIEGjAYgRZtYXR0am9uZXNAeWllbGRib3QuY29t
|
26
|
+
MA0GCSqGSIb3DQEBBQUAA4IBAQBbzXAYA3BVGw8DZ0YYoY1VHPNEcH5qPIApmHO8
|
27
|
+
rvSmuUT0yMEi7u00H/5uHRFf4LleGT/+sTdyXKsNPGT9kdRuQEgwi+vf7Zfvd8aX
|
28
|
+
UF/+4VkEYf/8rV8Ere6u2QaWPgApdMV6JjKr1fAwCTd8AuGXNaWItiPPMseSQzLJ
|
29
|
+
JKP4hVvbc1d+oS925B1lcBiqn2aYvElbyNAVmQPywNNqkWmvtlqj9ZVJfV5HQLdu
|
30
|
+
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
|
+
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
|
+
-----END CERTIFICATE-----
|
33
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
34
|
+
dependencies:
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: english
|
37
|
+
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - '='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: 0.6.3
|
42
|
+
type: :runtime
|
43
|
+
prerelease: false
|
44
|
+
version_requirements: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - '='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.6.3
|
49
|
+
- !ruby/object:Gem::Dependency
|
50
|
+
name: sensu-plugin
|
51
|
+
requirement: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - '='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.1.0
|
56
|
+
type: :runtime
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - '='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: 1.1.0
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: json
|
65
|
+
requirement: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 1.8.2
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: 1.8.2
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: codeclimate-test-reporter
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
type: :development
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: rubocop
|
93
|
+
requirement: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ~>
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 0.17.0
|
98
|
+
type: :development
|
99
|
+
prerelease: false
|
100
|
+
version_requirements: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ~>
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 0.17.0
|
105
|
+
- !ruby/object:Gem::Dependency
|
106
|
+
name: rspec
|
107
|
+
requirement: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ~>
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '3.1'
|
112
|
+
type: :development
|
113
|
+
prerelease: false
|
114
|
+
version_requirements: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ~>
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '3.1'
|
119
|
+
- !ruby/object:Gem::Dependency
|
120
|
+
name: bundler
|
121
|
+
requirement: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ~>
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '1.7'
|
126
|
+
type: :development
|
127
|
+
prerelease: false
|
128
|
+
version_requirements: !ruby/object:Gem::Requirement
|
129
|
+
requirements:
|
130
|
+
- - ~>
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '1.7'
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rake
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - ~>
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '10.0'
|
140
|
+
type: :development
|
141
|
+
prerelease: false
|
142
|
+
version_requirements: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - ~>
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '10.0'
|
147
|
+
- !ruby/object:Gem::Dependency
|
148
|
+
name: github-markup
|
149
|
+
requirement: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
type: :development
|
155
|
+
prerelease: false
|
156
|
+
version_requirements: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - '>='
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0'
|
161
|
+
- !ruby/object:Gem::Dependency
|
162
|
+
name: redcarpet
|
163
|
+
requirement: !ruby/object:Gem::Requirement
|
164
|
+
requirements:
|
165
|
+
- - '>='
|
166
|
+
- !ruby/object:Gem::Version
|
167
|
+
version: '0'
|
168
|
+
type: :development
|
169
|
+
prerelease: false
|
170
|
+
version_requirements: !ruby/object:Gem::Requirement
|
171
|
+
requirements:
|
172
|
+
- - '>='
|
173
|
+
- !ruby/object:Gem::Version
|
174
|
+
version: '0'
|
175
|
+
- !ruby/object:Gem::Dependency
|
176
|
+
name: yard
|
177
|
+
requirement: !ruby/object:Gem::Requirement
|
178
|
+
requirements:
|
179
|
+
- - '>='
|
180
|
+
- !ruby/object:Gem::Version
|
181
|
+
version: '0'
|
182
|
+
type: :development
|
183
|
+
prerelease: false
|
184
|
+
version_requirements: !ruby/object:Gem::Requirement
|
185
|
+
requirements:
|
186
|
+
- - '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
description: Sensu process checks
|
190
|
+
email: <sensu-users@googlegroups.com>
|
191
|
+
executables:
|
192
|
+
- check-cmd.rb
|
193
|
+
- check-process-restart.rb
|
194
|
+
- check-process.rb
|
195
|
+
extensions: []
|
196
|
+
extra_rdoc_files: []
|
197
|
+
files:
|
198
|
+
- bin/check-cmd.rb
|
199
|
+
- bin/check-process-restart.rb
|
200
|
+
- bin/check-process.rb
|
201
|
+
- lib/sensu-plugins-process-checks.rb
|
202
|
+
- LICENSE
|
203
|
+
- README.md
|
204
|
+
- CHANGELOG.md
|
205
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-process-checks
|
206
|
+
licenses:
|
207
|
+
- MIT
|
208
|
+
metadata: {}
|
209
|
+
post_install_message:
|
210
|
+
rdoc_options: []
|
211
|
+
require_paths:
|
212
|
+
- lib
|
213
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - '>='
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: 1.9.3
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - '>'
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.3.1
|
223
|
+
requirements: []
|
224
|
+
rubyforge_project:
|
225
|
+
rubygems_version: 2.0.14
|
226
|
+
signing_key:
|
227
|
+
specification_version: 4
|
228
|
+
summary: Sensu process checks
|
229
|
+
test_files: []
|
230
|
+
has_rdoc:
|
metadata.gz.sig
ADDED
Binary file
|