Class: Fluent::Plugin::ObjectSpaceInput

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

Defined Under Namespace

Classes: Counter

Constant Summary

Constants included from Configurable

Configurable::CONFIG_TYPE_REGISTRY

Instance Attribute Summary

Attributes included from Fluent::PluginLoggerMixin

#log

Attributes inherited from Base

#under_plugin_development

Instance Method Summary collapse

Methods included from Fluent::PluginHelper::Mixin

included

Methods included from Fluent::PluginLoggerMixin

#configure, included, #terminate

Methods included from Fluent::PluginId

#configure, #plugin_id, #plugin_id_configured?, #plugin_id_for_test?

Methods inherited from Base

#after_shutdown, #after_shutdown?, #after_start, #after_started?, #before_shutdown, #before_shutdown?, #close, #closed?, #configure, #configured?, #has_router?, #inspect, #shutdown, #shutdown?, #started?, #stop, #stopped?, #terminate, #terminated?

Methods included from SystemConfig::Mixin

#system_config, #system_config_override

Methods included from Configurable

#config, #configure, included, lookup_type, register_type

Constructor Details

#initializeObjectSpaceInput

Returns a new instance of ObjectSpaceInput.



28
29
30
# File 'lib/fluent/plugin/in_object_space.rb', line 28

def initialize
  super
end

Instance Method Details

#on_timerObject



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/fluent/plugin/in_object_space.rb', line 59

def on_timer
  now = Fluent::EventTime.now

  array = []
  map = {}

  ObjectSpace.each_object {|obj|
    klass = obj.class rescue Object
    if c = map[klass]
      c.incr!
    else
      c = Counter.new(klass, 1)
      array << c
      map[klass] = c
    end
  }

  array.sort_by! {|c| -c.count }

  record = {}
  array.each_with_index {|c,i|
    break if i >= @top
    record[c.name] = c.count
  }

  router.emit(@tag, now, record)
rescue => e
  log.error "object space failed to emit", error: e, tag: @tag, record: Yajl.dump(record)
  log.error_backtrace
end

#startObject



36
37
38
39
40
# File 'lib/fluent/plugin/in_object_space.rb', line 36

def start
  super

  timer_execute(:object_space_input, @emit_interval, &method(:on_timer))
end