Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Monitor 10.2.8 clients using MRTG and NET-SNMP UNIX
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:
  1. On each 'monitored' box:
    • net-snmp
  2. On webserver:
    • dlcompat
    • libpng
    • libgd
    • mrtg
For those interested, I've outlined the how-to steps in the remainder of this hint (it's a cut and paste from a more involved set of tasks, but I think I got rid of any irrelevant dependencies). It takes all of about 30 minutes (with a coffee break!). It ain't pretty, but should be self explanatory. FYI, this works nicely on a different boxes, including a PPC 8500 with Sonnet G3 333MHz CPU upgrade and Asante696 10/100 Ethernet running MacOSX 10.2.8; a Beige G3 with Sonnet G4 500MHz CPU upgrade and Asante696 10/100 Ethernet and MacOSX 10.2.8; and a TiBook G4 800MHz with onboard Ethernet and MacOSX 10.2.8. Oh, and latest Develepor Tools and gcc 3.3 compiler are required, of course ...

I think that's everything. as always, be forwarned, you're monkeying around with a non-standard system ... so, Caveat Emptor!

[robg adds: I have *not* tested this one, nor do I know if anything changes under Panther. I would clearly classify this as an advanced hint -- although detailed, the explanation assumes a certain level of Unix knowledge.]

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: Downloads, including a couple of patches:After downloading, do:

% 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.net
Start the daemon with snmpd -c /etc/snmpd.conf, and then test it by typing:
% snmpwalk -v 1 -c local_ro_user localhost system
The 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.33
Now 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...)

netsnmpd_restart:

% 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:

dlcompat:
reference URL: dlcompat page @ Fink

% 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:
reference URL: dlcompat page @ Fink Downloads: libpng-1.2.5.tar.gz

% 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
Reference URL: GD library web page Downloads: gd-2.0.15.tar.gz

% 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
Reference URL: MRTG web page Downloads: mrtg-2.10.5.tar.gz

% 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:
  • Replace NAME_OF_SERVER & YOUR_DOMAIN, as appropriate
  • Community name here is: local_ro_user, same as in /etc/snmpd.conf, above
  • Setting default SNMP version to "3"
  • Refer to ethernet interfaces by description, e.g., "en0"

% /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.cfg
Now 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:
http://NAME_OF_SERVER.YOUR_DOMAIN.com/mrtg/index.html

Congrats! You're done!
    •    
  • Currently 2.75 / 5
  You rated: 5 / 5 (4 votes cast)
 
[30,243 views]  

Monitor 10.2.8 clients using MRTG and NET-SNMP | 8 comments | Create New Account
Click here to return to the 'Monitor 10.2.8 clients using MRTG and NET-SNMP' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: jpbjpbjpbjpb on Oct 28, '03 08:18:47PM

net-snmp is in fink also. It takes just as long to compile, but you end up with packages you can move to other machines.



[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: LouieNet on Nov 02, '03 03:09:58AM

also in fink is mrtg

---
G4 cube, 1152M RAM, OS X Server 10.2.6



[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: thornrag on Oct 29, '03 03:30:50AM

Getting network statistics is no problem with the cfgmaker script. But what about Mem usage, Disk usage, and CPU usage?

I'm having a difficult time finding the correct OIDs for Mem, Disk, and CPU. Any pointers on where this is documented? Do these OIDs even work in OS X?



[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: alexc on Mar 08, '04 09:52:36PM

Awesome hint. Thank you very much :-)

Its really helped me out.

In the end I used Fink to install SNMP & MRTG.

and I used your guide to help me configure and get SNMP and MRTG going.

Cant thank you enough for writiing this. :-)

All I need to do now is figure out how to make MRTG do the reports I need...

thanks, Alex.



[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: rofl on Mar 15, '04 07:13:24AM

I can't find MRTG anymore in fink, at the website it's there but using the FinkCommander or the fink command tool, there is no MRTG!



[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: rofl on Mar 15, '04 08:20:14AM

ah just forgot to open myself to *unstable* now it runs fine...



[ Reply to This | # ]
A quick mod for libpng
Authored by: sketchy on Aug 17, '04 02:33:07PM
Having just gone through this process using a slightly different hint, a small change is required to the compilation of Libpng. 1.2.5 is no longer available (due to vulnerabilities) so use 1.2.6 instead.

Under 1.2.6 there is no makefile.macosx so use makefile.darwin instead.

Just my $0.02

[ Reply to This | # ]
Monitor 10.2.8 clients using MRTG and NET-SNMP
Authored by: weez on Dec 07, '04 04:10:00PM

This article is awesome, I could never have done this procedure on my own without this guide. I managed to find all the required parts using darwinports on OSX 10.3, and no problems thus far. Next step is to customize it for displaying icecast stats!



[ Reply to This | # ]