sensu-plugins-process-count-metrics 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 0b66e5bd813feb25a73ada15d00f37351fc25375
4
+ data.tar.gz: '0787fa33c1c60d699321f9482e755029d9c754ea'
5
+ SHA512:
6
+ metadata.gz: 49559d3aa8160d95681b23c7974e7d653164cefee43a049fdd3200709dbcbb29e194334e6d15b33d6461061a5490ae268e6a1a55c8454bf52d5e6a843de662b9
7
+ data.tar.gz: 8674ce407dcbe97489dfadf5e0b24c046f2d582b34ad4f747128c93030643334e10ee9fb6c8fc8359544acf8a31306af38d0fd16f9584cab769b7fc15ab388de
data/README.md ADDED
@@ -0,0 +1,20 @@
1
+ Sensu Plugins Process Count Metrics
2
+ ====================================
3
+
4
+ [![Build Status](https://travis-ci.org/ElvenSpellmaker/sensu-plugins-process-count-metrics.svg?branch=master)](https://travis-ci.org/ElvenSpellmaker/sensu-plugins-process-count-metrics) [![Gem Version](https://badge.fury.io/rb/sensu-plugins-process-count-metrics.svg)](https://badge.fury.io/rb/sensu-plugins-process-count-metrics)
5
+
6
+ This is a Sensu Plug-in to interface with `pgrep` and count the number of
7
+ processes with a given name as metrics.
8
+
9
+ Supply `-f` to use `-f` in `pgrep`.
10
+
11
+ This plug-in will ignore itself in the process list.
12
+
13
+ Tested on Ruby 2.3.
14
+
15
+ The unit tests are a bit dubious as they run the Ruby file externally as it's
16
+ almost impossible to run unit tests on a Sensu plug-in because they run as soon
17
+ as scoped...
18
+ The tests must be run from the project root directory.
19
+
20
+ `bundle exec rspec` should run the test, after bundle installing of course.
@@ -0,0 +1,53 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ require 'sensu-plugin/metric/cli'
4
+ require 'time'
5
+ require 'open3'
6
+
7
+ class CountCpuMetrics < Sensu::Plugin::Metric::CLI::Graphite
8
+ option :scheme,
9
+ description: 'Metric naming scheme, text to prepend to metric',
10
+ short: '-s SCHEME',
11
+ long: '--scheme SCHEME',
12
+ default: 'sensu'
13
+
14
+ option :process_name,
15
+ description: 'The process part(s) to `pgrep` for',
16
+ short: '-p',
17
+ long: '--pgrep-name Process Name',
18
+ default: nil
19
+
20
+ option :full_check,
21
+ description: 'Whether to check the full process string, or just the name',
22
+ short: '-f',
23
+ long: '--full-check',
24
+ boolean: true
25
+
26
+ def run
27
+ time = Time.now.utc.to_i
28
+
29
+ process_name = config[:process_name]
30
+
31
+ full_command = config[:full_check] ? ['-f', process_name] : [process_name]
32
+
33
+ if (process_name).to_s.empty?
34
+ critical '`process_name`/`p` shouldn\'t be empty!'
35
+ end
36
+
37
+ metric, err, status = Open3.capture3('pgrep', *full_command)
38
+
39
+ critical "Failed to `pgrep` with message: #{err}" if ! [0, 1].include?(status.exitstatus)
40
+
41
+ # We need to count up here, and remove the Ruby process from pgrep's result
42
+ # if present, hence not using `-c`.
43
+ count = 0
44
+ process_number = Process.pid.to_s
45
+ metric.each_line do |line|
46
+ count += 1 unless line.chomp == process_number
47
+ end
48
+
49
+ output [config[:scheme], 'process_count', process_name, 'count'].join('.'), count, time
50
+
51
+ ok
52
+ end
53
+ end
@@ -0,0 +1,9 @@
1
+ module SensuPluginsProcessCountMetrics
2
+ class Version
3
+ MAJOR = 0
4
+ MINOR = 0
5
+ PATCH = 1
6
+
7
+ VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-plugins-process-count-metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jack
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-plugin
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ description: A Sensu plug-in to provide count metrics for processes
42
+ email:
43
+ executables:
44
+ - sensu-plugins-process-count-metrics.rb
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - README.md
49
+ - bin/sensu-plugins-process-count-metrics.rb
50
+ - lib/sensu-plugins-process-count-metrics/version.rb
51
+ homepage: https://github.com/ElvenSpellmaker/sensu-plugins-process-count-metrics
52
+ licenses:
53
+ - MIT
54
+ metadata:
55
+ maintainer: "@ElvenSpellmaker"
56
+ development_status: active
57
+ production_status: unstable - testing recommended
58
+ release_draft: 'false'
59
+ release_prerelease: 'false'
60
+ post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
61
+ in /etc/default/sensu
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '2.3'
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ requirements: []
76
+ rubyforge_project:
77
+ rubygems_version: 2.6.8
78
+ signing_key:
79
+ specification_version: 4
80
+ summary: Sensu plug-in to provide count metrics for processes
81
+ test_files: []