File: disk.rb

package info (click to toggle)
ruby-vmstat 2.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 344 kB
  • sloc: ruby: 1,136; ansic: 347; makefile: 3
file content (44 lines) | stat: -rw-r--r-- 1,492 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
module Vmstat
  # Gathered disk statistics snapshot.
  # @attr [Symbol] type
  #   The file system name e. g. *hfs*.
  # @attr [String] origin
  #   The location of the device e.g. */dev/disk0*.
  # @attr [String] mount
  #   The mount point of the device e.g. */mnt/store*.
  # @attr [Fixnum] block_size
  #   Size of file system blocks in bytes.
  # @attr [Fixnum] free_blocks
  #   Free blocks in the file system.
  # @attr [Fixnum] available_blocks
  #   Available blocks in the file system.
  # @attr [Fixnum] total_blocks
  #   Total number of blocks in the file system.
  class Disk < Struct.new(:type, :origin, :mount, :block_size, 
                          :free_blocks, :available_blocks, :total_blocks)
    # Calculates the number of free bytes for the file system.
    # @return [Fixnum] number of free bytes
    def free_bytes
      free_blocks * block_size
    end

    # Calculates the number of available bytes for the file system.
    # @return [Fixnum] number of available bytes
    def available_bytes
      available_blocks * block_size
    end

    # Calculates the number of used bytes for the file system.
    # @return [Fixnum] number of used bytes
    def used_bytes
      (total_blocks - free_blocks) * block_size
    end

    # Calculates the number of total bytes for the file system. This is the max.
    # number of bytes possible on the device.
    # @return [Fixnum] number of total bytes
    def total_bytes
      total_blocks * block_size
    end
  end
end