sensu-plugins-process-checks 2.6.0 → 2.7.0
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 +4 -4
- data/CHANGELOG.md +6 -1
- data/bin/metrics-per-process.py +50 -15
- data/lib/sensu-plugins-process-checks/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 876caee1acc9312011319211530a65c0277ba8827397e5b0efb1855417e95f64
|
4
|
+
data.tar.gz: 7d353e6e88a47b7d9edb50586f08e4569a2b4ebe578df3a91ececdf5c9cb01fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e9cb951943643d96a22cd791b742db5dc7c5b1540a966373597149fabd365e5ae3e4fdbcf4a36844def13ce0a6c85106afef2bab9fb302eaba226b717e00743a
|
7
|
+
data.tar.gz: 8a07af4a8bc3eacb1b8ed6829a08db70cdc392cdc8e25bdf7bcbcf4460d6971ab451fdb048f40ef0cbe8b9308872930822ebb339a19fd9979f3d9ff9ea2691df
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [2.7.0] - 2018-01-06
|
10
|
+
### Changed
|
11
|
+
- metrics-per-processes.py: Add option to find processes by username (@rthouvenin)
|
12
|
+
|
9
13
|
## [2.6.0] - 2017-12-05
|
10
14
|
### Changed
|
11
15
|
- loosen dependency of `sys-proctable` (@majormoses)
|
@@ -156,7 +160,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins
|
|
156
160
|
- built against 1.9.3, 2.0, 2.1
|
157
161
|
- cryptographically signed
|
158
162
|
|
159
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.
|
163
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.7.0...HEAD
|
164
|
+
[2.7.0]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.6.0...2.7.0
|
160
165
|
[2.6.0]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.5.0...2.6.0
|
161
166
|
[2.5.0]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.4.0...2.5.0
|
162
167
|
[2.4.0]: https://github.com/sensu-plugins/sensu-plugins-process-checks/compare/2.3.0...2.4.0
|
data/bin/metrics-per-process.py
CHANGED
@@ -16,7 +16,7 @@
|
|
16
16
|
#
|
17
17
|
# USAGE:
|
18
18
|
#
|
19
|
-
# metrics-per-process.py -n <process_name> | -p <path_to_process_pid_file> [-s <graphite_scheme>] [-m <metrics_regexes>]
|
19
|
+
# metrics-per-process.py -n <process_name> | -p <path_to_process_pid_file> | -u <username> [-s <graphite_scheme>] [-m <metrics_regexes>]
|
20
20
|
#
|
21
21
|
# NOTES:
|
22
22
|
# The plugin requires to read files in the /proc file system, make sure the owner
|
@@ -66,6 +66,7 @@
|
|
66
66
|
import os
|
67
67
|
import optparse
|
68
68
|
import psutil
|
69
|
+
import pwd
|
69
70
|
import re
|
70
71
|
import sys
|
71
72
|
import time
|
@@ -92,23 +93,46 @@ TCP_CONN_STATUSES = [
|
|
92
93
|
]
|
93
94
|
MEMORY_STATS = ['rss', 'vms', 'shared', 'text', 'lib', 'data', 'dirty']
|
94
95
|
|
95
|
-
def
|
96
|
-
'''Find process PID
|
96
|
+
def find_pids(matcher):
|
97
|
+
'''Find process PID using /proc/<pids> with given matcher'''
|
97
98
|
|
98
99
|
pids_in_proc = [ pid for pid in os.listdir(PROC_ROOT_DIR) if pid.isdigit() ]
|
99
100
|
pids = []
|
100
101
|
for pid in pids_in_proc:
|
101
102
|
path = PROC_ROOT_DIR + pid
|
102
103
|
try:
|
103
|
-
|
104
|
-
|
105
|
-
if file_handler.read().rstrip() == process_name:
|
106
|
-
pids.append(int(pid))
|
104
|
+
if matcher(path):
|
105
|
+
pids.append(int(pid))
|
107
106
|
except OSError, e:
|
108
|
-
|
109
|
-
|
107
|
+
if e.errno == 2:
|
108
|
+
pass
|
110
109
|
return pids
|
111
110
|
|
111
|
+
def find_pids_from_name(process_name):
|
112
|
+
'''Find process PID from name using /proc/<pids>/comm'''
|
113
|
+
|
114
|
+
def matcher(path):
|
115
|
+
if 'comm' in os.listdir(path):
|
116
|
+
file_handler = open(path + '/comm', 'r')
|
117
|
+
return file_handler.read().rstrip() == process_name
|
118
|
+
|
119
|
+
return find_pids(matcher)
|
120
|
+
|
121
|
+
def find_pids_from_user(username):
|
122
|
+
'''Find process PID from username using ownership of /proc/<pids>'''
|
123
|
+
|
124
|
+
try:
|
125
|
+
user = pwd.getpwnam(username)
|
126
|
+
uid = user.pw_uid
|
127
|
+
except KeyError:
|
128
|
+
return []
|
129
|
+
|
130
|
+
def matcher(path):
|
131
|
+
stat = os.stat(path)
|
132
|
+
return stat.st_uid == uid
|
133
|
+
|
134
|
+
return find_pids(matcher)
|
135
|
+
|
112
136
|
def additional_stats(process_handler, metrics_regexp):
|
113
137
|
stats = {}
|
114
138
|
|
@@ -250,15 +274,20 @@ def main():
|
|
250
274
|
parser = optparse.OptionParser()
|
251
275
|
|
252
276
|
parser.add_option('-n', '--process-name',
|
253
|
-
help = 'name of process to collect stats (imcompatible with -p)',
|
277
|
+
help = 'name of process to collect stats (imcompatible with -p or -u)',
|
254
278
|
dest = 'process_name',
|
255
279
|
metavar = 'PROCESS_NAME')
|
256
280
|
|
257
281
|
parser.add_option('-p', '--pid-file',
|
258
|
-
help = 'path to pid file for process to collect stats (imcompatible with -n)',
|
282
|
+
help = 'path to pid file for process to collect stats (imcompatible with -n or -u)',
|
259
283
|
dest = 'process_pid_file',
|
260
284
|
metavar = 'PROCESS_PID_FILE')
|
261
285
|
|
286
|
+
parser.add_option('-u', '--user',
|
287
|
+
help = 'username of user running the process to collect stats (incompatible with -n or -p)',
|
288
|
+
dest = 'username',
|
289
|
+
metavar = 'USERNAME')
|
290
|
+
|
262
291
|
parser.add_option('-s', '--graphite_scheme',
|
263
292
|
help = 'graphite scheme to prepend, default to <process_stats>',
|
264
293
|
default = 'per_process_stats',
|
@@ -272,13 +301,15 @@ def main():
|
|
272
301
|
metavar = 'METRICS_REGEXES')
|
273
302
|
|
274
303
|
(options, args) = parser.parse_args()
|
304
|
+
options_list = [options.process_name, options.process_pid_file, options.username]
|
305
|
+
options_count = len(filter(lambda x: x is not None, options_list))
|
275
306
|
|
276
|
-
if
|
277
|
-
print 'Specify a process name or a process pid file path, but
|
307
|
+
if options_count > 1:
|
308
|
+
print 'Specify a process name or a process pid file path or username, but only one of them'
|
278
309
|
sys.exit(1)
|
279
310
|
|
280
|
-
if
|
281
|
-
print 'A process name or a process pid file path is needed'
|
311
|
+
if options_count == 0:
|
312
|
+
print 'A process name or a process pid file path or username is needed'
|
282
313
|
sys.exit(1)
|
283
314
|
|
284
315
|
options.metrics_regexes = [re.compile(regex) for regex in options.metrics_regexes.split(',')]
|
@@ -287,6 +318,10 @@ def main():
|
|
287
318
|
pids = find_pids_from_name(options.process_name)
|
288
319
|
graphite_printer(multi_pid_process_stats(pids, options.metrics_regexes), options.graphite_scheme)
|
289
320
|
|
321
|
+
if options.username:
|
322
|
+
pids = find_pids_from_user(options.username)
|
323
|
+
graphite_printer(multi_pid_process_stats(pids, options.metrics_regexes), options.graphite_scheme)
|
324
|
+
|
290
325
|
if options.process_pid_file:
|
291
326
|
pid = get_pid_from_pid_file(options.process_pid_file)
|
292
327
|
graphite_printer(stats_per_pid(pid, options.metrics_regexes), options.graphite_scheme)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-process-checks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: english
|
@@ -236,7 +236,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
236
236
|
version: '0'
|
237
237
|
requirements: []
|
238
238
|
rubyforge_project:
|
239
|
-
rubygems_version: 2.7.
|
239
|
+
rubygems_version: 2.7.4
|
240
240
|
signing_key:
|
241
241
|
specification_version: 4
|
242
242
|
summary: Sensu plugins for checking running processes
|