/usr/lib/ruby/vendor_ruby/ohai/plugins/darwin/memory.rb is in ohai 8.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | #
# Author:: Patrick Collins (<pat@burned.com>)
# Copyright:: Copyright (c) 2013 Opscode, Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
Ohai.plugin(:Memory) do
provides 'memory'
collect_data(:darwin) do
memory Mash.new
installed_memory = shell_out("sysctl -n hw.memsize").stdout.to_i / 1024 / 1024.0
memory[:total] = "#{installed_memory.to_i}MB"
total_consumed = 0
active = 0
inactive = 0
vm_stat = shell_out("vm_stat").stdout
vm_stat_match = /page size of (\d+) bytes/.match(vm_stat)
page_size = if vm_stat_match and vm_stat_match[1]
vm_stat_match[1].to_i
else
4096
end
vm_stat.split("\n").each do |line|
['wired down', 'active', 'inactive'].each do |match|
unless line.index("Pages #{match}:").nil?
pages = line.split.last.to_i
megabyte_val = (pages * page_size) / 1024 / 1024.0
total_consumed += megabyte_val
case match
when 'wired down'
active += megabyte_val.to_i
when 'active'
active += megabyte_val.to_i
when 'inactive'
inactive += megabyte_val.to_i
end
end
end
end
memory[:active] = "#{active}MB" if active > 0
memory[:inactive] = "#{inactive}MB" if inactive > 0
free_memory = installed_memory - total_consumed
memory[:free] = "#{free_memory.to_i}MB" if total_consumed > 0
end
end
|