Monitoring a RAID controller on a remote machine with MRTG
In this post, I’ll show you how, using MRTG and xinetd, I set up monitoring of the temperature of a RAID controller on a remote machine. I use the same technique to also graph the temperatures of the individual hard drives in the RAID array as well, and it can be used to graph just about anything.
DISCLAIMER: This is how I did it, and it works for me. You are responsible for whatever you do with your machines, including screwing them up. This HOWTO assumes a reasonable level of proficiency with Linux. For instance, I’m not going to show you how to locate or install packages, or teach you how to use a text editor. Proceed at your own risk.
- IP: 172.16.0.2
- CentOS 6.5
- IP: 172.16.0.3
- LSI MegaRAID 9266-8i
- Debian 7.5.0
It’s assumed that MegaCli is installed and working on the RAID system, as well as any/all the other packages required to implement this setup. You may need to install some things as you go. If you’re using different operating systems, you’ll need to adjust these instructions accordingly.
On the RAID system, create a perl script that collects the temperature and generates output in MRTG-friendly format. On my system, this script is a bit more complex, as I’ve written it to notify me by email if the temperature crosses a certain threshold. For simple graphing, the script below should be sufficient.
$megacli = '/opt/MegaRAID/MegaCli/MegaCli64';
$controller_num = '0';
$uptime = '/usr/bin/uptime';
$hostname = '/bin/hostname';
### get raid temp
@data = grep /^ROC temperature : /, `$megacli -AdpAllinfo -a$controller_num`;
$temp = $data;
$temp =~ s/ROC temperature : //;
$temp =~ s/ degree Celsius//;
### get system uptime
$upt = `$uptime`;
$upt =~ s/^.*? up //;
$upt =~ s/,[\s]+[0-9]+ user.*$//;
### get hostname
$host = `$hostname`;
### generate output
Be sure to set/verify the options in the config section, and if you’re copying and pasting, check that WordPress didn’t mess up the backticks or the quotes. There should be two spaces before “degree Celsius”. Save the script (I saved it as /usr/local/sbin/mrtg-raidtemp), make it executable and test it. It should produce output resembling this:
2 days, 16:15
Now we have to configure the system to allow access to this script remotely. I do this through xinetd. Here’s how.
Create the file /etc/xinetd.d/raidtemp, and paste the following into it, editing it as necessary (script location, port, etc):
disable = no
socket_type = stream
protocol = tcp
port = 12345
log_on_success += USERID
log_on_failure += USERID
server = /usr/local/sbin/mrtg-raidtemp
user = root
instances = UNLIMITED
wait = no
log_type = SYSLOG daemon debug
Save the file. Now open the file /etc/services, and add the following to the end:
raidtemp 12345/tcp # get raid temp for mrtg
Make sure to use the same port you used in the xinetd file. Restart xinetd and configure your firewall to allow connections to that port. You should now be able to telnet to your RAID system on that port and see the MRTG-friendly output. If so, continue. If not, figure out why and fix it.
On the MRTG system, we first need to create a helper script for MRTG to get the data from the RAID system. Create a file (I use /usr/local/sbin/mrtg-raidtemp) and add the following, changing the IP and port as needed:
$| = 1;
$socket = new IO::Socket::INET (
PeerHost => '172.16.0.3',
PeerPort => '12345',
Proto => 'tcp',
) or die "ERROR in socket creation: $!";
Save the file and make it executable. Run the script – you should see the MRTG output from the remote machine. If not, find out why and fix it (I would start with the firewall).
Now we need to configure MRTG to create the graphs. Create the file /etc/mrtg/raidtemp.cfg and add the following, editing the options as needed:
Title[raidtemp]: Temperature of RAID controller on raidhost
PageTop[raidtemp]: <h1>Temperature of RAID controller on raidhost</h1>
PNGTitle[raidtemp]: Temperature of RAID Controller
YLegend[raidtemp]: Degrees C
Save the file. Now open mrtg.cfg and add the following:
Save the file.
That’s it! After 10 minutes, you should see graphs being produced. Don’t forget to run indexmaker.