Class: Fluent::ProcCountInput
- Inherits:
-
Input
- Object
- Input
- Fluent::ProcCountInput
- Includes:
- Sys
- Defined in:
- lib/fluent/plugin/in_proc_count.rb
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit_proc_count ⇒ Object
- #get_processes(process_spec) ⇒ Object
-
#initialize ⇒ ProcCountInput
constructor
A new instance of ProcCountInput.
- #run ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ ProcCountInput
Returns a new instance of ProcCountInput.
9 10 11 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 9 def initialize super end |
Instance Method Details
#configure(conf) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 21 def configure(conf) super @processes = @processes.map { |process| s = OpenStruct.new s.regexp = Regexp.new(process.regexp) s.proc_count = process.proc_count s.tag = process.tag s } end |
#emit_proc_count ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 49 def emit_proc_count begin @processes.each do |process_spec| records = get_processes(process_spec) if process_spec.proc_count != records.size router.emit( process_spec.tag, Fluent::Engine.now, { regexp: process_spec.regexp.source, proc_count: records.size, expect_proc_count: process_spec.proc_count, hostname: Socket.gethostname } ) end end rescue => e log.error e end end |
#get_processes(process_spec) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 71 def get_processes(process_spec) processes = [] ProcTable.ps do |process| if process_spec.regexp.match(process.cmdline) processes << process end end processes end |
#run ⇒ Object
42 43 44 45 46 47 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 42 def run loop do Thread.new(&method(:emit_proc_count)) sleep @interval end end |
#shutdown ⇒ Object
37 38 39 40 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 37 def shutdown super Thread.kill(@thread) end |
#start ⇒ Object
32 33 34 35 |
# File 'lib/fluent/plugin/in_proc_count.rb', line 32 def start super @thread = Thread.new(&method(:run)) end |