Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[OHAI-279] CPU plugin for MacOSX/Darwin #98

Closed
wants to merge 1 commit into from

4 participants

@dmytro

Plugin implements simple CPU information collection for MacOSX/Darwin. As given a ticket it uses output of sysctl -a hw command.

@btm
Owner
btm commented

Thank you for taking the time to help make Chef better! We require a Contributor License Agreement (CLA) from contributors to help protect all Chef users. It is easy to complete one online. Instructions to do so are on our wiki, which is linked below. Once your account is updated, you will have access to 'resolve' tickets that indicates to the code review team that your contribution is ready for review.

http://wiki.opscode.com/display/chef/How+to+Contribute

http://tickets.opscode.com/browse/OHAI-279

@patcon

Hey @dmytro, this looks awesome! Would you be able to sign the CLA? From reading your recent comment on the ticket, I wasn't able to tell whether you were planning to sign it :)

@dmytro
@patcon

Ah gotcha. That's great! You can have a JIRA account without signing the CLA -- unless something has changed since I went through the process

@dmytro
@patcon patcon referenced this pull request in myplanetdigital/vagrant-ariadne
Open

Auto-detect number of cpu cores #33

@pawelpacana

Would love to have this merged. Whats else needs to be done here?

@btm
Owner

Fixed by #141

@btm btm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2012
  1. @dmytro
This page is out of date. Refresh to see the latest.
Showing with 35 additions and 0 deletions.
  1. +35 −0 lib/ohai/plugins/darwin/cpu.rb
View
35 lib/ohai/plugins/darwin/cpu.rb
@@ -0,0 +1,35 @@
+#
+# Author:: Dmytro Kovalov (<dmytro.kovalov@gmail.com>)
+# Copyright:: Copyright (c) 2012, Dmytro Kovalov
+# 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.
+#
+
+provides "cpu"
+
+cpuinfo = Mash.new
+cpu_number = 0
+
+
+IO.popen("sysctl -a hw").each do |line|
+ next unless line =~/^hw\..*cpu.*:\s*\d+/
+ key,val = line.strip.split /\s*:\s*/
+ key.sub!(/^hw\./, '')
+ cpuinfo[key.to_sym] = val
+
+end
+
+cpu cpuinfo
+cpu[:total] = cpuinfo[:ncpu].to_i
+cpu[:real] = cpuinfo[:physicalcpu].to_i
Something went wrong with that request. Please try again.