Module: Vmstat

Extended by:
Stub
Defined in:
lib/vmstat.rb,
lib/vmstat/cpu.rb,
lib/vmstat/disk.rb,
lib/vmstat/stub.rb,
lib/vmstat/task.rb,
lib/vmstat/memory.rb,
lib/vmstat/procfs.rb,
lib/vmstat/solaris.rb,
lib/vmstat/version.rb,
lib/vmstat/snapshot.rb,
lib/vmstat/linux_disk.rb,
lib/vmstat/netopenbsd.rb,
lib/vmstat/load_average.rb,
lib/vmstat/network_interface.rb,
ext/vmstat/vmstat.c

Overview

This is a focused and fast library to get system information like:

  • Memory (free, active, …)

  • Network Interfaces (name, in bytes, out bytes, …)

  • CPU (user, system, nice, idle)

  • Load Average

  • Disk (type, disk path, free bytes, total bytes, …)

  • Boot Time

  • Current Task (used bytes and usage time MACOSX or LINUX ONLY)

Defined Under Namespace

Modules: ProcFS, Solaris, Stub Classes: Cpu, Disk, LinuxDisk, LinuxMemory, LoadAverage, Memory, NetworkInterface, Snapshot, Task

Constant Summary collapse

VERSION =
"2.3.1"

Class Method Summary collapse

Class Method Details

.boot_timeTime

Fetches the boot time of the system.

Examples:

Vmstat.boot_time # => 2012-10-09 18:42:37 +0200

Returns:

  • (Time)

    the boot time as regular time object.



# File 'lib/vmstat.rb', line 27

.cpuArray<Vmstat::Cpu>

Fetches the cpu statistics (usage counter for user, nice, system and idle)

Examples:

Vmstat.cpu # => [#<struct Vmstat::Cpu ...>, #<struct Vmstat::Cpu ...>]

Returns:



# File 'lib/vmstat.rb', line 33

.disk(path) ⇒ Vmstat::Disk

Fetches the usage data and other useful disk information for the given path.

Examples:

Vmstat.disk("/") # => #<struct Vmstat::Disk type=:hfs, ...>

Parameters:

  • path (String)

    the path (mount point or device path) to the disk

Returns:



# File 'lib/vmstat.rb', line 39

.ethernet_devicesArray<NetworkInterface>

Filters all available ethernet devices.

Returns:



88
89
90
# File 'lib/vmstat.rb', line 88

def self.ethernet_devices
  network_interfaces.select(&:ethernet?)
end

.extract_uvm_val(uvmexp, name) ⇒ Object



55
56
57
58
59
60
# File 'lib/vmstat/netopenbsd.rb', line 55

def self.extract_uvm_val(uvmexp, name)
  regexp = Regexp.new('(\d+)\s' + name)
  uvmexp.lines.grep(regexp) do |line|
    return $1.to_i
  end
end

.load_averageVmstat::LoadAverage

Fetches the load average for the current system.

Examples:

Vmstat.load_average # => #<struct Vmstat::LoadAverage one_minute=...>

Returns:



# File 'lib/vmstat.rb', line 46

.loopback_devicesArray<NetworkInterface>

Filters all available loopback devices.

Returns:



94
95
96
# File 'lib/vmstat.rb', line 94

def self.loopback_devices
  network_interfaces.select(&:loopback?)
end

.memoryVmstat::Memory

Fetches the memory usage information.

Examples:

Vmstat.memory # => #<struct Vmstat::Memory ...>

Returns:



# File 'lib/vmstat.rb', line 52

.network_interfacesArray<Vmstat::NetworkInterface>

Fetches the information for all available network devices.

Examples:

Vmstat.network_interfaces # => [#<struct Vmstat::NetworkInterface ...>, ...]

Returns:



# File 'lib/vmstat.rb', line 58

.pagesizeFixnum

Fetches pagesize of the current system.

Examples:

Vmstat.pagesize # => 4096

Returns:

  • (Fixnum)

    the pagesize of the current system in bytes.



# File 'lib/vmstat.rb', line 64

.snapshot(paths = ["/"]) ⇒ Vmstat::Snapshot

Creates a full snapshot of the systems hardware statistics.

Examples:

Vmstat.snapshot # => #<struct Vmstat::Snapshot ...>

Parameters:

  • paths (Array<String>) (defaults to: ["/"])

    the paths to the disks to snapshot.

Returns:



82
83
84
# File 'lib/vmstat.rb', line 82

def self.snapshot(paths = ["/"])
  Snapshot.new(paths)
end

.taskArray<Vmstat::Task>

Note:

Currently only on Mac OS X

Fetches time and memory usage for the current process.

Examples:

Vmstat.task # => #<struct Vmstat::Task ...>

Returns:



# File 'lib/vmstat.rb', line 70