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
Constant Summary collapse
- VERSION =
"1.2.0"
Class Method Summary collapse
- .balance_pid ⇒ Object
- .blk_param(blkdev, name) ⇒ Object
- .bootline ⇒ Object
- .clocksource(param) ⇒ Object
-
.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…
- .mounted ⇒ Object
- .ncores ⇒ Object
- .net_dev_exist?(name) ⇒ Boolean
- .net_driver(name) ⇒ Object
- .net_param(netdev, name) ⇒ Object
-
.net_rps(netdev, ix) ⇒ Object
Receive Packet Steering - software.
-
.net_rss(irq) ⇒ Object
Receive Side Scaling - hardware.
- .set_sysctl(name, value) ⇒ Object
- .sysctl(name) ⇒ Object
- .xfsinfo(mount) ⇒ Object
Class Method Details
.balance_pid ⇒ Object
9 10 11 12 13 |
# File 'lib/tweek.rb', line 9 def self.balance_pid @balance_pid ||= `pgrep irqbalance`.strip.to_i raise "pgrep appears to be missing!" if $? == 127 return @balance_pid end |
.blk_param(blkdev, name) ⇒ Object
53 54 55 |
# File 'lib/tweek.rb', line 53 def self.blk_param blkdev, name ::File.open("/sys/block/#{blkdev}/queue/#{name}", &:read).strip rescue $!. end |
.bootline ⇒ Object
5 6 7 |
# File 'lib/tweek.rb', line 5 def self.bootline @bootline ||= ::File.open("/proc/cmdline", &:read).strip end |
.clocksource(param) ⇒ Object
28 29 30 |
# File 'lib/tweek.rb', line 28 def self.clocksource param ::File.open("/sys/devices/system/clocksource/#{param}/current_clocksource",&:read).strip rescue $!. 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…
18 19 20 21 22 |
# File 'lib/tweek.rb', line 18 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 |
.mounted ⇒ Object
71 72 73 |
# File 'lib/tweek.rb', line 71 def self.mounted ::File.open("/proc/mounts", &:readlines).map{|m| m.split(' ')} end |
.ncores ⇒ Object
24 25 26 |
# File 'lib/tweek.rb', line 24 def self.ncores `getconf _NPROCESSORS_ONLN`.strip.to_i rescue 0 end |
.net_dev_exist?(name) ⇒ Boolean
45 46 47 |
# File 'lib/tweek.rb', line 45 def self.net_dev_exist? name ::File.readable?("/sys/class/net/#{name}") end |
.net_driver(name) ⇒ Object
49 50 51 |
# File 'lib/tweek.rb', line 49 def self.net_driver name ::File.basename(::File.readlink("/sys/class/net/#{name}/device/driver")) end |
.net_param(netdev, name) ⇒ Object
67 68 69 |
# File 'lib/tweek.rb', line 67 def self.net_param netdev, name ::File.open("/sys/class/net/#{netdev}/#{name}", &:read).strip.gsub(/\s+/,' ') rescue $!. end |
.net_rps(netdev, ix) ⇒ Object
Receive Packet Steering - software
63 64 65 |
# File 'lib/tweek.rb', line 63 def self.net_rps netdev, ix ::File.open("/sys/class/net/#{netdev}/queues/rx-#{ix}/rps_cpus", &:read).strip rescue $!. end |
.net_rss(irq) ⇒ Object
Receive Side Scaling - hardware
58 59 60 |
# File 'lib/tweek.rb', line 58 def self.net_rss irq ::File.open("/proc/irq/#{irq}/smp_affinity",&:read).strip rescue $!. end |
.set_sysctl(name, value) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/tweek.rb', line 36 def self.set_sysctl name, value begin ::File.open("/proc/sys/#{name}", "w"){|f| f.write value} value rescue $!. end end |
.sysctl(name) ⇒ Object
32 33 34 |
# File 'lib/tweek.rb', line 32 def self.sysctl name ::File.open("/proc/sys/#{name}", &:read).strip.gsub(/\s+/,' ') rescue $!. end |
.xfsinfo(mount) ⇒ Object
75 76 77 78 |
# File 'lib/tweek.rb', line 75 def self.xfsinfo mount info = `xfs_info #{mount} 2>/dev/null`.strip return $?.exitstatus > 0 ? nil : info end |