Skip to content

Commit 9c6f109

Browse files
committed
Merge branch 'v2.3.0'
2 parents da2db81 + 68326c7 commit 9c6f109

13 files changed

+284
-15
lines changed

Diff for: .gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
.config
55
.yardoc
66
.DS_Store
7-
Gemfile.lock
87
InstalledFiles
98
_yardoc
109
coverage

Diff for: .ruby-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.2.4
1+
2.2.6

Diff for: .travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ language: ruby
22
os:
33
- linux
44
rvm:
5-
- ruby-2.2.5
5+
- ruby-2.2.6
66
- ruby-head
77
env:
88
- TRAVIS=true

Diff for: Gemfile.lock

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
PATH
2+
remote: .
3+
specs:
4+
vmstat (2.3.0)
5+
6+
GEM
7+
remote: https://rubygems.org/
8+
specs:
9+
coderay (1.1.1)
10+
diff-lcs (1.2.5)
11+
ffi (1.9.14)
12+
formatador (0.2.5)
13+
guard (2.14.0)
14+
formatador (>= 0.2.4)
15+
listen (>= 2.7, < 4.0)
16+
lumberjack (~> 1.0)
17+
nenv (~> 0.1)
18+
notiffany (~> 0.0)
19+
pry (>= 0.9.12)
20+
shellany (~> 0.0)
21+
thor (>= 0.18.1)
22+
guard-compat (1.2.1)
23+
guard-rspec (4.7.3)
24+
guard (~> 2.1)
25+
guard-compat (~> 1.1)
26+
rspec (>= 2.99.0, < 4.0)
27+
listen (3.1.5)
28+
rb-fsevent (~> 0.9, >= 0.9.4)
29+
rb-inotify (~> 0.9, >= 0.9.7)
30+
ruby_dep (~> 1.2)
31+
lumberjack (1.0.10)
32+
method_source (0.8.2)
33+
nenv (0.3.0)
34+
notiffany (0.1.1)
35+
nenv (~> 0.1)
36+
shellany (~> 0.0)
37+
pry (0.10.4)
38+
coderay (~> 1.1.0)
39+
method_source (~> 0.8.1)
40+
slop (~> 3.4)
41+
rake (11.3.0)
42+
rake-compiler (1.0.3)
43+
rake
44+
rb-fsevent (0.9.8)
45+
rb-inotify (0.9.7)
46+
ffi (>= 0.5.0)
47+
rspec (2.99.0)
48+
rspec-core (~> 2.99.0)
49+
rspec-expectations (~> 2.99.0)
50+
rspec-mocks (~> 2.99.0)
51+
rspec-core (2.99.2)
52+
rspec-expectations (2.99.2)
53+
diff-lcs (>= 1.1.3, < 2.0)
54+
rspec-mocks (2.99.4)
55+
ruby_dep (1.5.0)
56+
shellany (0.0.1)
57+
slop (3.6.0)
58+
thor (0.19.4)
59+
timecop (0.8.1)
60+
61+
PLATFORMS
62+
ruby
63+
64+
DEPENDENCIES
65+
guard-rspec
66+
rake (~> 11.3)
67+
rake-compiler
68+
rspec (~> 2.9)
69+
timecop
70+
vmstat!
71+
72+
BUNDLED WITH
73+
1.13.6

Diff for: lib/vmstat.rb

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Vmstat
1515
autoload :Disk, "vmstat/disk"
1616
autoload :LinuxDisk, "vmstat/linux_disk"
1717
autoload :Memory, "vmstat/memory"
18+
autoload :LinuxMemory, "vmstat/linux_memory"
1819
autoload :Task, "vmstat/task"
1920
autoload :LoadAverage, "vmstat/load_average"
2021
autoload :ProcFS, "vmstat/procfs"

Diff for: lib/vmstat/linux_memory.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# @attr [Fixnum] available
2+
# The estimated available memory (linux)
3+
# See: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
4+
class Vmstat::LinuxMemory < Vmstat::Memory
5+
attr_accessor :available
6+
7+
# Calculate the available bytes based of the active pages.
8+
# @return [Fixnum] active bytes
9+
def available_bytes
10+
available * pagesize
11+
end
12+
end
13+

Diff for: lib/vmstat/memory.rb

+15-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Memory < Struct.new(:pagesize, :wired, :active, :inactive, :free,
1919
# Calculate the wired bytes based of the wired pages.
2020
# @return [Fixnum] wired bytes
2121
def wired_bytes
22-
wired * pagesize
22+
wired * pagesize
2323
end
2424

2525
# Calculate the active bytes based of the active pages.
@@ -43,7 +43,20 @@ def free_bytes
4343
# Calculate the total bytes based of all pages
4444
# @return [Fixnum] total bytes
4545
def total_bytes
46-
(wired + active + inactive + free) * pagesize
46+
(wired + active + inactive + free) * pagesize
47+
end
48+
end
49+
50+
# @attr [Fixnum] available
51+
# The estimated available memory (linux)
52+
# See: https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=34e431b0ae398fc54ea69ff85ec700722c9da773
53+
class LinuxMemory < Memory
54+
attr_accessor :available
55+
56+
# Calculate the available bytes based of the active pages.
57+
# @return [Fixnum] active bytes
58+
def available_bytes
59+
available * pagesize
4760
end
4861
end
4962
end

Diff for: lib/vmstat/procfs.rb

+14-7
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,21 @@ def cpu
4545
# Vmstat.memory # => #<struct Vmstat::Memory ...>
4646
def memory
4747
@pagesize ||= Vmstat.pagesize
48+
has_available = false
4849

49-
total = free = active = inactive = pageins = pageouts = 0
50+
total = free = active = inactive = pageins = pageouts = available = 0
5051
procfs_file("meminfo") do |file|
5152
content = file.read(2048) # the requested information is in the first bytes
5253

53-
content.scan(/(\w+):\s+(\d+) kB/) do |name, kbytes|
54+
content.scan(/(\w+):\s+(\d+) kB/) do |name, kbytes|
5455
pages = (kbytes.to_i * 1024) / @pagesize
5556

5657
case name
5758
when "MemTotal" then total = pages
5859
when "MemFree" then free = pages
60+
when "MemAvailable"
61+
available = pages
62+
has_available = true
5963
when "Active" then active = pages
6064
when "Inactive" then inactive = pages
6165
end
@@ -74,8 +78,11 @@ def memory
7478
end
7579
end
7680

77-
Memory.new @pagesize, total-free-active-inactive, active, inactive, free,
78-
pageins, pageouts
81+
mem_klass = has_available ? LinuxMemory : Memory
82+
mem_klass.new(@pagesize, total-free-active-inactive, active,
83+
inactive, free, pageins, pageouts).tap do |mem|
84+
mem.available = available if has_available
85+
end
7986
end
8087

8188
# Fetches the information for all available network devices.
@@ -91,8 +98,8 @@ def network_interfaces
9198
when /^lo/ then NetworkInterface::LOOPBACK_TYPE
9299
end
93100

94-
netifcs << NetworkInterface.new(columns[0].to_sym, columns[1].to_i,
95-
columns[3].to_i, columns[4].to_i,
101+
netifcs << NetworkInterface.new(columns[0].to_sym, columns[1].to_i,
102+
columns[3].to_i, columns[4].to_i,
96103
columns[9].to_i, columns[11].to_i,
97104
type)
98105
end
@@ -107,7 +114,7 @@ def task
107114

108115
procfs_file("self", "stat") do |file|
109116
data = file.read.split(/ /)
110-
Task.new(data[22].to_i / @pagesize, data[23].to_i,
117+
Task.new(data[22].to_i / @pagesize, data[23].to_i,
111118
data[13].to_i * 1000, data[14].to_i * 1000)
112119
end
113120
end

Diff for: lib/vmstat/version.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
module Vmstat
2-
VERSION = "2.2.1"
2+
VERSION = "2.3.0"
33
end

Diff for: spec/memavail_procfs/meminfo

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
MemTotal: 1884428 kB
2+
MemFree: 252452 kB
3+
MemAvailable: 458368 kB
4+
Buffers: 76 kB
5+
Cached: 321752 kB
6+
SwapCached: 4 kB
7+
Active: 1307912 kB
8+
Inactive: 177976 kB
9+
Active(anon): 1074332 kB
10+
Inactive(anon): 106548 kB
11+
Active(file): 233580 kB
12+
Inactive(file): 71428 kB
13+
Unevictable: 21100 kB
14+
Mlocked: 21100 kB
15+
SwapTotal: 2097148 kB
16+
SwapFree: 2097140 kB
17+
Dirty: 60 kB
18+
Writeback: 0 kB
19+
AnonPages: 1185204 kB
20+
Mapped: 101384 kB
21+
Shmem: 8760 kB
22+
Slab: 59380 kB
23+
SReclaimable: 27064 kB
24+
SUnreclaim: 32316 kB
25+
KernelStack: 4528 kB
26+
PageTables: 21592 kB
27+
NFS_Unstable: 0 kB
28+
Bounce: 0 kB
29+
WritebackTmp: 0 kB
30+
CommitLimit: 3039360 kB
31+
Committed_AS: 2906080 kB
32+
VmallocTotal: 34359738367 kB
33+
VmallocUsed: 269704 kB
34+
VmallocChunk: 34359466492 kB
35+
HardwareCorrupted: 0 kB
36+
AnonHugePages: 659456 kB
37+
HugePages_Total: 0
38+
HugePages_Free: 0
39+
HugePages_Rsvd: 0
40+
HugePages_Surp: 0
41+
Hugepagesize: 2048 kB
42+
DirectMap4k: 26624 kB
43+
DirectMap2M: 2070528 kB

Diff for: spec/memavail_procfs/vmstat

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
nr_free_pages 107062
2+
nr_inactive_anon 60
3+
nr_active_anon 1557
4+
nr_inactive_file 8341
5+
nr_active_file 4939
6+
nr_unevictable 0
7+
nr_mlock 0
8+
nr_anon_pages 1579
9+
nr_mapped 1461
10+
nr_file_pages 13346
11+
nr_dirty 1
12+
nr_writeback 0
13+
nr_slab_reclaimable 1628
14+
nr_slab_unreclaimable 1885
15+
nr_page_table_pages 101
16+
nr_kernel_stack 88
17+
nr_unstable 0
18+
nr_bounce 0
19+
nr_vmscan_write 0
20+
nr_vmscan_immediate_reclaim 0
21+
nr_writeback_temp 0
22+
nr_isolated_anon 0
23+
nr_isolated_file 0
24+
nr_shmem 67
25+
nr_dirtied 185
26+
nr_written 182
27+
nr_anon_transparent_hugepages 0
28+
nr_dirty_threshold 24392
29+
nr_dirty_background_threshold 12196
30+
pgpgin 64599
31+
pgpgout 1104
32+
pswpin 0
33+
pswpout 0
34+
pgalloc_dma 2
35+
pgalloc_normal 190973
36+
pgalloc_high 0
37+
pgalloc_movable 0
38+
pgfree 298439
39+
pgactivate 5802
40+
pgdeactivate 0
41+
pgfault 581461
42+
pgmajfault 42
43+
pgrefill_dma 0
44+
pgrefill_normal 0
45+
pgrefill_high 0
46+
pgrefill_movable 0
47+
pgsteal_dma 0
48+
pgsteal_normal 0
49+
pgsteal_high 0
50+
pgsteal_movable 0
51+
pgscan_kswapd_dma 0
52+
pgscan_kswapd_normal 0
53+
pgscan_kswapd_high 0
54+
pgscan_kswapd_movable 0
55+
pgscan_direct_dma 0
56+
pgscan_direct_normal 0
57+
pgscan_direct_high 0
58+
pgscan_direct_movable 0
59+
pginodesteal 0
60+
slabs_scanned 0
61+
kswapd_steal 0
62+
kswapd_inodesteal 0
63+
kswapd_low_wmark_hit_quickly 0
64+
kswapd_high_wmark_hit_quickly 0
65+
kswapd_skip_congestion_wait 0
66+
pageoutrun 1
67+
allocstall 0
68+
pgrotated 0
69+
compact_blocks_moved 0
70+
compact_pages_moved 0
71+
compact_pagemigrate_failed 0
72+
compact_stall 0
73+
compact_fail 0
74+
compact_success 0
75+
htlb_buddy_alloc_success 0
76+
htlb_buddy_alloc_fail 0
77+
unevictable_pgs_culled 0
78+
unevictable_pgs_scanned 0
79+
unevictable_pgs_rescued 0
80+
unevictable_pgs_mlocked 0
81+
unevictable_pgs_munlocked 0
82+
unevictable_pgs_cleared 0
83+
unevictable_pgs_stranded 0
84+
unevictable_pgs_mlockfreed 0
85+
thp_fault_alloc 0
86+
thp_fault_fallback 0
87+
thp_collapse_alloc 0
88+
thp_collapse_alloc_failed 0
89+
thp_split 0

Diff for: spec/vmstat/memavail_spec.rb

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
3+
describe Vmstat::LinuxMemory do
4+
let(:procfs) do
5+
Class.new do
6+
extend Vmstat::ProcFS
7+
8+
def self.procfs_path
9+
File.expand_path("../../memavail_procfs", __FILE__)
10+
end
11+
end
12+
end
13+
14+
context "#memory" do
15+
subject { procfs.memory }
16+
17+
it { should be_a(Vmstat::LinuxMemory) }
18+
if `getconf PAGESIZE`.chomp.to_i == 4096
19+
it do
20+
should == Vmstat::LinuxMemory.new(4096, 36522, 326978,
21+
44494, 63113, 64599, 1104)
22+
end
23+
24+
it "should have the right total" do
25+
(subject.wired_bytes + subject.active_bytes +
26+
subject.inactive_bytes + subject.free_bytes).should == 1929654272
27+
end
28+
end
29+
end
30+
end
31+

Diff for: vmstat.gemspec

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Gem::Specification.new do |gem|
2121
gem.require_paths = ["lib"]
2222
gem.extensions = ["ext/vmstat/extconf.rb"]
2323

24-
gem.add_development_dependency('rake')
25-
gem.add_development_dependency('rspec', "~> 2.9")
24+
gem.add_development_dependency('rake', '~> 11.3')
25+
gem.add_development_dependency('rspec', '~> 2.9')
2626
gem.add_development_dependency('rake-compiler')
2727
gem.add_development_dependency('guard-rspec')
2828
gem.add_development_dependency('timecop')

0 commit comments

Comments
 (0)