sensu-plugins-process-checks 0.0.1.alpha.2 → 0.0.1.alpha.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/CHANGELOG.md +15 -0
- data/README.md +35 -14
- data/bin/check-process.sh +71 -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.rb +1 -1
- metadata +72 -35
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c33b9fc64bd6ef7dfa512988334f3c9d320a5770
|
4
|
+
data.tar.gz: 0f937fadbbb52ec37eee8467474f787c333c1821
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 372171c107cb89791fccb0b775badd782256ab54a063a62856025b97b9e5bfa36963d2c2bde1d6a0c56f3badea0cfaa1e929545204df350a07048a5e91a871f4
|
7
|
+
data.tar.gz: 80935bf4f7b9129c01c9e3c473dd92d4322f0afbb908f87d44bb4e62aa79eb6f0614959276f0e196f3d071355a5a65ad007940a17e2f625138b7b6e9982252ac
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -14,3 +14,18 @@
|
|
14
14
|
* update README
|
15
15
|
* add required Ruby version *>= 1.9.3*
|
16
16
|
* add test/spec_help.rb
|
17
|
+
|
18
|
+
#### 0.0.1-alpha.3
|
19
|
+
|
20
|
+
* add proc-status-metrics
|
21
|
+
* change proc-status-metrics to process-status-metrics
|
22
|
+
|
23
|
+
#### 0.0.1.alpha.4
|
24
|
+
|
25
|
+
* convert scrips to sys-proctable gem for platform independence
|
26
|
+
|
27
|
+
#### 0.0.1.alpha.5
|
28
|
+
|
29
|
+
* add new check for process uptime metrics
|
30
|
+
|
31
|
+
|
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
[![
|
4
|
-
[![
|
5
|
-
[![
|
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)
|
1
|
+
[![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-process-checks.svg?branch=master)][1]
|
2
|
+
[![Gem Version](https://badge.fury.io/rb/sensu-plugins-process-checks.svg)][2]
|
3
|
+
[![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks/badges/gpa.svg)][3]
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks/badges/coverage.svg)][4]
|
5
|
+
[![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-process-checks.svg)][5]
|
7
6
|
|
8
7
|
## Functionality
|
9
8
|
|
@@ -15,20 +14,42 @@
|
|
15
14
|
* bin/check-cmd.rb
|
16
15
|
* bin/check-process-restart.rb
|
17
16
|
* bin/check-process.rb
|
17
|
+
* bin/check-process.sh
|
18
|
+
* bin/metrics-process-status
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
#### Rubygems
|
23
|
+
|
24
|
+
`gem install sensu-plugins-process-checks`
|
25
|
+
|
26
|
+
#### Bundler
|
18
27
|
|
19
|
-
|
28
|
+
Add *sensu-plugins-disk-checks* to your Gemfile and run `bundle install` or `bundle update`
|
20
29
|
|
21
|
-
|
30
|
+
#### Chef
|
22
31
|
|
32
|
+
Using the Sensu **sensu_gem** LWRP
|
23
33
|
```
|
24
|
-
|
25
|
-
|
34
|
+
sensu_gem 'sensu-plugins-process-checks' do
|
35
|
+
options('--prerelease')
|
36
|
+
version '0.0.1.alpha.4'
|
37
|
+
end
|
26
38
|
```
|
27
39
|
|
28
|
-
|
40
|
+
Using the Chef **gem_package** resource
|
41
|
+
```
|
42
|
+
gem_package 'sensu-plugins-process-checks' do
|
43
|
+
options('--prerelease')
|
44
|
+
version '0.0.1.alpha.4'
|
45
|
+
end
|
46
|
+
```
|
29
47
|
|
30
|
-
|
48
|
+
## Notes
|
31
49
|
|
32
|
-
Add *sensu-plugins-process-checks* to your Gemfile, manifest, cookbook, etc
|
33
50
|
|
34
|
-
|
51
|
+
[1]:[https://travis-ci.org/sensu-plugins/sensu-plugins-process-checks]
|
52
|
+
[2]:[http://badge.fury.io/rb/sensu-plugins-process-checks]
|
53
|
+
[3]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks]
|
54
|
+
[4]:[https://codeclimate.com/github/sensu-plugins/sensu-plugins-process-checks]
|
55
|
+
[5]:[https://gemnasium.com/sensu-plugins/sensu-plugins-process-checks]
|
@@ -0,0 +1,71 @@
|
|
1
|
+
#!/bin/bash
|
2
|
+
#
|
3
|
+
# Check process
|
4
|
+
#
|
5
|
+
# ===
|
6
|
+
#
|
7
|
+
# Examples:
|
8
|
+
#
|
9
|
+
# # check by process name
|
10
|
+
# check-process.sh -p nginx
|
11
|
+
#
|
12
|
+
# # check by PID file
|
13
|
+
# check-process.sh -f /var/spool/postfix/pid/master.pid
|
14
|
+
#
|
15
|
+
# Date: 2014-09-12
|
16
|
+
# Author: Jun Ichikawa <jun1ka0@gmail.com>
|
17
|
+
#
|
18
|
+
# Released under the same terms as Sensu (the MIT license); see LICENSE
|
19
|
+
# for details.
|
20
|
+
|
21
|
+
# get arguments
|
22
|
+
while getopts 'p:f:h' OPT; do
|
23
|
+
case $OPT in
|
24
|
+
p) PROCESS=$OPTARG;;
|
25
|
+
f) PID_FILE=$OPTARG;;
|
26
|
+
h) hlp="yes";;
|
27
|
+
*) unknown="yes";;
|
28
|
+
esac
|
29
|
+
done
|
30
|
+
|
31
|
+
# usage
|
32
|
+
HELP="
|
33
|
+
usage: $0 [ -p value -f value -h ]
|
34
|
+
|
35
|
+
-p --> process name
|
36
|
+
-f --> file path to pid file
|
37
|
+
-h --> print this help screen
|
38
|
+
"
|
39
|
+
|
40
|
+
if [ "$hlp" = "yes" ]; then
|
41
|
+
echo "$HELP"
|
42
|
+
exit 0
|
43
|
+
fi
|
44
|
+
|
45
|
+
if [ ${PROCESS} ]; then
|
46
|
+
scriptname=`basename $0`
|
47
|
+
ret=`ps aux | grep "${PROCESS}" | grep -v grep | grep -v $scriptname`
|
48
|
+
if [ ! "${ret}" ]; then
|
49
|
+
echo "CRITICAL - process ${PROCESS} does not exist"
|
50
|
+
exit 2
|
51
|
+
fi
|
52
|
+
echo "PROCESS OK - ${PROCESS}"
|
53
|
+
exit 0
|
54
|
+
fi
|
55
|
+
|
56
|
+
if [ ${PID_FILE} ]; then
|
57
|
+
if [ ! -e ${PID_FILE} ]; then
|
58
|
+
echo "CRITICAL - PID file ${PID_FILE} does not exist"
|
59
|
+
exit 2
|
60
|
+
fi
|
61
|
+
pid=`cat ${PID_FILE} | tr -d ' '`
|
62
|
+
if [ ! -f /proc/${pid}/status ]; then
|
63
|
+
echo "CRITICAL - status of ${PID_FILE} not found"
|
64
|
+
exit 2
|
65
|
+
fi
|
66
|
+
echo "PROCESS OK - ${PID_FILE}"
|
67
|
+
exit 0
|
68
|
+
fi
|
69
|
+
|
70
|
+
echo "$HELP"
|
71
|
+
exit 2
|
@@ -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
|
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)
|
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
|
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
|
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
|
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
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-process-checks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1.alpha.
|
4
|
+
version: 0.0.1.alpha.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
- Yieldbot, Inc
|
7
|
+
- Yieldbot, Inc. and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
|
31
31
|
HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2015-
|
33
|
+
date: 2015-03-06 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: english
|
@@ -74,134 +74,172 @@ dependencies:
|
|
74
74
|
- - '='
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: 1.8.2
|
77
|
+
- !ruby/object:Gem::Dependency
|
78
|
+
name: sys-proctable
|
79
|
+
requirement: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - '='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: 0.9.6
|
84
|
+
type: :runtime
|
85
|
+
prerelease: false
|
86
|
+
version_requirements: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 0.9.6
|
77
91
|
- !ruby/object:Gem::Dependency
|
78
92
|
name: codeclimate-test-reporter
|
79
93
|
requirement: !ruby/object:Gem::Requirement
|
80
94
|
requirements:
|
81
|
-
- -
|
95
|
+
- - ">="
|
82
96
|
- !ruby/object:Gem::Version
|
83
97
|
version: '0'
|
84
98
|
type: :development
|
85
99
|
prerelease: false
|
86
100
|
version_requirements: !ruby/object:Gem::Requirement
|
87
101
|
requirements:
|
88
|
-
- -
|
102
|
+
- - ">="
|
89
103
|
- !ruby/object:Gem::Version
|
90
104
|
version: '0'
|
91
105
|
- !ruby/object:Gem::Dependency
|
92
106
|
name: rubocop
|
93
107
|
requirement: !ruby/object:Gem::Requirement
|
94
108
|
requirements:
|
95
|
-
- - ~>
|
109
|
+
- - "~>"
|
96
110
|
- !ruby/object:Gem::Version
|
97
|
-
version: 0.17
|
111
|
+
version: '0.17'
|
98
112
|
type: :development
|
99
113
|
prerelease: false
|
100
114
|
version_requirements: !ruby/object:Gem::Requirement
|
101
115
|
requirements:
|
102
|
-
- - ~>
|
116
|
+
- - "~>"
|
103
117
|
- !ruby/object:Gem::Version
|
104
|
-
version: 0.17
|
118
|
+
version: '0.17'
|
105
119
|
- !ruby/object:Gem::Dependency
|
106
120
|
name: rspec
|
107
121
|
requirement: !ruby/object:Gem::Requirement
|
108
122
|
requirements:
|
109
|
-
- - ~>
|
123
|
+
- - "~>"
|
110
124
|
- !ruby/object:Gem::Version
|
111
125
|
version: '3.1'
|
112
126
|
type: :development
|
113
127
|
prerelease: false
|
114
128
|
version_requirements: !ruby/object:Gem::Requirement
|
115
129
|
requirements:
|
116
|
-
- - ~>
|
130
|
+
- - "~>"
|
117
131
|
- !ruby/object:Gem::Version
|
118
132
|
version: '3.1'
|
119
133
|
- !ruby/object:Gem::Dependency
|
120
134
|
name: bundler
|
121
135
|
requirement: !ruby/object:Gem::Requirement
|
122
136
|
requirements:
|
123
|
-
- - ~>
|
137
|
+
- - "~>"
|
124
138
|
- !ruby/object:Gem::Version
|
125
139
|
version: '1.7'
|
126
140
|
type: :development
|
127
141
|
prerelease: false
|
128
142
|
version_requirements: !ruby/object:Gem::Requirement
|
129
143
|
requirements:
|
130
|
-
- - ~>
|
144
|
+
- - "~>"
|
131
145
|
- !ruby/object:Gem::Version
|
132
146
|
version: '1.7'
|
133
147
|
- !ruby/object:Gem::Dependency
|
134
148
|
name: rake
|
135
149
|
requirement: !ruby/object:Gem::Requirement
|
136
150
|
requirements:
|
137
|
-
- - ~>
|
151
|
+
- - "~>"
|
138
152
|
- !ruby/object:Gem::Version
|
139
153
|
version: '10.0'
|
140
154
|
type: :development
|
141
155
|
prerelease: false
|
142
156
|
version_requirements: !ruby/object:Gem::Requirement
|
143
157
|
requirements:
|
144
|
-
- - ~>
|
158
|
+
- - "~>"
|
145
159
|
- !ruby/object:Gem::Version
|
146
160
|
version: '10.0'
|
147
161
|
- !ruby/object:Gem::Dependency
|
148
162
|
name: github-markup
|
149
163
|
requirement: !ruby/object:Gem::Requirement
|
150
164
|
requirements:
|
151
|
-
- -
|
165
|
+
- - "~>"
|
152
166
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
167
|
+
version: '1.3'
|
154
168
|
type: :development
|
155
169
|
prerelease: false
|
156
170
|
version_requirements: !ruby/object:Gem::Requirement
|
157
171
|
requirements:
|
158
|
-
- -
|
172
|
+
- - "~>"
|
159
173
|
- !ruby/object:Gem::Version
|
160
|
-
version: '
|
174
|
+
version: '1.3'
|
161
175
|
- !ruby/object:Gem::Dependency
|
162
176
|
name: redcarpet
|
163
177
|
requirement: !ruby/object:Gem::Requirement
|
164
178
|
requirements:
|
165
|
-
- -
|
179
|
+
- - "~>"
|
166
180
|
- !ruby/object:Gem::Version
|
167
|
-
version: '
|
181
|
+
version: '3.2'
|
168
182
|
type: :development
|
169
183
|
prerelease: false
|
170
184
|
version_requirements: !ruby/object:Gem::Requirement
|
171
185
|
requirements:
|
172
|
-
- -
|
186
|
+
- - "~>"
|
173
187
|
- !ruby/object:Gem::Version
|
174
|
-
version: '
|
188
|
+
version: '3.2'
|
175
189
|
- !ruby/object:Gem::Dependency
|
176
190
|
name: yard
|
177
191
|
requirement: !ruby/object:Gem::Requirement
|
178
192
|
requirements:
|
179
|
-
- -
|
193
|
+
- - "~>"
|
180
194
|
- !ruby/object:Gem::Version
|
181
|
-
version: '0'
|
195
|
+
version: '0.8'
|
182
196
|
type: :development
|
183
197
|
prerelease: false
|
184
198
|
version_requirements: !ruby/object:Gem::Requirement
|
185
199
|
requirements:
|
186
|
-
- -
|
200
|
+
- - "~>"
|
187
201
|
- !ruby/object:Gem::Version
|
188
|
-
version: '0'
|
202
|
+
version: '0.8'
|
203
|
+
- !ruby/object:Gem::Dependency
|
204
|
+
name: pry
|
205
|
+
requirement: !ruby/object:Gem::Requirement
|
206
|
+
requirements:
|
207
|
+
- - "~>"
|
208
|
+
- !ruby/object:Gem::Version
|
209
|
+
version: '0.10'
|
210
|
+
type: :development
|
211
|
+
prerelease: false
|
212
|
+
version_requirements: !ruby/object:Gem::Requirement
|
213
|
+
requirements:
|
214
|
+
- - "~>"
|
215
|
+
- !ruby/object:Gem::Version
|
216
|
+
version: '0.10'
|
189
217
|
description: Sensu process checks
|
190
|
-
email: <sensu-users@googlegroups.com>
|
218
|
+
email: "<sensu-users@googlegroups.com>"
|
191
219
|
executables:
|
192
220
|
- check-cmd.rb
|
193
221
|
- check-process-restart.rb
|
194
222
|
- check-process.rb
|
223
|
+
- check-process.sh
|
224
|
+
- check-threads-count.rb
|
225
|
+
- metrics-process-status.rb
|
226
|
+
- metrics-processes-threads-count.rb
|
227
|
+
- process-uptime-metrics.sh
|
195
228
|
extensions: []
|
196
229
|
extra_rdoc_files: []
|
197
230
|
files:
|
231
|
+
- CHANGELOG.md
|
232
|
+
- LICENSE
|
233
|
+
- README.md
|
198
234
|
- bin/check-cmd.rb
|
199
235
|
- bin/check-process-restart.rb
|
200
236
|
- bin/check-process.rb
|
237
|
+
- bin/check-process.sh
|
238
|
+
- bin/check-threads-count.rb
|
239
|
+
- bin/metrics-process-status.rb
|
240
|
+
- bin/metrics-processes-threads-count.rb
|
241
|
+
- bin/process-uptime-metrics.sh
|
201
242
|
- lib/sensu-plugins-process-checks.rb
|
202
|
-
- LICENSE
|
203
|
-
- README.md
|
204
|
-
- CHANGELOG.md
|
205
243
|
homepage: https://github.com/sensu-plugins/sensu-plugins-process-checks
|
206
244
|
licenses:
|
207
245
|
- MIT
|
@@ -212,19 +250,18 @@ require_paths:
|
|
212
250
|
- lib
|
213
251
|
required_ruby_version: !ruby/object:Gem::Requirement
|
214
252
|
requirements:
|
215
|
-
- -
|
253
|
+
- - ">="
|
216
254
|
- !ruby/object:Gem::Version
|
217
255
|
version: 1.9.3
|
218
256
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
257
|
requirements:
|
220
|
-
- -
|
258
|
+
- - ">"
|
221
259
|
- !ruby/object:Gem::Version
|
222
260
|
version: 1.3.1
|
223
261
|
requirements: []
|
224
262
|
rubyforge_project:
|
225
|
-
rubygems_version: 2.
|
263
|
+
rubygems_version: 2.2.2
|
226
264
|
signing_key:
|
227
265
|
specification_version: 4
|
228
266
|
summary: Sensu process checks
|
229
267
|
test_files: []
|
230
|
-
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|