0

I've been tasked with writing a script that will run on a server every few hours to log the cpu usage, memory, and disk utilization. This script will be run on windows and linux boxes. I chose ruby for this task. I am new to scripting. I have googled without success. Help me?

  • I must write a script because I'm calling a web service with the information. – Becky Jul 30 '09 at 0:59
1

First of all, if you're doing some systema administration with ruby, you should read Practical ruby for system administration.

Then I think that you have, at least, two options:

  • The script will run on every system and call the web service
  • The script will run on a monitoring machine that will poll each of the machines and then call the web service

If you were to use the first option, you should create an data gathering class and a data sending class. The former should be operating system dependent, but with the same methods. In that case you can use system to launch system commands and get the desired data. Otherwise you can use rush to get more advance data.

For the second option you can use SNMP from a central location. Of course, that means activating SNMP on your servers (securely!!).

Reading a bit more, it seems that there is some support for Windows on rush. And there's a rushd deamon that can be used to access remotely the machine a execute local commands.

servers = %w(www1 www2 www3).map { |n| Rush::Box.new(n) }
servers.each do |s| 
  s.bash 'df -h'
end
| improve this answer | |
1
  • The script will look completely different on Windows and Linux unless you can find a specialized library. That I know of, Ruby doesn't have access to these stats directly, so you'll have to call external programs to do it.
  • If you've got a space (NFS, for example) to which you can write from your entire network, it will make your life easier.
  • If you use Nagios, then NRPE and n2rrd are your friends. If not, you might still want to look at NRPE as it is designed for this type of stuff. NRPE available from the Nagios website and n2rrd is available at this link.
  • If you're not using Nagios, then a cron job is probably your best bet on getting the script to run somewhat regularly.
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy