From: Siep Korteling Date: 2010-03-05T23:28:32+09:00 Subject: Re: System Stats from Ruby? Nick Hird wrote: > I am new to ruby but am working hard to learn all i can. Is there a > way to get system information from ruby on windows? I am looking to > get some data to make a system monitor type of thing. Data like conky > or samurize have. Just not as crazy, just things like total memory and > used memory, hard drive space and network usage, stuff like that. > Thanks for the help! > -Nick For a windows-only solution I'd recommend ruby-wmi (gem install rdp-ruby-wmi if you are using ruby 1.9, don't know why ). You can get to WMI via win32ole, like this: require 'win32ole' wmi_classes = %w(Win32_BIOS Win32_BootConfiguration Win32_ComputerSystem Win32_LogicalDisk) computername = '.' wmi = WIN32OLE.connect("winmgmts://#{computername}/root/cimv2") wmi_classes.each do |wmi_class| puts wmi_class wmi_objects = wmi.ExecQuery("select * from #{wmi_class}") wmi_objects.each do |wmi_obj| wmi_obj.properties_.each do |prop| puts "#{prop.name}\t#{prop.value}" if prop.value end end puts "_"*60 end ruby_wmi is cleaner, it handles the connection and the querying syntax. require 'ruby-wmi' c_drive = WMI::Win32_PerfRawData_PerfDisk_LogicalDisk.find :first, :conditions => {'Name' => 'C:'} puts 'C percent free:', c_drive.PercentFreeSpace.to_f*100/c_drive.PercentFreeSpace_Base hth, Siep Attachments: http://www.ruby-forum.com/attachment/4539/wmi.rb -- Posted via http://www.ruby-forum.com/.