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: Entry, File, Section
Constant Summary
collapse
- VERSION =
"1.2.2"
Class Method Summary
collapse
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 $!.message
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 $!.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…
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 $!.message
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 $!.message
end
|
Receive Side Scaling - hardware
58
59
60
|
# File 'lib/tweek.rb', line 58
def self. irq
::File.open("/proc/irq/#{irq}/smp_affinity",&:read).strip rescue $!.message
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
$!.message
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 $!.message
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
|