{"id":1166,"date":"2013-08-18T19:43:25","date_gmt":"2013-08-18T23:43:25","guid":{"rendered":"https:\/\/infotechguy.net\/?p=1166"},"modified":"2025-02-22T11:31:21","modified_gmt":"2025-02-22T16:31:21","slug":"mrtg-in-minutes","status":"publish","type":"post","link":"https:\/\/infotechguy.net\/?p=1166","title":{"rendered":"Linux &#8212; MRTG in Minutes!"},"content":{"rendered":"<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Multi_Router_Traffic_Grapher\" target=\"_blank\" rel=\"noopener noreferrer\">MRTG<\/a> is one of those tools a Network Engineer has on his\/her toolbelt. MRTG allows the graphing of trending network activity for a wide range of devices. It uses <a href=\"http:\/\/en.wikipedia.org\/wiki\/Simple_Network_Management_Protocol\" target=\"_blank\" rel=\"noopener noreferrer\">SNMP<\/a> to query a host and poll it&#8217;s network information and statistics. It can be used with Routers, Switches, Linux Hosts, etc.<br \/>\n<img decoding=\"async\" src=\"http:\/\/s6.postimg.org\/4hkcn4we9\/mrtg1.png\" alt=\"\" \/><\/p>\n<p>I&#8217;m going to run MRTG against a Linux Router(running IPtables), a HP PowerConnect Switch, a Cisco Router, and an ESXi host. Anyway&#8230;.Let&#8217;s get started.<\/p>\n<p><!--more--><\/p>\n<h3>Prepare SNMP Devices<\/h3>\n<ul>\n<li>\n<h4>Linux Router &#8211;Install SNMPd on the Linux Host being used as a router.<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">apt-get install snmpd<\/pre>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">vi \/etc\/snmp\/snmpd.conf\n\n#Paste in the follow:\n\ncom2sec local localhost public\ncom2sec mynetwork 10.0.0.0\/24 public\n\ngroup MyRWGroup v1         local\ngroup MyRWGroup v2c        local\ngroup MyRWGroup usm        local\ngroup MyROGroup v1         mynetwork\ngroup MyROGroup v2c        mynetwork\ngroup MyROGroup usm        mynetwork\n\nview all included .1    80\n\naccess MyROGroup \"\"      any       noauth    exact  all    none   none\naccess MyRWGroup \"\"      any       noauth    exact  all    all    none\n\nsyslocation Linux (RH3_UP2), Home Linux Router.\nsyscontact Jim &lt;jim@techjockey.net&gt;\n<\/pre>\n<p><i>What we are doing here is setting up the default settings for SNMPd. <b>local<\/b> is the Read\/Write group profile, which will only be localhost. <b>mynetwork<\/b> is the Read Only group profile, which will be accessable by any host address on the 10.0.0.0\/24.<\/i><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">service snmpd restart<\/pre>\n<\/li>\n<li>\n<h4>PowerConnect Switch<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">SW1# conf t\nSW1(conf)# snmp-server 10.0.0.9\nSW1(conf)# snmp-server community public ro view Default\nSW1(conf)# exit\nSW1# copy running-config startup-config <\/pre>\n<p><b>Note:<\/b><i>We are setting the snmp server IP and the community string of public to Read Only.This way when MRTG trys to query SNMP statistics it will have permissions to read the Switch&#8217;s metrics.<\/i><\/li>\n<li>\n<h4>Cisco Switch\/Router<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">Router# conf t\nRouter(config)# snmp-server community public RO \nRouter(config)# snmp-server host 10.0.0.9\nRouter(config)# end\nRouter# wr me<\/pre>\n<p><i>Very similar to PowerConnect Switch<\/i><\/li>\n<li>\n<h4>ESXi 5.1 Host<\/h4>\n<ol>\n<li><b>Get the current Community<\/b>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">esxcli system snmp get\n   Authentication: \n   Communities: public\n   Enable: false\n   Engineid: 00000063000000a1c0a8000a\n   Hwsrc: indications\n   Loglevel: info\n   Notraps: \n   Port: 161\n   Privacy: \n   Remoteusers: \n   Syscontact: \n   Syslocation: \n   Targets:\n   Users: \n   V3targets: \n<\/pre>\n<p>Notice, SNMP is currently not enabled. So we need to enable it :-p<\/li>\n<li><b>Enable SNMP<\/b>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">esxcli system snmp set --enable 1\nesxcli system snmp set --communities public --targets 10.0.0.9\nesxcli system snmp test<\/pre>\n<p>This will configure the ESXi host to use community public and trust 10.0.0.9<\/li>\n<\/ol>\n<\/li>\n<\/ul>\n<h3>Setting up the MRTG Collector<\/h3>\n<ol>\n<li style=\"list-style-type: none;\">\n<ol>\n<li>\n<h4>First off, install MRTG:<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">apt-get install mrtg apache2<\/pre>\n<\/li>\n<li>\n<h4>Create a MRTG config for each Device<\/h4>\n<p>Run the <b>cfgmaker<\/b> command to auto populate the cfg for this type of host. This will create a config file for this device type&#8230;.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">cfgmaker --global \"WorkDir: \/var\/www\/mrtg\/router\" --output \/etc\/mrtg.d\/router.cfg --ifref=name public@10.0.0.1<\/pre>\n<p><i>We assume 10.0.0.1 is our Router<\/i><\/li>\n<li>\n<h4>Create an Index.html page for each Device<\/h4>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">indexmaker --output \/var\/www\/mrtg\/router\/index.html \/etc\/mrtg.d\/router.cfg \nenv LANG=C mrtg \/etc\/mrtg.d\/router.cfg <\/pre>\n<p><b>Notice<\/b>, The indexmaker reads the MRTG config file that you made above and creates HTML to present the graphs for each interface.<\/li>\n<li>\n<h4>Configure CRON job to periodically poll each Device<\/h4>\n<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">vi \/etc\/cron.d\/mrtg\n#Paste the following for each device:\n\/5 * * * * root env LANG=C mrtg \/etc\/mrtg.d\/router.cfg\n<\/pre>\n<p><b>Notice<\/b>, the above line sets a cron job to run every 5 minutes and run MRTG using configuration file router.cfg. So if you have multiple devices, just add a new line for each one.<\/p>\n<p>Sources:<\/p>\n<ul>\n<li><a href=\"http:\/\/oss.oetiker.ch\/mrtg\/doc\/cfgmaker.en.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/oss.oetiker.ch\/mrtg\/doc\/cfgmaker.en.html<\/a><\/li>\n<li><a href=\"http:\/\/www.my-guides.net\/en\/guides\/linux\/how-to-install-mrtg-under-linux\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.my-guides.net\/en\/guides\/linux\/how-to-install-mrtg-under-linux<\/a><\/li>\n<li><a href=\"http:\/\/write.keinism.com\/2008\/02\/29\/create-new-mrtg-graph-8-steps\/\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/write.keinism.com\/2008\/02\/29\/create-new-mrtg-graph-8-steps\/<\/a><\/li>\n<li><a href=\"http:\/\/www.cyberciti.biz\/nixcraft\/linux\/docs\/uniqlinuxfeatures\/mrtg\/mrtg_config_step_7.php\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.cyberciti.biz\/nixcraft\/linux\/docs\/uniqlinuxfeatures\/mrtg\/mrtg_config_step_7.php<\/a><\/li>\n<li><a href=\"http:\/\/www.debianadmin.com\/mrtg-installation-and-configuration-in-debian-based-distributions-2.html\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.debianadmin.com\/mrtg-installation-and-configuration-in-debian-based-distributions-2.html<\/a><\/li>\n<li><a href=\"http:\/\/www.debianhelp.co.uk\/mrtg.htm\" target=\"_blank\" rel=\"noopener noreferrer\">http:\/\/www.debianhelp.co.uk\/mrtg.htm<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>MRTG is one of those tools a Network Engineer has on his\/her toolbelt. MRTG allows the graphing of trending network activity for a wide range of devices. It uses SNMP to query a host and&#46;&#46;&#46;<\/p>\n","protected":false},"author":2,"featured_media":4240,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[111],"class_list":["post-1166","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","tag-scripting"],"_links":{"self":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1166","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1166"}],"version-history":[{"count":1,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions"}],"predecessor-version":[{"id":4167,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/posts\/1166\/revisions\/4167"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=\/wp\/v2\/media\/4240"}],"wp:attachment":[{"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/infotechguy.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}