Module: Tweek

Defined in:
lib/tweek.rb,
lib/tweek/version.rb

Overview

Define data-collection methods so we can easily stub them for tests

Defined Under Namespace

Classes: File, Section

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.balance_pidObject



9
10
11
# File 'lib/tweek.rb', line 9

def self.balance_pid
  @balance_pid ||= `pgrep irqbalance`.chomp.to_i
end

.blk_param(blkdev, name) ⇒ Object



38
39
40
# File 'lib/tweek.rb', line 38

def self.blk_param blkdev, name
  ::File.open("/sys/block/#{blkdev}/queue/#{name}", &:read).chomp rescue $!.message
end

.bootlineObject



5
6
7
# File 'lib/tweek.rb', line 5

def self.bootline
  @bootline ||= ::File.open("/proc/cmdline", &:read).chomp
end

.clocksource(param) ⇒ Object



26
27
28
# File 'lib/tweek.rb', line 26

def self.clocksource param
   ::File.open("/sys/devices/system/clocksource/#{param}/current_clocksource",&:read).chomp rescue $!.message
end

.irqs(netdev) ⇒ Object

Determine the queue processing interrupts for the network device Empirically we observe that the convention for the name in /proc/interrupts varies so some hacking required…



16
17
18
19
20
# File 'lib/tweek.rb', line 16

def self.irqs netdev
  @irqs = ::File.open("/proc/interrupts", &:readlines).grep(/\b#{netdev}\b/)
  @irqs.reject! {|i| i !~ /\b#{netdev}-Tx-?Rx/} if @irqs.size > 1
  @irqs.map{|m| m.partition(':')[0].strip}
end

.mountedObject



56
57
58
# File 'lib/tweek.rb', line 56

def self.mounted
  ::File.open("/proc/mounts", &:readlines).map{|m| m.split(' ')}
end

.ncoresObject



22
23
24
# File 'lib/tweek.rb', line 22

def self.ncores
  `getconf _NPROCESSORS_ONLN`.chomp.to_i rescue 0
end

.net_driver(name) ⇒ Object



34
35
36
# File 'lib/tweek.rb', line 34

def self.net_driver name
  ::File.basename(::File.readlink("/sys/class/net/#{name}/device/driver"))
end

.net_param(netdev, name) ⇒ Object



52
53
54
# File 'lib/tweek.rb', line 52

def self.net_param netdev, name
  ::File.open("/sys/class/net/#{netdev}/#{name}", &:read).chomp.gsub(/\s+/,' ')
end

.net_rps(netdev, ix) ⇒ Object

Receive Packet Steering - software



48
49
50
# File 'lib/tweek.rb', line 48

def self.net_rps netdev, ix
  ::File.open("/sys/class/net/#{netdev}/queues/rx-#{ix}/rps_cpus", &:read).chomp rescue $!.message
end

.net_rss(irq) ⇒ Object

Receive Side Scaling - hardware



43
44
45
# File 'lib/tweek.rb', line 43

def self.net_rss irq
  ::File.open("/proc/irq/#{irq}/smp_affinity",&:read).chomp rescue $!.message
end

.sysctl(name) ⇒ Object



30
31
32
# File 'lib/tweek.rb', line 30

def self.sysctl name
  ::File.open("/proc/sys/#{name}", &:read).chomp.gsub(/\s+/,' ') rescue $!.message
end

.xfsinfo(mount) ⇒ Object



60
61
62
63
# File 'lib/tweek.rb', line 60

def self.xfsinfo mount
  info = `xfs_info #{mount} 2>/dev/null`.chomp
  return $?.exitstatus > 0 ? nil : info
end