System Stats from Ruby?

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

Nick H. 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

The sysutils project has some things you’ll want:

http://www.rubyforge.org/projects/sysutils

Regards,

Dan

Nick H. 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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs