Method: Fluent::Plugin::ObjectSpaceInput#on_timer

Defined in:
lib/fluent/plugin/in_object_space.rb

#on_timerObject



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
89
90
91
# File 'lib/fluent/plugin/in_object_space.rb', line 62

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