Class: Fluent::JstatInput

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

Defined Under Namespace

Classes: TimerWatcher

Instance Method Summary collapse

Constructor Details

#initializeJstatInput

Returns a new instance of JstatInput.



5
6
7
# File 'lib/fluent/plugin/in_jstat.rb', line 5

def initialize
  super
end

Instance Method Details

#configure(conf) ⇒ Object



31
32
33
# File 'lib/fluent/plugin/in_jstat.rb', line 31

def configure(conf)
  super
end

#on_timerObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fluent/plugin/in_jstat.rb', line 55

def on_timer
  pid = File.read(@pid_path)
  command = "#{@jstat_path} #{@option} #{pid}"
  now = Engine.now
  io = IO.popen(command, "r")
  lines = io.readlines()
  headers = lines[0].split()
  datas = lines[1].split()
 
  record = Hash.new
  headers.each_with_index{|header, i|
    record[header] = datas[i].to_f * @scale
  }
  Engine.emit(@tag, now, record)
end

#runObject



48
49
50
51
52
53
# File 'lib/fluent/plugin/in_jstat.rb', line 48

def run
  @loop.run
rescue
  $log.error "unexpected error", :error=>$!.to_s
  $log.error_backtrace
end

#shutdownObject



42
43
44
45
46
# File 'lib/fluent/plugin/in_jstat.rb', line 42

def shutdown
  @loop.watchers.each {|w| w.detach }
  @loop.stop
  @thread.join
end

#startObject



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

def start
  @loop = Coolio::Loop.new
  @timer = TimerWatcher.new(@emit_interval, true, &method(:on_timer))
  @loop.attach(@timer)
  @thread = Thread.new(&method(:run))
end