fluent-plugin-proc_count 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 65cf9683795c5e95e8930157f62738313453df9f
4
- data.tar.gz: 0a20921c1ddb7c8ad1a572e6e2d2829b29b0b760
3
+ metadata.gz: 87e0030594a618600414b01345d83440eb16f7a2
4
+ data.tar.gz: 7b2bae56a1d04b2e4f3fe24b5cd65cbe9d053459
5
5
  SHA512:
6
- metadata.gz: 4faf563de09bd3560d12e9d27fa16c3024353ce6d30c5b54915d320419b194f848c509c845ddb2b6de63f5fe3e7248063b3029267a2b04081b0280916e12a529
7
- data.tar.gz: cd0242d1f8e3cabf384f0fc15d7a660d391ca294e82f4a94fdd1005c5b0eeb5d3f5e5dd6518c36b4ed83b144f5cea8c715b71a8fa0dcaab81cbb4e8448a05e62
6
+ metadata.gz: 1be406576b5d193951f9942a7c1788ab0b8ed319dfe5b1aa52f0fd8bb3d69b0fc054f641507cab94c4b394b404740f9faa4fdc49e643391ef638c5cd8f3c2984
7
+ data.tar.gz: bf1cdc126d71d13ee7f7f9828d3ca44621ca103560cd81ed4617bc9866a68328bce4278a4264ac41988cb8d61049ff0f3be358238a56812c5f427506ce95a141
@@ -1,13 +1,12 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 1.9.3
5
- - 2.0.0
6
- - 2.1
7
-
4
+ - 2.1.*
5
+ - 2.2.*
6
+ - 2.3.2
7
+ - 2.4.1
8
8
  os:
9
9
  - linux
10
- - osx
11
10
 
12
11
  gemfile:
13
12
  - Gemfile
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # fluent-plugin-proc_count
2
+ [![Gem Version](https://badge.fury.io/rb/fluent-plugin-proc_count.svg)](http://badge.fury.io/rb/fluent-plugin-proc_count)
3
+ [![Build Status](https://secure.travis-ci.org/toyama0919/fluent-plugin-proc_count.png?branch=master)](http://travis-ci.org/toyama0919/fluent-plugin-proc_count)
2
4
 
3
5
  process count check plugin for fluentd
4
6
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "fluent-plugin-proc_count"
5
- gem.version = "0.0.1"
5
+ gem.version = "0.0.2"
6
6
  gem.summary = %q{process count check plugin for fluentd.}
7
7
  gem.description = %q{process count check plugin for fluentd.}
8
8
  gem.license = "MIT"
@@ -24,5 +24,6 @@ Gem::Specification.new do |gem|
24
24
  gem.add_development_dependency 'rake'
25
25
  gem.add_development_dependency 'rubocop'
26
26
  gem.add_development_dependency 'rubygems-tasks'
27
+ gem.add_development_dependency 'test-unit'
27
28
  gem.add_development_dependency 'yard'
28
29
  end
@@ -1,3 +1,4 @@
1
+ require 'fluent/input'
1
2
  require 'sys/proctable'
2
3
  require 'ostruct'
3
4
 
@@ -16,15 +17,18 @@ module Fluent
16
17
  config_param :tag, :string
17
18
  config_param :regexp, :string
18
19
  config_param :proc_count, :integer, default: 1
20
+ config_param :operator_name, :string, default: "equal"
19
21
  end
20
22
 
21
23
  def configure(conf)
22
24
  super
23
- @processes = @processes.map { |process|
25
+ @processes = @processes.map { |process|
24
26
  s = OpenStruct.new
25
27
  s.regexp = Regexp.new(process.regexp)
26
28
  s.proc_count = process.proc_count
27
29
  s.tag = process.tag
30
+ s.operator_name = process.operator_name
31
+ s.operator = select_operator(process.operator_name)
28
32
  s
29
33
  }
30
34
  end
@@ -47,27 +51,49 @@ module Fluent
47
51
  end
48
52
 
49
53
  def emit_proc_count
50
- begin
51
- @processes.each do |process_spec|
52
- records = get_processes(process_spec)
53
- if process_spec.proc_count != records.size
54
+ @processes.each do |process_spec|
55
+ begin
56
+ record_size = get_processes(process_spec).size
57
+ if !correct_process?(process_spec, record_size)
54
58
  router.emit(
55
59
  process_spec.tag,
56
60
  Fluent::Engine.now,
57
61
  {
58
62
  regexp: process_spec.regexp.source,
59
- proc_count: records.size,
63
+ proc_count: record_size,
60
64
  expect_proc_count: process_spec.proc_count,
65
+ operator_name: process_spec.operator_name,
61
66
  hostname: Socket.gethostname
62
67
  }
63
68
  )
64
69
  end
70
+ rescue => e
71
+ log.error e
65
72
  end
66
- rescue => e
67
- log.error e
68
73
  end
69
74
  end
70
75
 
76
+ def select_operator(operator_name)
77
+ case operator_name.to_sym
78
+ when :equal
79
+ "=="
80
+ when :gather_than
81
+ ">"
82
+ when :gather_equal
83
+ ">="
84
+ when :less_than
85
+ "<"
86
+ when :less_equal
87
+ "<="
88
+ else
89
+ raise Fluent::ConfigError, "proc_count operator allows equal/gather_than/gather_equal/less_than/less_equal"
90
+ end
91
+ end
92
+
93
+ def correct_process?(process_spec, expect_proc_count)
94
+ expect_proc_count.public_send(process_spec.operator, process_spec.proc_count.to_i)
95
+ end
96
+
71
97
  def get_processes(process_spec)
72
98
  processes = []
73
99
  ProcTable.ps do |process|
@@ -5,7 +5,17 @@ class ProcCountInputTest < Test::Unit::TestCase
5
5
  Fluent::Test.setup
6
6
  end
7
7
 
8
- def create_driver(conf)
8
+ CONFIG = %q{
9
+ interval 60s
10
+
11
+ <process>
12
+ tag proc_count.test
13
+ regexp foobarbuzz
14
+ proc_count 0
15
+ </process>
16
+ }
17
+
18
+ def create_driver(conf = CONFIG)
9
19
  Fluent::Test::InputTestDriver.new(Fluent::ProcCountInput).configure(conf)
10
20
  end
11
21
 
@@ -23,12 +33,22 @@ class ProcCountInputTest < Test::Unit::TestCase
23
33
  tag proc_count.embulk
24
34
  regexp embulk
25
35
  proc_count 1
36
+ operator_name less_than
26
37
  </process>
27
38
  }
28
39
 
29
- assert_equal 'test', d.instance.tag
30
- assert_equal 10 * 60, d.instance.interval
31
- assert_equal 'hoge', d.instance.instance_variable_get(:@hoge)
40
+ assert_equal 60, d.instance.interval
41
+
42
+ process_conf1 = d.instance.processes.first
43
+ assert_equal 'proc_count.fluentd', process_conf1.tag
44
+ assert_equal 'bin/fluentd', process_conf1.regexp.match('bin/fluentd -c')[0]
45
+ assert_equal 'equal', process_conf1.operator_name
46
+ assert_equal '==', process_conf1.operator
47
+
48
+ process_conf2 = d.instance.processes.last
49
+ assert_equal 'proc_count.embulk', process_conf2.tag
50
+ assert_equal 'less_than', process_conf2.operator_name
51
+ assert_equal '<', process_conf2.operator
32
52
  end
33
53
 
34
54
  def test_configure_error_when_config_is_empty
@@ -45,8 +65,7 @@ class ProcCountInputTest < Test::Unit::TestCase
45
65
  end
46
66
 
47
67
  emits = d.emits
48
- assert_equal true, emits.length > 0
49
- assert_equal "tag1", emits[0].first
50
- assert_equal ({"k1"=>"ok"}), emits[0].last
68
+ assert_equal true, emits.length.zero?
69
+ assert_equal true, emits[0].nil?
51
70
  end
52
- end
71
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-proc_count
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - toyama0919
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-17 00:00:00.000000000 Z
11
+ date: 2017-04-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ffi
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - ">="
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: test-unit
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  - !ruby/object:Gem::Dependency
126
140
  name: yard
127
141
  requirement: !ruby/object:Gem::Requirement
@@ -176,11 +190,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
176
190
  version: '0'
177
191
  requirements: []
178
192
  rubyforge_project:
179
- rubygems_version: 2.5.1
193
+ rubygems_version: 2.6.11
180
194
  signing_key:
181
195
  specification_version: 4
182
196
  summary: process count check plugin for fluentd.
183
197
  test_files:
184
198
  - test/helper.rb
185
199
  - test/plugin/test_in_proc_count.rb
186
- has_rdoc: