# System Stats from Ruby?

**URL:** <https://www.ruby-forum.com/t/system-stats-from-ruby/184599>\
**Category:** Ruby\
**Created:** [March 5, 2010, 2:27am UTC](https://www.ruby-forum.com/t/system-stats-from-ruby/184599 "2010-03-05T02:27:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [March 5, 2010, 2:27am UTC](https://www.ruby-forum.com/t/system-stats-from-ruby/184599/1 "2010-03-05T02:27:56Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [March 5, 2010, 12:51pm UTC](https://www.ruby-forum.com/t/system-stats-from-ruby/184599/2 "2010-03-05T12:51:15Z")

</div>

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](http://www.rubyforge.org/projects/sysutils)

Regards,

Dan

---

<div class="post-metadata">

**Author:** ![nickh](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/7ea924/32.png) [@nickh](https://www.ruby-forum.com/u/nickh)\
**Post date:** [March 5, 2010, 3:28pm UTC](https://www.ruby-forum.com/t/system-stats-from-ruby/184599/3 "2010-03-05T15:28:30Z")

</div>

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
