Class: Fluent::DiskUsage

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

Instance Method Summary collapse

Instance Method Details

#configure(conf) ⇒ Object



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

def configure(conf)
  super
  require 'sys/filesystem'
end

#outputObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/fluent/plugin/in_diskusage.rb', line 31

def output
  filestats = Sys::Filesystem.stat(@mountpoint)
  total_bytes = filestats.block_size * filestats.blocks
  free_bytes = filestats.block_size * filestats.blocks_available
  used_bytes = total_bytes - free_bytes
  used_percent = 0
  free_percent = 0
  if total_bytes.nonzero?  
    used_percent = used_bytes / total_bytes.to_f
    free_percent = free_bytes / total_bytes.to_f
  end
  record = {"label"=>@label,"total_bytes"=>total_bytes,"free_bytes"=>free_bytes,"used_bytes"=>used_bytes,"used_percent"=>used_percent,"free_percent"=>free_percent}

  time = Fluent::Engine.now
  router.emit(tag,time,record)
end

#runObject



24
25
26
27
28
29
# File 'lib/fluent/plugin/in_diskusage.rb', line 24

def run
  while true
    output
  sleep @refresh_interval
  end
end

#shutdownObject



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

def shutdown
  @watcher.terminate
  @watcher.join

end

#startObject



19
20
21
22
# File 'lib/fluent/plugin/in_diskusage.rb', line 19

def start
  super
  @watcher = Thread.new(&method(:run))
end