@@ -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
0 commit comments