User Tools

Site Tools


mrtgwithlocalsnmp

MRTG With Local SNMP

If your switch or router won't report SNMP data so you can graph bandwidth usage with MRTG, then you'll have to install an SNMPd to track the bandwidth on your network card.

 1. Grab Net-SNMP from <uri strref="http://www.netsnmp.org"/>

<p> 2. <tt>./configure &amp;&amp; make &amp;&amp; make install</tt></p><p> 3. Edit /usr/local/share/snmp/snmpd.conf and add the following line:</p>

          rocommunity public localhost
 4. Add <tt>/usr/local/sbin/snmpd -r -s -u daemon localhost</tt> to your startup. This will run snmpd as 'daemon' instead of 'root'.
 5. Now you can download the MRTG source package from <uri strref="http://people.ee.ethz.ch/~oetiker/webtools/mrtg/pub/"/>

<p> 6. Follow the installation instructions on <uri strref=“http://people.ee.ethz.ch/~oetiker/webtools/mrtg/unix-guide.html”/></p><p> 7. Optional: create a non-privileged user to run mrtg:</p>

/usr/sbin/useradd -u 110 -d /usr/local/mrtg-2/www -c &quot;MRTG&quot; -m -k /dev/null mrtg
 8. Create the directory /usr/local/mrtg-2/www and /usr/local/mrtg-2/cfg and configure your MRTG:
/usr/local/mrtg-2/bin/cfgmaker --global 'WorkDir: /usr/local/mrtg-2/www' \
--global 'Options[_]: bits,growright' --global 'WithPeak[_]: wmy' --output /usr/local/mrtg-2/cfg/localhost.cfg \
public@localhost
 9. Add the entry into root's cron to run MRTG every 5 minutes to update your graphs:
*/5 * * * * /usr/local/mrtg-2/bin/mrtg /usr/local/mrtg-2/mrtg.cfg --logging /var/log/mrtg.log

In my /var/log/mrtg.log I got:

<pre> 'WARNING: rateup died from Signal 0' </pre> When I tried to run /usr/local/mrtg-2/bin/rateup from the command line it said:

<pre> /usr/local/mrtg-2/bin/rateup: error in loading shared libraries: libgd.so.3: cannot open shared object file: No such file or directory </pre>

    I found libgd.so.3 in /usr/local/lib - so I added that to <tt>/etc/ld.so.conf</tt> and ran <tt>/sbin/ldconfig -v | grep gd</tt> to make sure ld could find that file.
10. Now just set up apache (or a VirtualHost) to point to your <tt>/usr/local/mrtg-2/www</tt> as a DocumentRoot.

<p> To make images work - copy them from /usr/local/mrtg-2/lib/mrtg2/mrtg-* to your <tt>/usr/local/mrtg-2/www</tt> directory. </p><p>Notes:</p><p>When using MRTG for more than one device - I put all .cfg files into a <tt>/usr/local/mrtg-2/cfg</tt> directory, and use this in my crontab:</p>

*/5 * * * * for each in `find /usr/local/mrtg-2/cfg -name \*.cfg`; do /usr/local/mrtg-2/bin/mrtg $each --logging /var/log/mrtg.log; done 

To be even safer - I will put this into a crontab for a role user 'mrtg' so that it doesn't run as root.

To show the date from the epoch seconds found in the first column of the mrtg.log file use: <p><tt>perl -e 'print scalar localtime(x),&quot;\n&quot;'</tt></p>

mrtgwithlocalsnmp.txt · Last modified: 2020/02/13 22:55 (external edit)

free spam filter