Jump to content

FreeBSD/MRTG

From MattWiki

Installing the ports tree[edit | edit source]

Start out by installing the FreeBSD's Ports system:

portsnap fetch && portsnap extract && portsnap fetch update

Installing MRTG and SNMPD[edit | edit source]

Install SNMPd port with:

cd /usr/ports/net-mgmt/net-snmp; make install

Then install MRTG port with:

cd /usr/ports/net-mgmt/mrtg ; make install

Configure SNMP[edit | edit source]

  • Then copy the code below, and edit to this location: /usr/local/share/snmp/snmpd.conf
################################################## #########################
#
# /usr/local/share/snmp/snmpd.conf
#
################################################## #########################
#
# snmpd.conf
#
# - created by the snmpconf configuration program
#
################################################## #########################
# SECTION: System Information Setup
#
# This section defines some of the information reported in
# the "system" mib group in the mibII tree.

# syslocation: The [typically physical] location of the system.
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysLocation.0 variable will make
# the agent return the "notWritable" error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: location_string

syslocation My Country 

# syscontact: The contact information for the administrator
# Note that setting this value here means that when trying to
# perform an snmp SET operation to the sysContact.0 variable will make
# the agent return the "notWritable" error code. IE, including
# this token in the snmpd.conf file will disable write access to
# the variable.
# arguments: contact_string

syscontact Name - [email protected]

################################################## #########################
# SECTION: Access Control Setup
#
# This section defines who is allowed to talk to your running
# snmp agent.

# rocommunity: a SNMPv1/SNMPv2c read-only access community name
# arguments: community [default|hostname|network/bits] [oid]

rocommunity public localhost

Starting SNMPD[edit | edit source]

Add snmpd_enable= "YES" to /etc/rc.conf and save. Then type /usr/local/etc/rc.d/snmpd start

Configure MRTG using cfgmaker

cfgmaker --global 'WorkDir: /usr/local/www/data-dist/mrtg' --global 'Options[_]: growright,unknaszero' --output /usr/local/www/data-dist/mrtg.cfg public@localhost 
/usr/local/www/data-dist/mrtg = The location you want at your webserver
/usr/local/www/data-dist/mrtg/mrtg.cfg = The location you want of your mrtg.cfg

Edit this to suite your needs. dumburk is the name of my machine. If you wanna change, you need to edit both snmpd.conf and edit cfgmaker command before run.

OK. Now everything should be setup right try run

/usr/local/bin/mrtg /path/to/mrtg.cfg 

Adding the following command to /etc/crontab will update mrtg-graphs every 5th minute.

*/5 * * * * root /usr/bin/env LANG=C /usr/local/bin/mrtg /path/to/mrtg.cfg --logging /var/log/mrtg.log

This guide is a couple of years old, but still works great.