Class: Fluent::ObjectSpaceInput
- Inherits:
-
Input
- Object
- Input
- Fluent::ObjectSpaceInput
show all
- Defined in:
- lib/fluent/plugin/in_object_space.rb
Defined Under Namespace
Classes: Counter, TimerWatcher
Constant Summary
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Input
#router
#log
Instance Method Summary
collapse
included
Methods included from PluginId
#plugin_id
#config, included, lookup_type, register_type
Constructor Details
Returns a new instance of ObjectSpaceInput.
26
27
28
|
# File 'lib/fluent/plugin/in_object_space.rb', line 26
def initialize
super
end
|
Instance Method Details
50
51
52
|
# File 'lib/fluent/plugin/in_object_space.rb', line 50
def configure(conf)
super
end
|
#on_timer ⇒ Object
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'lib/fluent/plugin/in_object_space.rb', line 91
def on_timer
now = Engine.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.to_s, error_class: e.class.to_s, tag: @tag, record: Yajl.dump(record)
end
|
#run ⇒ Object
67
68
69
70
71
72
|
# File 'lib/fluent/plugin/in_object_space.rb', line 67
def run
@loop.run
rescue
log.error "unexpected error", error: $!.to_s
log.error_backtrace
end
|
#shutdown ⇒ Object
61
62
63
64
65
|
# File 'lib/fluent/plugin/in_object_space.rb', line 61
def shutdown
@loop.watchers.each {|w| w.detach }
@loop.stop
@thread.join
end
|
#start ⇒ Object
54
55
56
57
58
59
|
# File 'lib/fluent/plugin/in_object_space.rb', line 54
def start
@loop = Coolio::Loop.new
@timer = TimerWatcher.new(@emit_interval, true, log, &method(:on_timer))
@loop.attach(@timer)
@thread = Thread.new(&method(:run))
end
|