Class: Fluent::RubyMemoryUsageProfilerInput

Inherits:
Input
  • Object
show all
Defined in:
lib/fluent/plugin/in_ruby_memory_usage_profiler.rb

Instance Method Summary collapse

Constructor Details

#initializeRubyMemoryUsageProfilerInput

Returns a new instance of RubyMemoryUsageProfilerInput.



14
15
16
17
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 14

def initialize
  super
  require 'memory_usage_profiler'
end

Instance Method Details

#configure(conf) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 19

def configure(conf)
  super

  @banner = MemoryUsageProfiler.banner_items

  case @output_type
  when 'event'
    @out = lambda{|result| Fluent::Engine.emit(@tag, Fluent::Engine.now, Hash[ [@banner, result].transpose ])}
  when 'log'
    @loglevel = @loglevel.to_sym
    @out = lambda{|result| $log.send(@loglevel, Hash[ [@banner, result].transpose ])}
  when 'file'
    raise Fluent::ConfigError, "'path' must be specified for 'output_type file'" unless @path
    @file = (@path == '-' ? STDOUT : open(@path, 'w+'))
    raise Fluent::ConfigError, "failed to open file '#{@path}' to write" unless @file
    @file.sync = true
    @file.puts @banner.join("\t")
    @out = lambda{|result| @file.puts result.join("\t")}
  else
    raise Fluent::ConfigError, "invalid output_type '#{@output_type}'"
  end
end

#startObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 42

def start
  super
  @running = true
  @thread = Thread.new do
    begin
      while @running
        MemoryUsageProfiler.kick(@name) {|result|
          @out.call(result)
        }
        sleep @duration
      end
    rescue => e
      $log.error "Unexpected error in ruby_memory_usage_profiler", :error_class => e.class, :error => e
    end
  end
end

#stopObject



59
60
61
# File 'lib/fluent/plugin/in_ruby_memory_usage_profiler.rb', line 59

def stop
  @running = false
end