MRTG Network Traffic View and Analytics
Simple Network Management Protocol (or SNMP) can be used for traffic monitoring. All you need on the SNMP device end (switch, NIC, etc) is a so called community password. It's easy to find it under SNMP settings on whatever device you're going to monitor. If you don't have access, the default on most devices is 'public'. This article is Windows based, check MTRG docs for *nix.
Alternatively, check out PRTG.
1. Get MTRG from here.
2. Get PERL from here.
3. Extract MTRG somewhere you want and make sure perl is in your environment path.
4. Run config for your devices:
c:\somwhere\bin\perl cfgmaker public@IP --global "WorkDir: c:\somewhere\mtrgdata" --output Switch1.cfg c:\somwhere\bin\perl cfgmaker public@IP2 --global "WorkDir: c:\somewhere\mtrgdata" --output Server1.cfg c:\somwhere\bin\perl cfgmaker public@IP3 --global "WorkDir: c:\somewhere\mtrgdata" --output Computer1.cfg etc...
If you want to leave CMD open and run with 5 minute (default) intervalls:
1. Put 'RunAsDaemon: Yes' and 'Interval: 5' into .cfg files.
2. C:\somewhere\bin\perl mrtg --logging=eventlog devicename.cfg
Example boot script:
@ECHO OFF MODE CON:COLS=50 LINES=10 TITLE MTRG Service Start COLOR 17 start /D "c:\mrtg-2.17.4\bin" wperl mrtg --logging=eventlog ovreswitch.cfg start /D "c:\mrtg-2.17.4\bin" wperl mrtg --logging=eventlog nedreswitch.cfg start /D "c:\mrtg-2.17.4\bin" wperl mrtg --logging=eventlog serverswitch.cfg
Use insserv.exe, taskschd.msc or something else for setting up automation however you like beyond this.
HTML files will be generated per port in WorkDir. I wrote a quick php script that I run as a shortcut:
php c:\somwhere\mtrgdata\checkports.php
It then creates a index.html for me with a list similar to this (example, non-working links):
Switch1 Active Ports 192.168.1.201_5001.html < this one works as example output, not much data but shows layout. 192.168.1.201_5002.html 192.168.1.201_5003.html 192.168.1.201_5004.html 192.168.1.201_5005.html 192.168.1.201_5006.html 192.168.1.201_5007.html 192.168.1.201_5008.html 192.168.1.201_5011.html 192.168.1.201_5012.html 192.168.1.201_5017.html 192.168.1.201_5021.html 192.168.1.201_5023.html 192.168.1.201_5024.html Switch2 Active Ports 192.168.1.202_5001.html 192.168.1.202_5002.html 192.168.1.202_5003.html 192.168.1.202_5007.html 192.168.1.202_5009.html 192.168.1.202_5010.html 192.168.1.202_5011.html 192.168.1.202_5013.html 192.168.1.202_5015.html 192.168.1.202_5023.html 192.168.1.202_5024.html Switch3 Active Ports 192.168.1.203_1.html 192.168.1.203_2.html 192.168.1.203_23.html 192.168.1.203_3.html 192.168.1.203_4.html 192.168.1.203_5.html 192.168.1.203_6.html
The PHP script:
<?php try { $port_registry = ""; $switch_registry = ['201','202','203']; $switch_current = ""; if (!$curdir = @scandir('c:\mrtgdata', 0)) throw new Exception('Could not scan the directory.'); foreach ($curdir as $f) { if (stripos($f, '.html') !== false && $f != "index.html") { if ( stripos($f, '192.168.1.'.$switch_registry[0]) !== false && $switch_current != $switch_registry[0] ) { $port_registry .= '<b>Øvre Switch Aktive Porter</b><br>'; $switch_current = $switch_registry[0]; } if ( stripos($f, '192.168.1.'.$switch_registry[1]) !== false && $switch_current != $switch_registry[1] ) { $port_registry .= '<br><br><b>Nedre Switch Aktive Porter</b><br>'; $switch_current = $switch_registry[1]; } if ( stripos($f, '192.168.1.'.$switch_registry[2]) !== false && $switch_current != $switch_registry[2] ) { $port_registry .= '<br><br><b>Server Switch Aktive Porter</b><br>'; $switch_current = $switch_registry[2]; } $port_registry .='<a href="'. $f .'">'. $f .'</a><br>'; } } file_put_contents("C:\mrtgdata\index.html", "<html><style>A{color:blue}</style><body>". $port_registry ."</body></html>"); exec('"c:\Program Files (x86)\Google\Chrome\Application\chrome.exe" c:\mrtgdata\index.html'); } catch (Exception $e) { echo 'Error occurred: '. $e->getMessage() ."\r\n\r\n"; } ?>