Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support TASK_IDLE process status. Include IDLE process in UNINTERRUPTIBLE metric for backward compatibility. Add new option to separate out metric if desired #66

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugins


## [Unreleased]
### Fixed
- metrics-processes-threads-count.rb: Backward compatible support for TASK_IDLE process state in Linux 4.14+ (@awangptc)

### Added
- metrics-processes-threads-count.rb: Add option to separate out TASK_IDLE process into it's own metric (@awangptc)


## [3.1.0] - 2018-05-02
### Added
Expand Down
16 changes: 15 additions & 1 deletion bin/metrics-processes-threads-count.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ class ProcessesThreadsCount < Sensu::Plugin::Metric::CLI::Graphite
boolean: true,
default: false

option :idle_state,
description: 'If specified, count TASK_IDLE (I) state in separate .idle metric. Note: TASK_IDLE is only available on Linux Kernels 4.14 and higher',
short: '-I',
long: '--idle-state',
boolean: true,
default: false

# Takes a value to be tested as an integer. If a new Integer instance cannot be created from it, return 1.
# See the comments on get_process_threads() for why 1 is returned.
def test_int(i)
Expand Down Expand Up @@ -95,9 +102,14 @@ def count_processes_by_status(ps_table)
%w[S R D T t X Z].each do |v|
list_proc[v] = 0
end
list_proc['I'] = 0 if config[:idle_state]
if ps_table.first.respond_to?(:state)
ps_table.each do |pr|
list_proc[pr[:state]] += 1
state = pr[:state]
if state == 'I'
state = 'D' unless config[:idle_state]
end
list_proc[state] += 1
end
end
list_proc
Expand Down Expand Up @@ -131,6 +143,8 @@ def run
output "#{[config[:scheme], 'dead'].join('.')} #{proc_count} #{timestamp}"
when 'Z'
output "#{[config[:scheme], 'zombie'].join('.')} #{proc_count} #{timestamp}"
when 'I'
output "#{[config[:scheme], 'idle'].join('.')} #{proc_count} #{timestamp}"
end
end
end
Expand Down
24 changes: 24 additions & 0 deletions test/metrics-processes-threads-count_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,30 @@
ptcount = ProcessesThreadsCount.new
expect(ptcount.count_threads(table)).to eq(10)
end

it 'should be able to count processes in each state - count I toward D for 4.14+ kernels' do
states = %w[S R D T t X Z I]
ps_entry = Struct.new(:state)
table = states.map { |state| ps_entry.new(state) }
ptcount = ProcessesThreadsCount.new
counts = ptcount.count_processes_by_status(table)
states.each do |state|
expect(counts[state]).to eq(2) if state == 'D'
expect(counts[state]).to be_nil if state == 'I'
end
end

it 'should be able to count processes in each state with :idle_state enabled - count I separate' do
states = %w[S R D T t X Z I]
ps_entry = Struct.new(:state)
table = states.map { |state| ps_entry.new(state) }
ptcount = ProcessesThreadsCount.new
ptcount.config[:idle_state] = true
counts = ptcount.count_processes_by_status(table)
states.each do |state|
expect(counts[state]).to eq(1)
end
end
end

describe ThreadsCount, 'run' do
Expand Down