cb_sensu_check_processes 0.0.5
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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +84 -0
- data/LICENSE +22 -0
- data/README.md +31 -0
- data/bin/check-cmd.rb +78 -0
- data/bin/check-process-restart.rb +112 -0
- data/bin/check-process.rb +298 -0
- data/bin/check-threads-count.rb +96 -0
- data/bin/metrics-process-status.rb +144 -0
- data/bin/metrics-processes-threads-count.rb +102 -0
- data/bin/process-uptime-metrics.sh +91 -0
- data/lib/sensu-plugins-process-checks/version.rb +9 -0
- data/lib/sensu-plugins-process-checks.rb +1 -0
- metadata +236 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: fdb6f6703ba42f26b2799acea9670c547eaf4f6e
|
4
|
+
data.tar.gz: 33ba683bef70de5a85d8ed72459557f521aa65ef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f937730105c45e68a0dd3d1c28ae50aa36c0339590e4aa5b0fa0f92ab2d54969e0857d1520d1ff36351ff2709d66ee53e6105de13a073a86212bdc25199a0f3e
|
7
|
+
data.tar.gz: eac4f12d6f1b77ec439409c25c404017c52188540c8c367c6fd77d742fba8a5ca500aa0392e5d94548bcae36a9087d7a3f97dc8df556f24b32864b49ae0e71fc
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
#Change Log
|
2
|
+
This project adheres to [Semantic Versioning](http://semver.org/).
|
3
|
+
|
4
|
+
This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
|
5
|
+
|
6
|
+
## Unreleased
|
7
|
+
|
8
|
+
## [0.0.4] - 2015-07-14
|
9
|
+
### Changed
|
10
|
+
- updated sensu-plugin gem to 1.2.0
|
11
|
+
|
12
|
+
## [0.0.3] - [2015-07-13]
|
13
|
+
### Fixed
|
14
|
+
- issue #9: variable type conversion to_i in check-process-restart
|
15
|
+
|
16
|
+
### Changed
|
17
|
+
- updated documentation links in README and CONTRIBUTING
|
18
|
+
- removed unused rake tasks from Rakefile
|
19
|
+
- puts deps in alpha order in Rakefile
|
20
|
+
- puts deps in order in Gemspec
|
21
|
+
|
22
|
+
## [0.0.2] - 2015-06-03
|
23
|
+
|
24
|
+
### Fixed
|
25
|
+
- added binstubs
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
- removed cruft from /lib
|
29
|
+
|
30
|
+
## [0.0.1] - [2015-05-01]
|
31
|
+
|
32
|
+
### Added
|
33
|
+
- initial stable release
|
34
|
+
|
35
|
+
## [0.0.1.alpha.6]
|
36
|
+
|
37
|
+
### Added
|
38
|
+
- add chef provisioner to Vagrantfile
|
39
|
+
- add metadata to gemspec
|
40
|
+
|
41
|
+
### Fixed
|
42
|
+
- fix rubocop errors
|
43
|
+
|
44
|
+
## [0.0.1.alpha.5]
|
45
|
+
|
46
|
+
### Added
|
47
|
+
- add new check for process uptime metrics
|
48
|
+
|
49
|
+
## [0.0.1.alpha.4]
|
50
|
+
|
51
|
+
### Changed
|
52
|
+
- convert scrips to sys-proctable gem for platform independence
|
53
|
+
|
54
|
+
## [0.0.1-alpha.3]
|
55
|
+
|
56
|
+
### Added
|
57
|
+
- add proc-status-metrics
|
58
|
+
|
59
|
+
### Changed
|
60
|
+
- change proc-status-metrics to process-status-metrics
|
61
|
+
|
62
|
+
## [0.0.1-alpha.2]
|
63
|
+
|
64
|
+
### Changed
|
65
|
+
- bump Vagrant to Chef 6.6
|
66
|
+
- update LICENSE and gemspec authors
|
67
|
+
- update README
|
68
|
+
|
69
|
+
### Added
|
70
|
+
- add required Ruby version *>= 1.9.3*
|
71
|
+
- add test/spec_help.rb
|
72
|
+
|
73
|
+
## [0.1.0-alpha.1]
|
74
|
+
|
75
|
+
- baseline release identical to **sensu-community-plugins** repo
|
76
|
+
|
77
|
+
### Changed
|
78
|
+
- changed *check-procs* to *check-process* to better reflect its use
|
79
|
+
- pinned dependencies
|
80
|
+
|
81
|
+
### Added
|
82
|
+
- basic yard coverage
|
83
|
+
- built against 1.9.3, 2.0, 2.1
|
84
|
+
- cryptographically signed
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2015 Sensu-Plugins
|
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,31 @@
|
|
1
|
+
## Sensu-Plugins-process-checks
|
2
|
+
|
3
|
+
[ ](https://travis-ci.org/sensu-plugins/sensu-plugins-process-checks)
|
4
|
+
[](http://badge.fury.io/rb/sensu-plugins-process-checks)
|
5
|
+
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks)
|
6
|
+
[](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks)
|
7
|
+
[](https://gemnasium.com/sensu-plugins/sensu-plugins-process-checks)
|
8
|
+
[](https://codeship.com/projects/77521)
|
9
|
+
|
10
|
+
## Functionality
|
11
|
+
|
12
|
+
**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.
|
13
|
+
|
14
|
+
**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.
|
15
|
+
|
16
|
+
## Files
|
17
|
+
* bin/check-cmd.rb
|
18
|
+
* bin/check-process-restart.rb
|
19
|
+
* bin/check-process.rb
|
20
|
+
* bin/check-threads-count.rb
|
21
|
+
* bin/metrics-process-status.rb
|
22
|
+
* bin/metrics-processes-threads-count.rb
|
23
|
+
* bin/process-uptime-metrics.sh
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
30
|
+
|
31
|
+
## 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 # rubocop:disable all
|
56
|
+
stdout = `#{config[:command]}`
|
57
|
+
# #YELLOW
|
58
|
+
unless $CHILD_STATUS.exitstatus.to_s == config[:status] # rubocop:disable UnlessElse
|
59
|
+
critical "exited with #{$CHILD_STATUS.exitstatus}"
|
60
|
+
else
|
61
|
+
if config[:check_output]
|
62
|
+
if Regexp.new(config[:check_output]).match(stdout)
|
63
|
+
ok "matched #{config[:check_output]} and exited with #{$CHILD_STATUS.exitstatus}"
|
64
|
+
else
|
65
|
+
critical "output didn't match #{config[:check_output]} (exit #{$CHILD_STATUS.exitstatus})"
|
66
|
+
end
|
67
|
+
else
|
68
|
+
ok "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 # rubocop:disable all
|
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].to_i && found < config[:crit].to_i
|
109
|
+
critical if found >= config[:crit].to_i
|
110
|
+
ok
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,298 @@
|
|
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 :exclude_pat,
|
99
|
+
short: '-x PATTERN',
|
100
|
+
long: '--exclude-pattern PATTERN',
|
101
|
+
description: "Don't match against a pattern to prevent false positives"
|
102
|
+
|
103
|
+
option :file_pid,
|
104
|
+
short: '-f PID',
|
105
|
+
long: '--file-pid PID',
|
106
|
+
description: 'Check against a specific PID'
|
107
|
+
|
108
|
+
option :vsz,
|
109
|
+
short: '-z VSZ',
|
110
|
+
long: '--virtual-memory-size VSZ',
|
111
|
+
description: 'Trigger on a Virtual Memory size is bigger than this',
|
112
|
+
proc: proc(&:to_i)
|
113
|
+
|
114
|
+
option :rss,
|
115
|
+
short: '-r RSS',
|
116
|
+
long: '--resident-set-size RSS',
|
117
|
+
description: 'Trigger on a Resident Set size is bigger than this',
|
118
|
+
proc: proc(&:to_i)
|
119
|
+
|
120
|
+
option :pcpu,
|
121
|
+
short: '-P PCPU',
|
122
|
+
long: '--proportional-set-size PCPU',
|
123
|
+
description: 'Trigger on a Proportional Set Size is bigger than this',
|
124
|
+
proc: proc(&:to_f)
|
125
|
+
|
126
|
+
option :thcount,
|
127
|
+
short: '-T THCOUNT',
|
128
|
+
long: '--thread-count THCOUNT',
|
129
|
+
description: 'Trigger on a Thread Count is bigger than this',
|
130
|
+
proc: proc(&:to_i)
|
131
|
+
|
132
|
+
option :state,
|
133
|
+
short: '-s STATE',
|
134
|
+
long: '--state STATE',
|
135
|
+
description: 'Trigger on a specific state, example: Z for zombie',
|
136
|
+
proc: proc { |a| a.split(',') }
|
137
|
+
|
138
|
+
option :user,
|
139
|
+
short: '-u USER',
|
140
|
+
long: '--user USER',
|
141
|
+
description: 'Trigger on a specific user',
|
142
|
+
proc: proc { |a| a.split(',') }
|
143
|
+
|
144
|
+
option :esec_over,
|
145
|
+
short: '-e SECONDS',
|
146
|
+
long: '--esec-over SECONDS',
|
147
|
+
proc: proc(&:to_i),
|
148
|
+
description: 'Match processes that older that this, in SECONDS'
|
149
|
+
|
150
|
+
option :esec_under,
|
151
|
+
short: '-E SECONDS',
|
152
|
+
long: '--esec-under SECONDS',
|
153
|
+
proc: proc(&:to_i),
|
154
|
+
description: 'Match process that are younger than this, in SECONDS'
|
155
|
+
|
156
|
+
option :cpu_over,
|
157
|
+
short: '-i SECONDS',
|
158
|
+
long: '--cpu-over SECONDS',
|
159
|
+
proc: proc(&:to_i),
|
160
|
+
description: 'Match processes cpu time that is older than this, in SECONDS'
|
161
|
+
|
162
|
+
option :cpu_under,
|
163
|
+
short: '-I SECONDS',
|
164
|
+
long: '--cpu-under SECONDS',
|
165
|
+
proc: proc(&:to_i),
|
166
|
+
description: 'Match processes cpu time that is younger than this, in SECONDS'
|
167
|
+
|
168
|
+
# Read the pid file
|
169
|
+
# @param path [String] the path to the pid file, including the file
|
170
|
+
def read_pid(path)
|
171
|
+
if File.exist?(path)
|
172
|
+
File.read(path).strip.to_i
|
173
|
+
else
|
174
|
+
unknown "Could not read pid file #{path}"
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
# read the output of a command
|
179
|
+
# @param cmd [String] the command to read the output from
|
180
|
+
def read_lines(cmd)
|
181
|
+
IO.popen(cmd + ' 2>&1') do |child|
|
182
|
+
child.read.split("\n")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# create a hash from the output of each line of a command
|
187
|
+
# @param line [String]
|
188
|
+
# @param cols
|
189
|
+
#
|
190
|
+
def line_to_hash(line, *cols)
|
191
|
+
Hash[cols.zip(line.strip.split(/\s+/, cols.size))]
|
192
|
+
end
|
193
|
+
|
194
|
+
# Is this running on cygwin
|
195
|
+
#
|
196
|
+
#
|
197
|
+
def on_cygwin?
|
198
|
+
# #YELLOW
|
199
|
+
`ps -W 2>&1`; $CHILD_STATUS.exitstatus == 0 # rubocop:disable Semicolon
|
200
|
+
end
|
201
|
+
|
202
|
+
# Acquire all the proceeses on a system for further analysis
|
203
|
+
#
|
204
|
+
def acquire_procs
|
205
|
+
if on_cygwin?
|
206
|
+
read_lines('ps -aWl').drop(1).map do |line|
|
207
|
+
# Horrible hack because cygwin's ps has no o option, every
|
208
|
+
# format includes the STIME column (which may contain spaces),
|
209
|
+
# and the process state (which isn't actually a column) can be
|
210
|
+
# blank. As of revision 1.35, the format is:
|
211
|
+
# const char *lfmt = "%c %7d %7d %7d %10u %4s %4u %8s %s\n";
|
212
|
+
state = line.slice!(0..0)
|
213
|
+
_stime = line.slice!(45..53)
|
214
|
+
line_to_hash(line, :pid, :ppid, :pgid, :winpid, :tty, :uid, :etime, :command, :time).merge(state: state)
|
215
|
+
end
|
216
|
+
else
|
217
|
+
read_lines('ps axwwo user,pid,vsz,rss,pcpu,nlwp,state,etime,time,command').drop(1).map do |line|
|
218
|
+
line_to_hash(line, :user, :pid, :vsz, :rss, :pcpu, :thcount, :state, :etime, :time, :command)
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
# Match to a time
|
224
|
+
#
|
225
|
+
def etime_to_esec(etime) # rubocop:disable all
|
226
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(etime)
|
227
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
228
|
+
end
|
229
|
+
|
230
|
+
# Match to a time
|
231
|
+
#
|
232
|
+
def cputime_to_csec(time) # rubocop:disable all
|
233
|
+
m = /(\d+-)?(\d\d:)?(\d\d):(\d\d)/.match(time)
|
234
|
+
(m[1] || 0).to_i * 86_400 + (m[2] || 0).to_i * 3600 + (m[3] || 0).to_i * 60 + (m[4] || 0).to_i
|
235
|
+
end
|
236
|
+
|
237
|
+
# The main function
|
238
|
+
#
|
239
|
+
def run # rubocop:disable all
|
240
|
+
procs = acquire_procs
|
241
|
+
|
242
|
+
if config[:file_pid] && (file_pid = read_pid(config[:file_pid]))
|
243
|
+
procs.reject! { |p| p[:pid].to_i != file_pid }
|
244
|
+
end
|
245
|
+
procs.reject! { |p| p[:pid].to_i == $PROCESS_ID } unless config[:match_self]
|
246
|
+
procs.reject! { |p| p[:pid].to_i == Process.ppid } unless config[:match_parent]
|
247
|
+
procs.reject! { |p| p[:command] =~ /#{config[:exclude_pat]}/ } if config[:exclude_pat]
|
248
|
+
procs.reject! { |p| p[:command] !~ /#{config[:cmd_pat]}/ } if config[:cmd_pat]
|
249
|
+
procs.reject! { |p| p[:vsz].to_f > config[:vsz] } if config[:vsz]
|
250
|
+
procs.reject! { |p| p[:rss].to_f > config[:rss] } if config[:rss]
|
251
|
+
procs.reject! { |p| p[:pcpu].to_f > config[:pcpu] } if config[:pcpu]
|
252
|
+
procs.reject! { |p| p[:thcount].to_i > config[:thcount] } if config[:thcount]
|
253
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) >= config[:esec_under] } if config[:esec_under]
|
254
|
+
procs.reject! { |p| etime_to_esec(p[:etime]) <= config[:esec_over] } if config[:esec_over]
|
255
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) >= config[:cpu_under] } if config[:cpu_under]
|
256
|
+
procs.reject! { |p| cputime_to_csec(p[:time]) <= config[:cpu_over] } if config[:cpu_over]
|
257
|
+
procs.reject! { |p| !config[:state].include?(p[:state]) } if config[:state]
|
258
|
+
procs.reject! { |p| !config[:user].include?(p[:user]) } if config[:user]
|
259
|
+
|
260
|
+
msg = "Found #{procs.size} matching processes"
|
261
|
+
msg += "; cmd /#{config[:cmd_pat]}/" if config[:cmd_pat]
|
262
|
+
msg += "; state #{config[:state].join(',')}" if config[:state]
|
263
|
+
msg += "; user #{config[:user].join(',')}" if config[:user]
|
264
|
+
msg += "; vsz < #{config[:vsz]}" if config[:vsz]
|
265
|
+
msg += "; rss < #{config[:rss]}" if config[:rss]
|
266
|
+
msg += "; pcpu < #{config[:pcpu]}" if config[:pcpu]
|
267
|
+
msg += "; thcount < #{config[:thcount]}" if config[:thcount]
|
268
|
+
msg += "; esec < #{config[:esec_under]}" if config[:esec_under]
|
269
|
+
msg += "; esec > #{config[:esec_over]}" if config[:esec_over]
|
270
|
+
msg += "; csec < #{config[:cpu_under]}" if config[:cpu_under]
|
271
|
+
msg += "; csec > #{config[:cpu_over]}" if config[:cpu_over]
|
272
|
+
msg += "; pid #{config[:file_pid]}" if config[:file_pid]
|
273
|
+
|
274
|
+
if config[:metric]
|
275
|
+
# #YELLOW
|
276
|
+
count = procs.map { |p| p[config[:metric]].to_i }.reduce { |a, b| a + b } # rubocop:disable SingleLineBlockParams
|
277
|
+
msg += "; #{config[:metric]} == #{count}"
|
278
|
+
else
|
279
|
+
count = procs.size
|
280
|
+
end
|
281
|
+
|
282
|
+
# #YELLOW
|
283
|
+
if !!config[:crit_under] && count < config[:crit_under] # rubocop:disable Style/DoubleNegation
|
284
|
+
critical msg
|
285
|
+
# #YELLOW
|
286
|
+
elsif !!config[:crit_over] && count > config[:crit_over] # rubocop:disable Style/DoubleNegation
|
287
|
+
critical msg
|
288
|
+
# #YELLOW
|
289
|
+
elsif !!config[:warn_under] && count < config[:warn_under] # rubocop:disable Style/DoubleNegation
|
290
|
+
warning msg
|
291
|
+
# #YELLOW
|
292
|
+
elsif !!config[:warn_over] && count > config[:warn_over] # rubocop:disable Style/DoubleNegation
|
293
|
+
warning msg
|
294
|
+
else
|
295
|
+
ok msg
|
296
|
+
end
|
297
|
+
end
|
298
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-threads-count.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Counts the number of threads running on the system and alerts if that number is greater than the warning or critical values.
|
7
|
+
# The default warning and critical count thresholds come from the ~32000 thread limit in older Linux kernels.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# check
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux, Windows
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: sys-proctable
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# The check will return an UNKNOWN if the sys-proctable version is not new enough to support it.
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
# sys-proctable > 0.9.5 is required for counting threads
|
24
|
+
#
|
25
|
+
# LICENSE:
|
26
|
+
# Copyright (c) 2015 Contegix LLC
|
27
|
+
# Richard Chatteron richard.chatterton@contegix.com
|
28
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
29
|
+
# for details.
|
30
|
+
#
|
31
|
+
|
32
|
+
require 'sensu-plugin/check/cli'
|
33
|
+
require 'sys/proctable'
|
34
|
+
|
35
|
+
#
|
36
|
+
# Check Threads Count
|
37
|
+
#
|
38
|
+
class ThreadsCount < Sensu::Plugin::Check::CLI
|
39
|
+
option :warn,
|
40
|
+
description: 'Produce a warning if the total number of threads is greater than this value.',
|
41
|
+
short: '-w WARN',
|
42
|
+
default: 30_000,
|
43
|
+
proc: proc(&:to_i)
|
44
|
+
|
45
|
+
option :crit,
|
46
|
+
description: 'Produce a critical if the total number of threads is greater than this value.',
|
47
|
+
short: '-c CRIT',
|
48
|
+
default: 32_000,
|
49
|
+
proc: proc(&:to_i)
|
50
|
+
|
51
|
+
PROCTABLE_MSG = 'sys-proctable version newer than 0.9.5 is required for counting threads with -t or --threads'
|
52
|
+
|
53
|
+
# Exit with an unknown if sys-proctable is not high enough to support counting threads.
|
54
|
+
def check_proctable_version
|
55
|
+
Gem.loaded_specs['sys-proctable'].version > Gem::Version.create('0.9.5')
|
56
|
+
end
|
57
|
+
|
58
|
+
# Takes a value to be tested as an integer. If a new Integer instance cannot be created from it, return 1.
|
59
|
+
# See the comments on get_process_threads() for why 1 is returned.
|
60
|
+
def test_int(i)
|
61
|
+
return Integer(i) rescue return 1
|
62
|
+
end
|
63
|
+
|
64
|
+
# Takes a process struct from Sys::ProcTable.ps() as an argument
|
65
|
+
# Attempts to use the Linux thread count field :nlwp first, then tries the Windows field :thread_count.
|
66
|
+
# Returns the number of processes in those fields.
|
67
|
+
# Otherwise, returns 1 as all processes are assumed to have at least one thread.
|
68
|
+
def get_process_threads(p)
|
69
|
+
if p.respond_to?(:nlwp)
|
70
|
+
return test_int(p.nlwp)
|
71
|
+
elsif p.respond_to?(:thread_count)
|
72
|
+
return test_int(p.thread_count)
|
73
|
+
else
|
74
|
+
return 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def count_threads
|
79
|
+
ps_table = Sys::ProcTable.ps
|
80
|
+
ps_table.reduce(0) do |sum, p|
|
81
|
+
sum + get_process_threads(p)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
# Main function
|
86
|
+
def run # rubocop:disable all
|
87
|
+
if !check_proctable_version
|
88
|
+
unknown PROCTABLE_MSG unless check_proctable_version
|
89
|
+
else
|
90
|
+
threads = count_threads
|
91
|
+
critical "#{threads} threads running, over threshold #{config[:crit]}" if threads > config[:crit]
|
92
|
+
warning "#{threads} threads running, over threshold #{config[:warn]}" if threads > config[:warn]
|
93
|
+
ok "#{threads} threads running"
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# proc-status-metrics
|
5
|
+
#
|
6
|
+
# DESCRIPTION:
|
7
|
+
# For all processes owned by a user AND/OR matching a provided process
|
8
|
+
# name substring, return selected memory metrics from /proc/[PID]/status
|
9
|
+
|
10
|
+
#
|
11
|
+
# OUTPUT:
|
12
|
+
# metric data
|
13
|
+
#
|
14
|
+
# PLATFORMS:
|
15
|
+
# Linux
|
16
|
+
#
|
17
|
+
# DEPENDENCIES:
|
18
|
+
# gem: sensu-plugin
|
19
|
+
#
|
20
|
+
# USAGE:
|
21
|
+
#
|
22
|
+
# NOTES:
|
23
|
+
# - This check names the metrics after the full process name
|
24
|
+
# string as found in /proc/[PID]/cmdline, so data will be lost if
|
25
|
+
# you have multiple processes with identical cmdlines.
|
26
|
+
# - A process that changes its cmdline but still matches the search
|
27
|
+
# query will be duplicated as multiple discovered processes.
|
28
|
+
# - We make some assumptions in parsing /proc/[PID]/status, this will
|
29
|
+
# mostly only work with the memory-related stats.
|
30
|
+
|
31
|
+
#
|
32
|
+
# LICENSE:
|
33
|
+
# Copyright (c) 2014 Cozy Services Ltd. opensource@cozy.co
|
34
|
+
# Matt Greensmith mgreensmith@cozy.co
|
35
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
36
|
+
# for details.
|
37
|
+
#
|
38
|
+
|
39
|
+
require 'sensu-plugin/metric/cli'
|
40
|
+
require 'socket'
|
41
|
+
|
42
|
+
#
|
43
|
+
# String
|
44
|
+
# monkeypatch for helping validate PID strings
|
45
|
+
#
|
46
|
+
class String
|
47
|
+
# if its and integer, set it to a string
|
48
|
+
def integer?
|
49
|
+
to_i.to_s == self
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
#
|
54
|
+
# Proc Status
|
55
|
+
#
|
56
|
+
# /proc/[PID]/status memory metrics plugin
|
57
|
+
#
|
58
|
+
class ProcStatus < Sensu::Plugin::Metric::CLI::Graphite
|
59
|
+
option :user,
|
60
|
+
description: 'Query processes owned by a user',
|
61
|
+
short: '-u USER',
|
62
|
+
long: '--user USER'
|
63
|
+
|
64
|
+
option :processname,
|
65
|
+
description: 'Process name substring to match against, not a regex.',
|
66
|
+
short: '-p PROCESSNAME',
|
67
|
+
long: '--process-name PROCESSNAME'
|
68
|
+
|
69
|
+
option :scheme,
|
70
|
+
description: 'Metric naming scheme',
|
71
|
+
long: '--scheme SCHEME',
|
72
|
+
default: "#{Socket.gethostname}.proc"
|
73
|
+
|
74
|
+
option :metrics,
|
75
|
+
description: 'Memory metrics to collect from /proc/[PID]/status, comma-separated',
|
76
|
+
short: '-m METRICS',
|
77
|
+
long: '--metrics METRICS',
|
78
|
+
default: 'VmSize,VmRSS,VmSwap'
|
79
|
+
|
80
|
+
# Build search command
|
81
|
+
#
|
82
|
+
def pgrep_command
|
83
|
+
pgrep_command = 'pgrep '
|
84
|
+
pgrep_command << "-u #{config[:user]} " if config[:user]
|
85
|
+
pgrep_command << "-f #{config[:processname]} " if config[:processname]
|
86
|
+
pgrep_command << '2<&1'
|
87
|
+
end
|
88
|
+
|
89
|
+
# Acquire process_pids
|
90
|
+
#
|
91
|
+
# @param pgrep_output [String]
|
92
|
+
#
|
93
|
+
def acquire_valid_pids(pgrep_output)
|
94
|
+
res = pgrep_output.split("\n").map(&:strip)
|
95
|
+
pids = res.reject { |x| !x.integer? }
|
96
|
+
pids
|
97
|
+
end
|
98
|
+
|
99
|
+
# Acquire the sate for the supplied PID
|
100
|
+
#
|
101
|
+
# @param pid [String]
|
102
|
+
#
|
103
|
+
def acquire_stats_for_pid(pid) # rubocop:disable all
|
104
|
+
return nil unless ::File.exist?(::File.join('/proc', pid, 'cmdline'))
|
105
|
+
|
106
|
+
cmdline_raw = `cat /proc/#{pid}/cmdline`
|
107
|
+
cmdline = cmdline_raw.strip.gsub(/[^[:alnum:]]/, '_')
|
108
|
+
|
109
|
+
metric_names = config[:metrics].split(',')
|
110
|
+
proc_status_lines = `cat /proc/#{pid}/status`.split("\n")
|
111
|
+
|
112
|
+
out = { "#{cmdline}" => {} }
|
113
|
+
|
114
|
+
metric_names.each do |m|
|
115
|
+
line = proc_status_lines.select { |x| /^#{m}/.match(x) }.first # rubocop:disable all
|
116
|
+
val = line ? line.split("\t")[1].to_i : nil
|
117
|
+
out[cmdline.to_s][m] = val
|
118
|
+
end
|
119
|
+
out
|
120
|
+
end
|
121
|
+
|
122
|
+
# Main functino
|
123
|
+
#
|
124
|
+
def run # rubocop:disable all
|
125
|
+
fail 'You must supply -u USER or -p PROCESSNAME' unless config[:user] || config[:processname]
|
126
|
+
metrics = {}
|
127
|
+
pgrep_output = `#{pgrep_command}`
|
128
|
+
pids = acquire_valid_pids(pgrep_output)
|
129
|
+
|
130
|
+
pids.each do |p|
|
131
|
+
data = acquire_stats_for_pid(p)
|
132
|
+
metrics.merge!(data) unless data.nil?
|
133
|
+
end
|
134
|
+
|
135
|
+
timestamp = Time.now.to_i
|
136
|
+
|
137
|
+
metrics.each do |proc_name, stats|
|
138
|
+
stats.each do |stat_name, value|
|
139
|
+
output [config[:scheme], proc_name, stat_name].join('.'), value, timestamp
|
140
|
+
end
|
141
|
+
end
|
142
|
+
ok
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# metric-processes-threads-count.rb
|
4
|
+
#
|
5
|
+
# DESCRIPTION:
|
6
|
+
# Counts the number of processes running on the system (and optionally, the number of running threads) and outputs it in metric format.
|
7
|
+
# Can alternatively count the number of processes/threads matching a certain substring.
|
8
|
+
#
|
9
|
+
# OUTPUT:
|
10
|
+
# metric data
|
11
|
+
#
|
12
|
+
# PLATFORMS:
|
13
|
+
# Linux, Windows
|
14
|
+
#
|
15
|
+
# DEPENDENCIES:
|
16
|
+
# gem: sensu-plugin
|
17
|
+
# gem: sys-proctable
|
18
|
+
#
|
19
|
+
# USAGE:
|
20
|
+
# Pass [-t|--threads] to count the number of running threads in addition to processes.
|
21
|
+
# The check will return an UNKNOWN if the sys-proctable version is not new enough to support counting threads.
|
22
|
+
#
|
23
|
+
# NOTES:
|
24
|
+
# sys-proctable > 0.9.5 is required for counting threads (-t, --threads)
|
25
|
+
#
|
26
|
+
# LICENSE:
|
27
|
+
# Copyright (c) 2015 Contegix LLC
|
28
|
+
# Richard Chatteron richard.chatterton@contegix.com
|
29
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
30
|
+
# for details.
|
31
|
+
#
|
32
|
+
|
33
|
+
require 'sensu-plugin/metric/cli'
|
34
|
+
require 'sys/proctable'
|
35
|
+
|
36
|
+
#
|
37
|
+
# Processes and Threads Count Metrics
|
38
|
+
#
|
39
|
+
class ProcessesThreadsCount < Sensu::Plugin::Metric::CLI::Graphite
|
40
|
+
option :scheme,
|
41
|
+
description: 'Scheme for metric output',
|
42
|
+
short: '-s SCHEME',
|
43
|
+
long: '--scheme SCHEME',
|
44
|
+
default: 'system'
|
45
|
+
|
46
|
+
option :threads,
|
47
|
+
description: 'If specified, count the number of threads running on the system in addition to processes. Note: Requires sys-proctables > 0.9.5',
|
48
|
+
short: '-t',
|
49
|
+
long: '--threads',
|
50
|
+
boolean: true,
|
51
|
+
default: false
|
52
|
+
|
53
|
+
PROCTABLE_MSG = 'sys-proctable version newer than 0.9.5 is required for counting threads with -t or --threads'
|
54
|
+
|
55
|
+
# Exit with an unknown if sys-proctable is not high enough to support counting threads.
|
56
|
+
def check_proctable_version
|
57
|
+
Gem.loaded_specs['sys-proctable'].version > Gem::Version.create('0.9.5')
|
58
|
+
end
|
59
|
+
|
60
|
+
# Takes a value to be tested as an integer. If a new Integer instance cannot be created from it, return 1.
|
61
|
+
# See the comments on get_process_threads() for why 1 is returned.
|
62
|
+
def test_int(i)
|
63
|
+
return Integer(i) rescue return 1
|
64
|
+
end
|
65
|
+
|
66
|
+
# Takes a process struct from Sys::ProcTable.ps() as an argument
|
67
|
+
# Attempts to use the Linux thread count field :nlwp first, then tries the Windows field :thread_count.
|
68
|
+
# Returns the number of processes in those fields.
|
69
|
+
# Otherwise, returns 1 as all processes are assumed to have at least one thread.
|
70
|
+
def get_process_threads(p)
|
71
|
+
if p.respond_to?(:nlwp)
|
72
|
+
return test_int(p.nlwp)
|
73
|
+
elsif p.respond_to?(:thread_count)
|
74
|
+
return test_int(p.thread_count)
|
75
|
+
else
|
76
|
+
return 1
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def count_threads(ps_table)
|
81
|
+
ps_table.reduce(0) do |sum, p|
|
82
|
+
sum + get_process_threads(p)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
# Main function
|
87
|
+
def run # rubocop:disable all
|
88
|
+
if config[:threads]
|
89
|
+
unknown PROCTABLE_MSG unless check_proctable_version
|
90
|
+
end
|
91
|
+
ps_table = Sys::ProcTable.ps
|
92
|
+
processes = ps_table.length
|
93
|
+
threads = count_threads(ps_table) if config[:threads]
|
94
|
+
|
95
|
+
timestamp = Time.now.to_i
|
96
|
+
output "#{[config[:scheme], 'process_count'].join('.')} #{processes} #{timestamp}"
|
97
|
+
if config[:threads]
|
98
|
+
output "#{[config[:scheme], 'thread_count'].join('.')} #{threads} #{timestamp}"
|
99
|
+
end
|
100
|
+
ok
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
|
3
|
+
#Author: Abhishek Jain<abhi111jain@gmail.com
|
4
|
+
|
5
|
+
#This script greps for a process if the process name is specified or looks for the pid file in case the path to the pid file is specified.
|
6
|
+
#If the grep is successful in the former case or the pid file is present with a valid running state in the latter case, a value of 1 is
|
7
|
+
#associated with the metric (<metric_name> <metric value> <timestamp>) format and outputted otherwise a value of 0 is emitted with the same format.
|
8
|
+
#The metric name is constructed based on the scheme prefix specified. If not specified, the hostname is picked as the metric scheme and the metric
|
9
|
+
#name is <hostname>.<process_name>.<uptime>
|
10
|
+
|
11
|
+
#Example run
|
12
|
+
#
|
13
|
+
# process-uptime-metrics.sh -f <path_to_pid_file> -s <scheme like uptime.metrics.hostname.my_process
|
14
|
+
#
|
15
|
+
# The above would emit a line in the following format "uptime.metrics.hostname.uptime.my_process <value(0/1)> <timestamp>"
|
16
|
+
#
|
17
|
+
#Alternatively (using the process name instead of the pid file
|
18
|
+
#
|
19
|
+
# process-uptime-metrics.sh -p my_process -s uptime.metrics.hostname
|
20
|
+
#
|
21
|
+
# Output: "uptime.metrics.hostname.my_process <value(0/1)> <timestamp>"
|
22
|
+
#
|
23
|
+
#
|
24
|
+
|
25
|
+
|
26
|
+
# #RED
|
27
|
+
SCHEME=`hostname`
|
28
|
+
|
29
|
+
usage()
|
30
|
+
{
|
31
|
+
cat <<EOF
|
32
|
+
usage: $0 options
|
33
|
+
|
34
|
+
This plugin produces CPU usage (%)
|
35
|
+
|
36
|
+
OPTIONS:
|
37
|
+
-h Show this message
|
38
|
+
-p PID
|
39
|
+
-f Path to PID file
|
40
|
+
-s Metric naming scheme, text to prepend to cpu.usage (default: $SCHEME)
|
41
|
+
EOF
|
42
|
+
}
|
43
|
+
|
44
|
+
while getopts "hp:f:s:" OPTION
|
45
|
+
do
|
46
|
+
case $OPTION in
|
47
|
+
h)
|
48
|
+
usage
|
49
|
+
exit 1
|
50
|
+
;;
|
51
|
+
p)
|
52
|
+
PROCESS="$OPTARG"
|
53
|
+
;;
|
54
|
+
s)
|
55
|
+
SCHEME="$OPTARG"
|
56
|
+
;;
|
57
|
+
f)
|
58
|
+
PIDFILE="$OPTARG"
|
59
|
+
;;
|
60
|
+
?)
|
61
|
+
usage
|
62
|
+
exit 1
|
63
|
+
;;
|
64
|
+
esac
|
65
|
+
done
|
66
|
+
|
67
|
+
if [ ${PROCESS} ]; then
|
68
|
+
scriptname=`basename $0`
|
69
|
+
SCHEME="${SCHEME}.${PROCESS}"
|
70
|
+
ret=`ps aux | grep "${PROCESS}" | grep -v grep | grep -v $scriptname`
|
71
|
+
if [ ! "${ret}" ]; then
|
72
|
+
echo "$SCHEME.uptime 0 `date +%s`"
|
73
|
+
exit 0
|
74
|
+
fi
|
75
|
+
echo "$SCHEME.uptime 1 `date +%s`"
|
76
|
+
exit 0
|
77
|
+
fi
|
78
|
+
|
79
|
+
if [ ${PIDFILE} ]; then
|
80
|
+
if [ ! -e ${PIDFILE} ]; then
|
81
|
+
echo "$SCHEME.uptime 0 `date +%s`"
|
82
|
+
exit 0
|
83
|
+
fi
|
84
|
+
pid=`cat ${PIDFILE} | tr -d ' '`
|
85
|
+
if [ ! -f /proc/${pid}/status ]; then
|
86
|
+
echo "$SCHEME.uptime 0 `date +%s`"
|
87
|
+
exit 0
|
88
|
+
fi
|
89
|
+
echo "$SCHEME.uptime 1 `date +%s`"
|
90
|
+
exit 0
|
91
|
+
fi
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-process-checks/version'
|
metadata
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cb_sensu_check_processes
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.5
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Sensu-Plugins and contributors
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: english
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.6.3
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.6.3
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sensu-plugin
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 1.2.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 1.2.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sys-proctable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.9.8
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.9.8
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: github-markup
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: pry
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0.10'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0.10'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rake
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '10.0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '10.0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: rspec
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - "~>"
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '3.1'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - "~>"
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '3.1'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: rubocop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0.30'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0.30'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: redcarpet
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - "~>"
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '3.2'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - "~>"
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '3.2'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: yard
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - "~>"
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0.8'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - "~>"
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0.8'
|
181
|
+
description: Sensu plugins for checking running processes
|
182
|
+
email: "<sensu-users@googlegroups.com>"
|
183
|
+
executables:
|
184
|
+
- metrics-process-status.rb
|
185
|
+
- check-cmd.rb
|
186
|
+
- check-process-restart.rb
|
187
|
+
- check-process.rb
|
188
|
+
- check-threads-count.rb
|
189
|
+
- metrics-processes-threads-count.rb
|
190
|
+
extensions: []
|
191
|
+
extra_rdoc_files: []
|
192
|
+
files:
|
193
|
+
- CHANGELOG.md
|
194
|
+
- LICENSE
|
195
|
+
- README.md
|
196
|
+
- bin/check-cmd.rb
|
197
|
+
- bin/check-process-restart.rb
|
198
|
+
- bin/check-process.rb
|
199
|
+
- bin/check-threads-count.rb
|
200
|
+
- bin/metrics-process-status.rb
|
201
|
+
- bin/metrics-processes-threads-count.rb
|
202
|
+
- bin/process-uptime-metrics.sh
|
203
|
+
- lib/sensu-plugins-process-checks.rb
|
204
|
+
- lib/sensu-plugins-process-checks/version.rb
|
205
|
+
homepage: https://github.com/sensu-plugins/sensu-plugins-process-checks
|
206
|
+
licenses:
|
207
|
+
- MIT
|
208
|
+
metadata:
|
209
|
+
maintainer: "@rmc3"
|
210
|
+
development_status: active
|
211
|
+
production_status: unstable - testing recommended
|
212
|
+
release_draft: 'false'
|
213
|
+
release_prerelease: 'false'
|
214
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
215
|
+
in /etc/default/sensu
|
216
|
+
rdoc_options: []
|
217
|
+
require_paths:
|
218
|
+
- lib
|
219
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
220
|
+
requirements:
|
221
|
+
- - ">="
|
222
|
+
- !ruby/object:Gem::Version
|
223
|
+
version: 1.9.3
|
224
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
225
|
+
requirements:
|
226
|
+
- - ">="
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
requirements: []
|
230
|
+
rubyforge_project:
|
231
|
+
rubygems_version: 2.4.3
|
232
|
+
signing_key:
|
233
|
+
specification_version: 4
|
234
|
+
summary: Sensu plugins for checking running processes
|
235
|
+
test_files: []
|
236
|
+
has_rdoc:
|