1

In the OpsCode Wiki there is there following documentation:

require 'ohai'

# ...
# Profit! ;-)

How can I print the JSON data provided by the 'ohai' command but using IRB? I tried to see the code in application.rb but I get empty data.

require 'ohai/application'
ohai = Ohai::System.new
ohai.json_pretty_print
 => "{\n\n}" 

I am not trying to do this within Chef (or Shef), I just want to use the ohai gem itself, in my own app.

Draco Ater
  • 20,820
  • 8
  • 62
  • 86
rtacconi
  • 14,317
  • 20
  • 66
  • 84

2 Answers2

6

Poking about in the Ohai::Application class (what you get when you run ohai), #run_application instantiates Ohai::System and, unless it was configured by a file, it calls all_plugins to populate it with data.

Presumably, Ohai::System#all_plugins delegates the data collection to the lib/ohai/plugins directory.

$ irb -rohai
> system = Ohai::System.new
 => #<Ohai::System:0x00000100988950 @data={}, @seen_plugins={}, @providers={}, @plugin_path="", @hints={}> 
> system.all_plugins
 => true 
> puts system.to_json
{"languages":{"ruby":{"platform":"x86_64-darwin10.8.0","version":"1.9.2", ...
> system.to_json.size
 => 42395 
willglynn
  • 11,210
  • 48
  • 40
2

I too searched for a simple and good library to do that...

I came across

Usagewatch

and after 5 minutes had my monitoring.rb done..

Install : gem install usagewatch

Install on mac : gem install usagewatch_ext

Refer to this article for more info

Refael
  • 1,252
  • 9
  • 10