<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Technology: Learn and Share &#187; SNMP</title>
	<atom:link href="http://crazytoon.com/category/snmp/feed/" rel="self" type="application/rss+xml" />
	<link>http://crazytoon.com</link>
	<description>Enterprise level solutions, LAMP, Linux, Apache, MySQL, PHP, Perl, Windows, Cache, Optimization</description>
	<lastBuildDate>Fri, 16 Jul 2010 20:24:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>MRTG (Multi Router Traffic Grapher):  How to setup MRTG in Linux to monitor Bandwidth usage?</title>
		<link>http://crazytoon.com/2007/05/01/mrtg-multi-router-traffic-grapher-how-to-setup-mrtg-in-linux-to-monitor-bandwidth-usage/</link>
		<comments>http://crazytoon.com/2007/05/01/mrtg-multi-router-traffic-grapher-how-to-setup-mrtg-in-linux-to-monitor-bandwidth-usage/#comments</comments>
		<pubDate>Wed, 02 May 2007 01:46:19 +0000</pubDate>
		<dc:creator>Sunny Walia</dc:creator>
				<category><![CDATA[Enterprise level solutions]]></category>
		<category><![CDATA[Linux System]]></category>
		<category><![CDATA[Linux Tips]]></category>
		<category><![CDATA[MRTG]]></category>
		<category><![CDATA[SNMP]]></category>
		<category><![CDATA[System admin]]></category>

		<guid isPermaLink="false">http://crazytoon.com/2007/05/01/mrtg-multi-router-traffic-grapher-how-to-setup-mrtg-in-linux/</guid>
		<description><![CDATA[If you run Linux server, there are times you probably wonder how much traffic is flowing through your server.  It could be you got a fat bill from your ISP because you used too much bandwidth (good problem to have most of the time).  At that point, you probably want to monitor how [...]]]></description>
			<content:encoded><![CDATA[<p>If you run Linux server, there are times you probably wonder how much traffic is flowing through your server.  It could be you got a fat bill from your ISP because you used too much bandwidth (good problem to have most of the time).  At that point, you probably want to monitor how much bandwidth you are using.  One of the best tools you can use is <a href="http://www.mrtg.com" title="MRTG (Multi Router Traffic Grapher)" target="_blank">MRTG </a>(Multi Router Traffic Grapher).  It is not very hard to setup MRTG and requires only few packages to be installed.</p>
<p>Assumptions:</p>
<ol>
<li>Linux server with Yum installed (of course you can download individual packages in other flavors of Linux which I am not going into details here).</li>
<li> Your server ip is on 192.x.x.x network.  If your server is not, please replace all the places where I mention using 192.x.x.x)</li>
<li>We are going to store files in /home/vhosts/mrtg  If you want a different location, change it in all appropriate places.</li>
<li>Apache is installed at:  /usr/local/apache2/ with httpd.conf in conf directory in Apache installed directory.</li>
<li>SNMP/MRTG packages are not installed.</li>
<li>Server IP is 192.168.30.115</li>
<li>Last but not least, YOU are logged in as <strong>root</strong>!</li>
</ol>
<p>Ok now let us go into details on how to install MRTG.</p>
<p>Lets install all the packages we need.  Note that this will also install few other packages.  Eg. gd, lm_sensors, net-snmp-libs, etc<br />
<code>yum -y install mrtg net-snmp-utils net-snmp</code></p>
<p>Now lets start SNMP server<br />
<code>/etc/init.d/snmpd start</code></p>
<p>Is SNMP running?  You should see something after you run following command<br />
<code>netstat -na | grep '0.0.0.0:199'</code></p>
<p>If it is not working, check logs and see why not. If it is (which is most probably the case if you didn&#8217;t miss the second step), try this command and see if you get output:<br />
<code>snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex </code><br />
OUTPUT (something similar, your 192.x.x.x ip should be your server ip):<br />
<code>IP-MIB::ipAdEntIfIndex.127.0.0.1 = INTEGER: 1<br />
IP-MIB::ipAdEntIfIndex.192.168.30.115 = INTEGER: 2</code></p>
<p>If you don&#8217;t get the above or something similar output, do following.<br />
NOTE:  I had to do following on all the servers I had setup:<br />
<code>vi /etc/snmp/snmpd.conf</code><br />
Replace the content in there with following:<br />
<code>com2sec local          localhost        public<br />
com2sec mynetwork 192.0.0.0/8      public<br />
group   MyRWGroup      v1          local<br />
group   MyRWGroup      v2c         local<br />
group   MyRWGroup      usm       local<br />
group   MyROGroup      v1          mynetwork<br />
group   MyROGroup      v2c         mynetwork<br />
group   MyROGroup      usm       mynetwork<br />
view    all            included      .1              80<br />
access MyROGroup ""      any       noauth    exact  all    none   none<br />
access MyRWGroup ""      any       noauth    exact  all    all    none<br />
syslocation "Some place out there"<br />
syscontact Admin &lt;admin@domain.com&gt;</code><br />
You should change last two lines to something appropriate to your usage.</p>
<p>At this point you should be good to go, so lets restart SNMP.<br />
<code>/etc/init.d/snmpd restart</code><br />
Run this command look for appropriate output as mentioned above.<br />
<code>snmpwalk -v 1 -c public localhost IP-MIB::ipAdEntIfIndex</code></p>
<p>Ok.  That is all we will do with SNMP.  Let us continue our MRTG installation.</p>
<p>Let us set up data directory to store html files:<br />
<code>mkdir /home/vhosts/mrtg</code></p>
<p>Now let us set up mrtg.conf to use for monitoring bandwidth usage:<br />
<code>cfgmaker --global "workdir: /home/vhosts/mrtg" -ifref=ip --output /etc/mrtg/mrtg.cfg --global 'options[_]: growright,bits' public@localhost </code></p>
<p>Let us create index file for MRTG page:<br />
<code>indexmaker --output=/home/vhosts/mrtg/index.html /etc/mrtg/mrtg.cfg</code></p>
<p>It is time for us to tell Apache to serve these pages<br />
<code>vi /usr/local/apache2/conf/httpd.conf</code><br />
<code>Alias /mrtg /home/vhosts/mrtg<br />
&lt;location /mrtg&gt;<br />
Order deny,allow<br />
Deny from all<br />
Allow from 127.0.0.1 192.168.30.0/24<br />
&lt;/location&gt;</code></p>
<p>NOTE: Make sure your subnet is in &#8220;Allow from &#8221; line.  Otherwise you won&#8217;t be able to access MRTG files from browser.<br />
Restart Apache to read the new conf file.<br />
<code>/usr/local/apache2/bin/apachectl graceful</code></p>
<p>It is time for us fire this thing up and start creating some graphs!<br />
<code>env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log</code></p>
<p>You should be able to view your MRTG graphs at:  http://192.168.30.115/mrtg</p>
<p>If everything is working fine, let us add this to cron so these stats are updated every 5 mins.<br />
<code>crontab -e</code><br />
<code>*/5 * * * * env LANG=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg --logging /var/log/mrtg.log</code></p>
]]></content:encoded>
			<wfw:commentRss>http://crazytoon.com/2007/05/01/mrtg-multi-router-traffic-grapher-how-to-setup-mrtg-in-linux-to-monitor-bandwidth-usage/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
