module Vmstat
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)
Constants
- VERSION
Public Class Methods
cpu()
click to toggle source
# File lib/vmstat/netopenbsd.rb, line 2 def self.cpu cptime = %x`sysctl kern.cp_time`.split(/=/).last user, nice, sys, irq, idle = cptime.split(/,/).map(&:to_i) [Cpu.new(0, user, sys + irq, nice, idle)] end
ethernet_devices()
click to toggle source
Filters all available ethernet devices. @return [Array<NetworkInterface>] the ethernet devices
# File lib/vmstat.rb, line 88 def self.ethernet_devices network_interfaces.select(&:ethernet?) end
extract_uvm_val(uvmexp, name)
click to toggle source
# 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
loopback_devices()
click to toggle source
Filters all available loopback devices. @return [Array<NetworkInterface>] the loopback devices
# File lib/vmstat.rb, line 94 def self.loopback_devices network_interfaces.select(&:loopback?) end
memory()
click to toggle source
# File lib/vmstat/netopenbsd.rb, line 8 def self.memory uvmexp = %x`vmstat -s` Memory.new( # pagesize call is not used to avoid double shell out pagesize, # pagesize extract_uvm_val(uvmexp, 'pages managed'), # wired extract_uvm_val(uvmexp, 'pages active'), # active extract_uvm_val(uvmexp, 'pages inactive'), # inactive extract_uvm_val(uvmexp, 'pages free'), # free extract_uvm_val(uvmexp, 'pagein operations'), # pageins extract_uvm_val(uvmexp, 'pages being paged out') # pageouts ) end
network_interfaces()
click to toggle source
# File lib/vmstat/netopenbsd.rb, line 23 def self.network_interfaces bytes = %x`netstat -ibq`.lines.grep(/<Link>/) # bytes pkgs = %x`netstat -iqd`.lines.grep(/<Link>/) # packages itf = Hash.new { |h, k| h[k] = NetworkInterface.new(k) } bytes.each do |line| # Name Mtu Network Address Ibytes Obytes name, _, _, _, ibytes, obytes = line.split(/\s+/) itf[name].in_bytes = ibytes.to_i itf[name].out_bytes = obytes.to_i end pkgs.each do |line| # Name Mtu Network Address Ipkts Ierrs Opkts Oerrs Colls Drop name, _, _, _, _, ierrs, _, oerrs, _, drop = line.split(/\s+/) itf[name].in_errors = ierrs.to_i itf[name].in_drops = drop.to_i itf[name].out_errors = oerrs.to_i end itf.each do |name, nic| if name =~ /lo\d+/ nic.type = NetworkInterface::LOOPBACK_TYPE else nic.type = NetworkInterface::ETHERNET_TYPE end end itf.values end
snapshot(paths = ["/"])
click to toggle source
Creates a full snapshot of the systems hardware statistics. @param [Array<String>] paths the paths to the disks to snapshot. @return [Vmstat::Snapshot] a snapshot of all statistics. @example
Vmstat.snapshot # => #<struct Vmstat::Snapshot ...>
# File lib/vmstat.rb, line 82 def self.snapshot(paths = ["/"]) Snapshot.new(paths) end