Class: Tnw::Metrics::Parsers::Df

Inherits:
Object
  • Object
show all
Defined in:
lib/tnw/metrics/parsers/df.rb

Constant Summary collapse

BLOCK_BYTES =
1024

Class Method Summary collapse

Class Method Details

.parse(output, mount: "/") ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/tnw/metrics/parsers/df.rb', line 7

def self.parse(output, mount: "/")
  rows = output.lines.drop(1).filter_map do |line|
    fields = line.strip.split(/\s+/, 6)
    fields if fields.length == 6
  end
  row = rows.find { |fields| fields.fetch(5) == mount }
  raise ParseError, "df output is missing mount #{mount}" unless row

  total = blocks_to_bytes(row.fetch(1))
  used = blocks_to_bytes(row.fetch(2))
  available = blocks_to_bytes(row.fetch(3))

  {
    total_bytes: total,
    used_bytes: used,
    available_bytes: available,
    mount: row.fetch(5)
  }
end