I recently wanted to get mrtg (MultiRouterTrafficGrapher) monitoring each of my OS X 10.2.8 Client boxes (e.g. gateway / router / firewall, mail / DNS, webserver, etc.). To do so requires having SNMP running on each of the boxes. As far as I know, SNMP support is built into OS X Server, but not OS X Client. I *thought* I'd heard it's supposed to be "in there," but I'll be darned if I could find it.
So, I decided to look to the open source net-snmp package to get up and running. There's lots of info for UNIX installs on the web -- as expected, virtually identical for OS X. Pre-requisites for an mrtg plus net-snmp install were fairly simple, with install order being:
Login as root @ shell; base of source tree: /usr/ports
Install net-snmp (5.0.9) on each machine you wish to monitor
Reference URL: www.net-snmp.org
Tutorials:
% gnutar zxf net-snmp-5.0.9.tar.gz
% cd /usr/ports/net-snmp-5.0.9
# apply patches:
% patch perl/SNMP/SNMP.xs ../net-snmp-5.0.9-p01-use-numeric.patch
% patch < ../net-snmp-5.0.9-p02-with-perl.patch
unsetenv CFLAGS CPPFLAGS CXX CXXFLAGS LDFLAGS LDDLFLAGS LD_PREBIND;\
unsetenv LC_ALL LANG LINGUAS ;\
setenv CPPFLAGS "-no-cpp-precomp"
./configure \
--prefix=/usr/local \
--with-openssl \
--with-default-snmp-version=3 \
--with-sys-contact=YOUR_NAME@YOURDOMAIN.com
The output should look like:
=========================================================
Net-SNMP configuration summary:
---------------------------------------------------------
Net-SNMP Version: 5.0.9
Building for: darwin6
Network transport support: Callback Unix TCP UDP
SNMPv3 Security Modules: usm
Agent MIB code: mibII ucd_snmp snmpv3mibs notification
target agent_mibs agentx agent_mibs utilities
Authentication support: MD5 SHA1
Encryption support: DES
=========================================================
If that worked, then do:
% make
% umask 022
% make install
% rehash
If you have a pre-existing /etc/snmpd.conf:
% mv /etc/snmpd.conf /etc/snmpd.confORIG
Create a simple /etc/snmpd.conf, you can mod it later as you wish. You can change local_ro_user to whatever you wish, but rememeber to make it consistent in the MRTG config, later. Using your favorite editor (vi /etc/snmpd.conf), insert this one line:
rocommunity local_ro_user
Now check your install with snmpd -v; the output should look like:
NET-SNMP version: 5.0.9 Web: http://www.net-snmp.org/ Email: net-snmp-coders@lists.sourceforge.netStart the daemon with snmpd -c /etc/snmpd.conf, and then test it by typing:
% snmpwalk -v 1 -c local_ro_user localhost systemThe output should look like this:
SNMPv2-MIB::sysORDescr.7 = STRING: The SNMP Management Architecture MIB. SNMPv2-MIB::sysORDescr.8 = STRING: The MIB for Message Processing and Dispatching. SNMPv2-MIB::sysORDescr.9 = STRING: The management information definitions for the SNMP User-based Security Model. SNMPv2-MIB::sysORUpTime.1 = Timeticks: (12) 0:00:00.12 SNMPv2-MIB::sysORUpTime.2 = Timeticks: (12) 0:00:00.12 SNMPv2-MIB::sysORUpTime.3 = Timeticks: (12) 0:00:00.12 SNMPv2-MIB::sysORUpTime.4 = Timeticks: (164) 0:00:01.64 SNMPv2-MIB::sysORUpTime.5 = Timeticks: (304) 0:00:03.04 SNMPv2-MIB::sysORUpTime.6 = Timeticks: (430) 0:00:04.30 SNMPv2-MIB::sysORUpTime.7 = Timeticks: (433) 0:00:04.33 SNMPv2-MIB::sysORUpTime.8 = Timeticks: (433) 0:00:04.33 SNMPv2-MIB::sysORUpTime.9 = Timeticks: (433) 0:00:04.33Now set up an OS X Startup items, and some start, stop, and restart tools ... First, the StartupItem item directory needs to be created:
% mkdir /System/Library/StartupItems/snmpd
Now create a few files in your favorite text editor (here, vi is used as an example...)
% vi /usr/local/bin/netsnmpd_restart
The contents of this file should be:
#!/bin/sh
#
echo "Killing SNMPD"
killall snmpd
/System/Library/StartupItems/snmpd/snmpd
netsnmpd_start:
% vi /usr/local/bin/netsnmpd_start
The contents of this file should be:
#!/bin/sh
#
/System/Library/StartupItems/snmpd/snmpd
netsnmpd_stop:
% vi /usr/local/bin/netsnmpd_stop
The contents of this file should be:
#!/bin/sh
#
echo "Killing Spamd"
killall snmpd
snmpd:
% vi /System/Library/StartupItems/snmpd/snmpd
The contents of this file should be:
#!/bin/sh
. /etc/rc.common
if [ "${NETSNMPD:=-NO-}" = "-YES-" ]; then
ConsoleMessage "Starting NetSNMPd daemon"
/usr/local/sbin/snmpd -c /etc/snmpd.conf
fi
StartupParameters.plist:
% vi /System/Library/StartupItems/snmpd/StartupParameters.plist
The contents of this file should be:
{ Description = "NetSNMPd";
Provides = ("NetSNMPd");
Requires = ("Network","Resolver","Disks");
OrderPreference = "Late";
}
Clean-up permissions for the files ...
% chmod 754 /usr/local/bin/netsnmpd_stop
% chmod 754 /usr/local/bin/netsnmpd_start
% chmod 754 /usr/local/bin/netsnmpd_restart
% chown -R root:wheel /System/Library/StartupItems/snmpd
% chmod 755 /System/Library/StartupItems/snmpd
% chmod 755 /System/Library/StartupItems/snmpd/snmpd
% chmod 644 /System/Library/StartupItems/snmpd/StartupParameters.plist
Enable NETSNMPD launch at startup by adding the following line to your hostconfig. Open host config in your favorite editor (vi /etc/hostconfig), and add this line:
+++ NETSNMPD=-YES-
Reboot your machine, and then check to see if snmpd is active with:
% ps -ax | grep snmpd
INSTALL THESE ONLY ON YOUR WEBSERVER:
% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/cvs/od login
% > password: (RETURN)
% cvs -d :pserver:anonymous@anoncvs.opendarwin.org:/cvs/od co -d dlcompat proj/dlcompat
% unsetenv CFLAGS CPPFLAGS CXX CXXFLAGS LDFLAGS LDDLFLAGS LD_PREBIND
% cd /usr/ports/dlcompat
% autoconf
%./configure \
--prefix=/usr
% make
% make install
libpng-1.2.5:
% unsetenv CFLAGS CPPFLAGS CXX CXXFLAGS LDFLAGS LDDLFLAGS LD_PREBIND
% gnutar zxf libpng-1.2.5.tar.gz
% cd /usr/ports/libpng-1.2.5
% cp /usr/ports/libpng-1.2.5/scripts/makefile.macosx /usr/ports/libpng-1.2.5/makefile
Once that's done, there's a bit of editing to do...
% vi /usr/ports/libpng-1.2.5/makefile
The following changes should be made:
+++ ZLIBLIB=/usr/lib
+++ ZLIBINC=/usr/include
+++ MANPATH=/usr/local/man
--- LDFLAGS=-L. -L$(ZLIBLIB) -lpng -lz -current_version $(PNGVER)
+++ LDFLAGS=-dynamiclib -L. -L$(ZLIBLIB) -lpng -lz -current_version $(PNGVER)
Then just make and make install...
% make
% make install
gd-2.0.15
% unsetenv CFLAGS CPPFLAGS CXX CXXFLAGS LDFLAGS LDDLFLAGS LD_PREBIND LC_ALL LANG LINGUAS ;\
setenv CPPFLAGS "-no-cpp-precomp -I/usr/X11R6/include/freetype2/" ;\
setenv LDFLAGS "-lz -lpng"
% gnutar zxf gd-2.0.15.tar.gz
% cd /usr/ports/gd-2.0.15
% ranlib /usr/local/lib/libpng.a
% ./configure \
--prefix=/usr/local/gd
% make
% make install
NOTE: since you now have CPAN, you might as well make it usable in Perl's CPAN as well:
% cpan> install GD::Text GD::Graph GD::Graph3d HTML::Tagset HTML::Parser File::Spec
mrtg-2.10.5
% unsetenv CFLAGS CPPFLAGS CXX CXXFLAGS LDFLAGS LDDLFLAGS LD_PREBIND LC_ALL LANG LINGUAS
% gnutar zxvf mrtg-2.10.5.tar.gz
% cd /usr/ports/mrtg-2.10.5
% ./configure \
--prefix=/usr/local/mrtg-2 \
--with-gd-lib=/usr/local/gd/lib \
--with-gd-inc=/usr/local/gd/include
% make
% make install
Create a directory in your WebServer document tree for the MRTG-created html files e.g:
% mkdir /Library/WebServer/Documents/mrtg
Create a config directory for MRTG, e.g:
mkdir -p /Library/WebServer/mrtg/cfg
TEST and autocreate a cfg file. Notes:
% /usr/local/mrtg-2/bin/cfgmaker \
--global 'WorkDir: /Library/WebServer/Documents/mrtg' \
--global 'Options[_]: bits,growright' \
--output /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfg \
--snmp-options=:::::3 \
--ifref=descr \
local_ro_user@NAME_OF_SERVER.YOUR_DOMAIN.com
If everything's working, look for the last line of output:
... --base: Writing /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfgNow make a stats directory and copy some stuff into it:
% mkdir /Library/WebServer/Documents/mrtg/stats
% cp /usr/local/mrtg-2/share/doc/mrtg2/*.png /Library/WebServer/Documents/mrtg/stats/ ;\
cp /usr/local/mrtg-2/share/mrtg2/icons/*.png /Library/WebServer/Documents/mrtg/stats/
The autoconfig should do a fine job, but of course, you can always edit each /Library -> WebServer -> mrtg -> cfg -> NAME_OF_SERVER.cfg as desired. Set up cron jobs to refresh MRTG graphs, e.g., every five minutes by adding one line for each (NAME_OF_SERVER) server to /private/etc/crontab:
0-59/5 * * * * root /usr/local/mrtg-2/bin/mrtg /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfg
Run MRTG three times for each server to INITIALIZE
% /usr/local/mrtg-2/bin/mrtg /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfg ;\
/usr/local/mrtg-2/bin/mrtg /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfg ;\
/usr/local/mrtg-2/bin/mrtg /Library/WebServer/mrtg/cfg/NAME_OF_SERVER.cfg
Make an index file in the MRTG website directory for all the servers ...
% /usr/local/mrtg-2/bin/indexmaker \
--output=/Library/WebServer/Documents/mrtg/index.html \
/Library/WebServer/mrtg/cfg/NAME_OF_SERVER_1.cfg \
/Library/WebServer/mrtg/cfg/NAME_OF_SERVER_2.cfg
View your MRTG results in your browser at URL:Mac OS X Hints
http://hints.macworld.com/article.php?story=20031019185335693