MRTG is installed on Linux system to monitor network traffic

Time:2021-3-1

Multi router traffic graph — MRTG is a tool software to monitor the traffic load of network link. It gets the traffic information of the device through the SNMP protocol, and displays the traffic load to the user in the form of HTML document containing PNG format graphics, so as to display the traffic load in a very intuitive form.
The predecessor of SNMP (Simple Network Management Protocol) is simple gateway monitoring protocol (SGMP), which is used to manage communication lines. After that, people have made great changes to SGMP, especially adding SMI and MIB: the architecture that conform to the definition of Internet. The improved protocol is the famous SNMP. The goal of SNMP is to manage the software and hardware platforms produced by many manufacturers on the Internet. Therefore, SNMP is greatly influenced by the Internet standard network management framework. Now SNMP has come out to the third version of the protocol, its function has been greatly enhanced and improved.
20151027120411784.png (643×602)

Here’s how to install it on Linux system:

(1) SNMP must be installed

Copy code

The code is as follows:

RPM – qa|grep SNMP * / / check if SNMP is installed
Yum – y install SNMP * / / install SNMP
#vim /etc/snmp/snmpd.conf
Rocommunity public / / configure SNMPv1 mode
Disk / 13102744 / / configure the size of the system
Disk / data 41279536 / / configure the size of the data disk
Service SNMP d start / / configure to start SNMP
Chkconfig snmpd on / / set boot time

(2) Installing MRTG

Copy code

The code is as follows:

yum -y install mrtg*

(3) Configure MRTG

Copy code

The code is as follows:

//Configuration is a template. You just need to change the IP to your own memory and change it to your own size. I tested it locally
Htmldir: / data / wwwroot / MRTG / / here is the HTML address of your website. The default is / var / www / MRTG
Imagedir: / data / wwwroot / MRTG / / the storage address is / var / www / MRTG by default
LogDir: /var/lib/mrtg
ThreshDir: /var/lib/mrtg
#
#[network inflow and outflow chart]
#
Target[eth0_lan]: /118.244.182.176:[email protected]
Options[eth0_lan]:growright
Language:utf8
Directory[eth0_lan]:eth1
MaxBytes[eth0_lan]: 5000000
Title[eth0_ LAN]: eht0 inflow outflow diagram
Kmg[eth0_lan]:K,M,G
YLegend[eth0_lan]:Bytes per Second
ShortLegend[eth0_lan]:B/s
Legend1[eth0_ LAN]: inflow per second
legend2[eth0_ LAN]: outflow per second
legendI[eth0_ [LAN]: inflow
legendO[eth0_ [LAN]: outflow
PageTop[eth0_ LAN]: < H1 > network card flow chart
PageFoot[eth0_lan]:<a href=”www.jb51.net”>jb51 Inc</a>
#
#[CPU load]
#
Target[cpuload]:.1.3.6.1.4.1.2021.11.50.0&.1.3.6.1.4.1.2021.11.53.0:[email protected]:
Options[cpuload]:nopercent,growright
Language:utf8
Directory[cpuload]:cpu
MaxBytes[cpuload]:100
Unscaled[cpuload]:dwym
Ylegend[cpuload]:CPU Utilization
Shortlegend[cpuload]:%
Legend1 [CPU load]: CPU user load (%)
Legend2 [CPU load]: CPU idle (%)
LegendI [cpuload]: user
Legendo [CPU load]: idle
Title [CPU load]: CPU load
Pagetop [CPU load]: < H1 > CPU load [user + idle]</h1>
PageFoot[cpuload]:<a href=”www.jb51.net”>jb51 Inc</a>
#
#[memory usage]
#
Target[memory]:.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.4.0:[email protected]:
Options[memory]:gauge,growright
Directory[memory]:mem
Language:utf8
MaxBytes1[memory]:514908
MaxBytes2[memory]:2096472
Kmg[memory]:K,M,G
kilo[memory]:1024
Unscaled[memory]:dwym
YLegend[memory]:Memory Btyes
ShortLegend[memory]:B
Legend1 [memory]: used memory (bytes)
Legend2 [memory]: swap (bytes) used
Legend I [memory]: used memory:
Legend o [memory]: swap used
Title [memory]: memory utilization
Pagetop [memory]: < H1 > memory usage (memory + swap)</h1>
PageFoot[memory]:<a href=”www.jb51.net”>jb51 Inc</a>
#
#[hard disk usage]
#
Target[disk]:.1.3.6.1.4.1.2021.9.1.8.1&.1.3.6.1.4.1.2021.9.1.8.2:[email protected]:
Options[disk]:gauge,growright
Language:utf8
Directory[disk]:disk
MaxBytes1[disk]:13102744
MaxBytes2[disk]:41279536
Kmg[disk]:K,M,G
Kilo[disk]:1024
Ylegend[disk]:Disk Bytes
Shortlegend[disk]:B
Legend1 [disk]: used space of system disk
Legend2 [disk]: used space of data disk
LegendI [disk]: system used
Legendo [disk]: data used
Title [disk]: hard disk space utilization
Pagetop [disk]: < H1 > hard disk space [system disk + data disk]</h1>
PageFoot[disk]:<a href=”www.jb51.net”>jb51 Inc</a>
#================================================================================
#Monitoring system load [1 min + 15 min]
#================================================================================
Target[systemload]: .1.3.6.1.4.1.2021.10.1.5.1&.1.3.6.1.4.1.2021.10.1.5.3:[email protected]:
Options[systemload]: gauge,nopercent,growright
Directory[systemload]: load
MaxBytes[systemload]: 3000
YLegend[systemload]: System Load
ShortLegend[systemload]:
Legend1 [systemload]: system load in the last minute (X100)
Legend2 [system load]: system load in the last 15 minutes (X100)
Legend I [system load]: 1 minute load:
Legend o [system load]: 15 minutes load:
Title [systemload]: system load (X100) [1 min + 15 min]
Pagetop [systemload]: < H1 > system load (X100) [1 min + 15 min]</h1>
#================================================================================
#Monitor the number of open TCP connections [TCP connections]
#================================================================================
Target[tcpopen]: .1.3.6.1.2.1.6.9.0&.1.3.6.1.2.1.6.9.0:[email protected]:
Options[tcpopen]: gauge,nopercent,growright
Directory[tcpopen]: tcpopen
MaxBytes[tcpopen]: 1000
YLegend[tcpopen]: Tcp Connections
Shortlegend [TCP open]: pieces
Legend1 [TCP open]: number of open TCP connections
Legend2[tcpopen]:
LegendI [TCP open]: number of TCP connections:
LegendO[tcpopen]:
Title [TCP open]: number of TCP connections [TCP connections]
Pagetop [TCP open]: < H1 > TCP connections [TCP connections]</h1>

(4) Set startup and corntab
After MRTG is installed, there will be a MRTG file under / etc / cron. D /. We just need to modify it

Copy code

The code is as follows:

*/2 * * * * root LANG=C LC_ ALL=C /usr/bin/mrtg /etc/mrtg/ mrtg.cfg –lock-file /var/lock/mrtg/mrtg_ l –confcache-file /var/lib/mrtg/ mrtg.ok //Every two minutes

There will be errors in the first execution, so we have to manually execute it three times without errors

Copy code

The code is as follows:

LANG=C LC_ALL=C /usr/bin/mrtg /etc/mrtg/mrtg.cfg –lock-file /var/lock/mrtg/mrtg_l –confcache-file /var/lib/mrtg/mrtg.ok

(5) We go to the directory to generate the index file

Copy code

The code is as follows:

/usr/local/mrtg/bin/indexmaker /etc/mrtg/ mrtg.cfg –output=/data/wwwroot/mrtg/ index.html –Title: “name yourself”

The effect is as follows
20151027120534128.png (300×151)