A System Monitoring Dashboard
Listing 1. smtp.pl tests outgoing mail through the SMTP server.
#!/usr/bin/perl -w # # Title : smtp.pl # Author : John_Ouellette@yahoo.com # Files : smtp.pl # Pupose : Send email through SMTP server # Called from monitor_smtp.sh # # Submit as use Net::SMTP; my $rcpt = $ARGV || 'mygroup@somewhere'; my $sender = $ARGV || 'root@host01'; my $host = $ARGV; #Start Script my $smtp =Net::SMTP->new($host, Debug => 1); my $input="test msg for server $host"; $smtp->mail("$sender"); $smtp->to("$rcpt"); $smtp->data(); $smtp->datasend("To: $rcpt\n") ; $smtp->datasend("From: $sender\n") ; $smtp->datasend("Subject: $host test\n") ; $smtp->datasend("$input"); $smtp->dataend(); $smtp->quit;
Do I Have That Perl Module Installed?
An easy way to check whether you have any Perl module installed is by issuing this from the command line:
$ perl -e "use Net::SMTP";
If nothing prints, you have that module installed. If you're missing the module, you get an error that looks like this:
$perl -e "use Net::OTHER"; Can't locate Net/OTHER.pm in @INC (@INC contains: /usr/lib/perl5/5.8.3/i386-linux-thread-multi /usr/lib/perl5/5.8.3 /usr/lib/perl5/vendor_perl/5.8.0 /usr/lib/perl5/vendor_perl .) at -e line 1. BEGIN failed--compilation aborted at -e line 1.
This error indicates a lack of the module in question.
Finally, we come to our stats script, monitor_stats.pl. This script logs in to each host and runs the commands:
df -k swapon -s top -n 1 | head -n 20 hostname uptime
It then displays the results in a browser (Figure 2) and saves the result in a log, again sorted by date on the filesystem. It serves as a simple dashboard to give quick stats on each server.
The benefit of this monitoring design is threefold:
We have a history of CPU, disk and swap usage, and we easily can pinpoint where problems may have occurred.
Tedious typing to extract this information for each server is reduced. This comes in handy before leaving work to resolve potential problems before getting paged at night.
Management quickly can see how well we're doing.
We are using the insecure rsh protocol in this script to show you how to get this set up quickly, but we recommend that you use SSH with properly distributed keys to gain security.
With the use of this new system monitoring dashboard, my team's productivity has increased and and its confidence in monitoring has soared, because we no longer are wasting time chasing down false positives. A history of system performance has been a real time saver in diagnosing problems. Finally, easy installation allows users with basic skills to conquer a complex system administration problem in one business day.
Resources for this article: /article/8269.
John Ouellette is a system administrator with nine years of experience in Microsoft Windows NT and UNIX. He believes the command line is king and loves chicken parmigiana. He can be reached at email@example.com.
Special Reports: DevOps
Have projects in development that need help? Have a great development operation in place that can ALWAYS be better? Regardless of where you are in your DevOps process, Linux Journal can help!
With deep focus on Collaborative Development, Continuous Testing and Release & Deployment, we offer here the DEFINITIVE DevOps for Dummies, a mobile Application Development Primer, advice & help from the experts, plus a host of other books, videos, podcasts and more. All free with a quick, one-time registration. Start browsing now...
- The Ubuntu Conspiracy
- A First Look at IBM's New Linux Servers
- Vigilante Malware
- Disney's Linux Light Bulbs (Not a "Luxo Jr." Reboot)
- Libreboot on an X60, Part I: the Setup
- System Status as SMS Text Messages
- Bluetooth Hacks
- Vagrant Simplified
- Dealing with Boundary Issues
- Non-Linux FOSS: Code Your Way To Victory!