System Stats from Ruby?

N

Nick Hird

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
 
D

Daniel Berger

Nick said:
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
 
S

Siep Korteling

Nick said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top