no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
— | blog:remote_monitoring_with_rrdtools [2010/01/11 09:59] (current) – created - external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Remote Monitoring with RRDTOOL ====== | ||
+ | |||
+ | Problem: I wanted to monitor HDD temperatures and network statistics of machines on my network and feed all the data back to a central point for storage and charting. | ||
+ | |||
+ | {{: | ||
+ | |||
+ | Reference | ||
+ | * http:// | ||
+ | |||
+ | ===== RRDTOOLS Server ===== | ||
+ | |||
+ | rrdtools in server mode require setting up the following: | ||
+ | |||
+ | **/ | ||
+ | < | ||
+ | # default: on | ||
+ | # description: | ||
+ | service rrdsrv | ||
+ | { | ||
+ | disable | ||
+ | socket_type | ||
+ | protocol | ||
+ | wait = no | ||
+ | user = apache | ||
+ | server | ||
+ | server_args | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We will run the SERVER as a non-privileged user for protection. | ||
+ | |||
+ | < | ||
+ | # mkdir / | ||
+ | # chmod 755 / | ||
+ | </ | ||
+ | |||
+ | Append the following to the **/ | ||
+ | < | ||
+ | # Local services | ||
+ | rrdsrv | ||
+ | </ | ||
+ | |||
+ | Reload XINETD to start this service. | ||
+ | < | ||
+ | [root@elmo xinetd.d]# service xinetd reload | ||
+ | Reloading configuration: | ||
+ | [root@elmo xinetd.d]# | ||
+ | </ | ||
+ | |||
+ | Verify that its up and running | ||
+ | < | ||
+ | [root@elmo xinetd.d]# lsof -i:13900 | ||
+ | COMMAND | ||
+ | xinetd | ||
+ | </ | ||
+ | |||
+ | ===== Remote Server ===== | ||
+ | |||
+ | ==== Database on elmo ==== | ||
+ | |||
+ | Before we create a cron job and start monitoring on **bingo** we need an initialized .RRD database for bingo to log to. We setup the server to log all data into / | ||
+ | |||
+ | Run the following script __once__ on **ELMO** as root: | ||
+ | <code perl> | ||
+ | # | ||
+ | use RRDs; | ||
+ | |||
+ | my $rrd = '/ | ||
+ | |||
+ | & | ||
+ | |||
+ | sub ProcessHDD | ||
+ | { | ||
+ | my($server, | ||
+ | |||
+ | # if rrdtool database doesn' | ||
+ | if (! -e " | ||
+ | { | ||
+ | print " | ||
+ | RRDs:: | ||
+ | "-s 300", | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | This will create the file **/ | ||
+ | < | ||
+ | # chown apache / | ||
+ | </ | ||
+ | |||
+ | ==== Remote logging from bingo ==== | ||
+ | |||
+ | This perl fragment is ran on **BINGO** it will read the temperature of the HDD and make and push the data at an RRD database stored on **ELMO**. | ||
+ | <code perl> | ||
+ | # | ||
+ | # | ||
+ | # rrd_hddtemp.pl | ||
+ | |||
+ | use IO::Socket; | ||
+ | |||
+ | # Remote RRD server and port | ||
+ | my $host = " | ||
+ | my $port = 13900; | ||
+ | |||
+ | my $socket = IO:: | ||
+ | PeerPort=> | ||
+ | Proto=> ' | ||
+ | Type=> SOCK_STREAM) | ||
+ | or die " | ||
+ | |||
+ | & | ||
+ | |||
+ | close $socket; | ||
+ | |||
+ | sub ProcessHDD | ||
+ | { | ||
+ | my($socket, | ||
+ | |||
+ | my $temp=`/ | ||
+ | $temp =~ s/[\n ]//g; | ||
+ | |||
+ | print "/ | ||
+ | |||
+ | print $socket " | ||
+ | $answer = < | ||
+ | print $answer; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Crontab entry on **BINGO** to push data to **ELMO** every 5 mins. | ||
+ | < | ||
+ | */5 * * * * / | ||
+ | </ | ||
+ | |||
+ | ===== Graphing ===== | ||
+ | |||
+ | It wouldn' | ||
+ | |||
+ | This scripts will accept two arguments as part of the URL - the server and harddrive we are charting. | ||
+ | |||
+ | **hddtemp.cgi** - Place this script in / | ||
+ | <code perl> | ||
+ | # | ||
+ | |||
+ | use RRDs; | ||
+ | use CGI qw/: | ||
+ | |||
+ | my $rrd = '/ | ||
+ | my $img = '/ | ||
+ | |||
+ | print header; | ||
+ | |||
+ | $server = param(' | ||
+ | $drive = param(' | ||
+ | |||
+ | if (" | ||
+ | & | ||
+ | } else { | ||
+ | print " | ||
+ | } | ||
+ | |||
+ | sub ProcessHDD | ||
+ | { | ||
+ | my($server, $hdd) = @_; | ||
+ | |||
+ | & | ||
+ | & | ||
+ | & | ||
+ | & | ||
+ | |||
+ | & | ||
+ | } | ||
+ | |||
+ | sub HTML_Page | ||
+ | { | ||
+ | my ($server, $name) = @_; | ||
+ | |||
+ | print start_html(-title=>" | ||
+ | | ||
+ | ' | ||
+ | ' | ||
+ | ), | ||
+ | h1(" | ||
+ | h2(' | ||
+ | h2(' | ||
+ | h2(' | ||
+ | h2(' | ||
+ | end_html; | ||
+ | } | ||
+ | |||
+ | # creates graph | ||
+ | # inputs: $hdd: hdd name (ie, hda, etc) | ||
+ | # | ||
+ | |||
+ | sub CreateGraph | ||
+ | { | ||
+ | my ($server, $hdd, $interval) = @_; | ||
+ | RRDs::graph " | ||
+ | " | ||
+ | "-s -1$interval", | ||
+ | "-t hdd temperature (/ | ||
+ | " | ||
+ | " | ||
+ | "-v degrees C", | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | if ($ERROR = RRDs:: | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Daily Graph (5 minute averages) ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | ==== Daily Graph (30 minute averages) ==== | ||
+ | |||
+ | {{: | ||
+ | |||
+ | {{tag> | ||