summaryrefslogtreecommitdiff
path: root/lib/ohai/plugins/netbsd/cpu.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ohai/plugins/netbsd/cpu.rb')
-rw-r--r--lib/ohai/plugins/netbsd/cpu.rb50
1 files changed, 27 insertions, 23 deletions
diff --git a/lib/ohai/plugins/netbsd/cpu.rb b/lib/ohai/plugins/netbsd/cpu.rb
index 5063db58..2e7f3470 100644
--- a/lib/ohai/plugins/netbsd/cpu.rb
+++ b/lib/ohai/plugins/netbsd/cpu.rb
@@ -16,33 +16,37 @@
# limitations under the License.
#
-provides 'cpu'
+Ohai.plugin(:Cpu) do
+ provides 'cpu'
-cpuinfo = Mash.new
+ collect_data do
+ cpuinfo = Mash.new
-# NetBSD provides some cpu information via sysctl, and a little via dmesg.boot
-# unlike OpenBSD and FreeBSD, NetBSD does not provide information about the
-# available instruction set
-# cpu0 at mainbus0 apid 0: Intel 686-class, 2134MHz, id 0x6f6
+ # NetBSD provides some cpu information via sysctl, and a little via dmesg.boot
+ # unlike OpenBSD and FreeBSD, NetBSD does not provide information about the
+ # available instruction set
+ # cpu0 at mainbus0 apid 0: Intel 686-class, 2134MHz, id 0x6f6
-File.open("/var/run/dmesg.boot").each do |line|
- case line
- when /cpu[\d\w\s]+:\s([\w\s\-]+),\s+(\w+),/
- cpuinfo[:model_name] = $1
- cpuinfo[:mhz] = $2.gsub(/mhz/i, "")
- end
-end
+ File.open("/var/run/dmesg.boot").each do |line|
+ case line
+ when /cpu[\d\w\s]+:\s([\w\s\-]+),\s+(\w+),/
+ cpuinfo[:model_name] = $1
+ cpuinfo[:mhz] = $2.gsub(/mhz/i, "")
+ end
+ end
-flags = []
-popen4("dmidecode") do |pid, stdin, stdout, stderr|
- stdin.close
- stdout.each do |line|
- if line =~ /^\s+([A-Z\d-]+)\s+\([\w\s-]+\)$/
- flags << $1.downcase
+ flags = []
+ popen4("dmidecode") do |pid, stdin, stdout, stderr|
+ stdin.close
+ stdout.each do |line|
+ if line =~ /^\s+([A-Z\d-]+)\s+\([\w\s-]+\)$/
+ flags << $1.downcase
+ end
+ end
end
- end
-end
-cpuinfo[:flags] = flags unless flags.empty?
+ cpuinfo[:flags] = flags unless flags.empty?
-cpu cpuinfo
+ cpu cpuinfo
+ end
+end