diff options
Diffstat (limited to 'lib/ohai/plugins/darwin/uptime.rb')
-rw-r--r-- | lib/ohai/plugins/darwin/uptime.rb | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/lib/ohai/plugins/darwin/uptime.rb b/lib/ohai/plugins/darwin/uptime.rb index ea258ec4..44011408 100644 --- a/lib/ohai/plugins/darwin/uptime.rb +++ b/lib/ohai/plugins/darwin/uptime.rb @@ -16,17 +16,20 @@ # limitations under the License. # -provides "uptime", "uptime_seconds" +Ohai.plugin(:DarwinUptime) do + provides "uptime", "uptime_seconds" -# kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 + # kern.boottime: { sec = 1232765114, usec = 823118 } Fri Jan 23 18:45:14 2009 -popen4("/usr/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| - stdin.close - stdout.each do |line| - if line =~ /kern.boottime:\D+(\d+)/ - uptime_seconds Time.new.to_i - $1.to_i - uptime seconds_to_human(uptime_seconds) + collect_data do + popen4("/usr/sbin/sysctl kern.boottime") do |pid, stdin, stdout, stderr| + stdin.close + stdout.each do |line| + if line =~ /kern.boottime:\D+(\d+)/ + uptime_seconds Time.new.to_i - $1.to_i + uptime seconds_to_human(uptime_seconds) + end + end end end end - |