I opened a website http://zjsx0575.vicp.net, but want to know the current website traffic, we can install MRTG this software through the web page to monitor network traffic. MRTG collects data generated by SNMP (Simple Network Management Protocol). Therefore, the server to be recorded must install SNMP. After MRTG is installed on your host, you can collect not only your own traffic data, but also other SNMP data that can be received on the local network. Therefore, you must install the SNMP software before installing the MRTG traffic analysis software. Both software can be installed under ports.
We use ports to install SNMP:
# cd /usr/ports/net/net-snmp# ake install clean
After the installation is complete, we must first add a community name that can read SNMP information. The so-called community name is an explicit string. we can regard it as the password between the management station and the agent. It is a string that must be first transmitted during MRTG and net-snmp communication. Different permissions can be granted to different domains or hosts, and different permissions can be determined based on the setting of community name. A network component can have multiple community names. Generally, the public community name preset by the SNMP agent is public. We do not have to set the community name to public, because public is the default value of common SNMP. For security issues, we do not set it to public. Here we will set the community name to MRTG and only have the read-only permission.
To set the community name, add a text file first./Etc/snmpd. config (this file installs different directories for different users)Add the following settings:
Open the File Using EE snmpd. config and you will find
# $ FreeBSD: src/etc/snmpd. config, V 1.1.4.2 2006/03/31 12:47:50 glebius exp $
#
# Example configuration file for bsnmpd (1 ).
#
#
# Set some common variables
#
HOST: = foobar
Location: = "room 200"
Contact: = "10.33.250.2"
System: = 1 # FreeBSD
Traphost: = localhost
Trapport: = 162
# Change this!
Read: = "public"
# Uncomment line 42 that sets the community string to enable write access.
Write: = "geheim"
Trap: = "mytrap"
#
# Configuration
#
% Snmpd
Begemotsnmpddebugdumppdus = 2
Begemotsnmpddebugsyslogpri = 7
#
# Set the Read and Write communities.
#
# The default value of the community strings is null (note, that this is
# Different from the empty string). This disables both read and write access.
# To Enable Read access only the read community string must be set. Setting
# The write community string enables both read and write access with that
# String.
#
# Be sure to understand the security implications of SNMPv2-the Community
# Strings are readable on the wire!
#
Begemotsnmpdcommunitystring.0.1 = $ (read)
# Begemotsnmpdcommunitystring.0.2 = $ (write)
Begemotsnmpdcommunitydisable = 1
# Open Standard SNMP ports
Begemotsnmpdportstatus. [$ (host)]. 161 = 1
Begemotsnmpdportstatus.127.0.0.1.161 = 1
# Open a Unix domain socket
Begemotsnmpdlocalportstatus. "/var/run/snmpd. Sock" = 1
Begemotsnmpdlocalporttype. "/var/run/snmpd. Sock" = 4
# Send traps to the traphost
Begemottrapsinkstatus. [$ (traphost)]. $ (trapport) = 4
Begemottrapsinkversion. [$ (traphost)]. $ (trapport) = 2
Begemottrapsinkcomm. [$ (traphost)]. $ (trapport) = $ (TRAP)
Rocommunity MRTG
Syscontact = $ (contact)
Syslocation = $ (location)
Sysobjectid = 1.3.6.1.4.1.12325.1.1.2.1. $ (system)
Snmpenableauthentraps = 2
#
# Load MIB-2 Module
#
Begemotsnmpdmodulepath. "mibii" = "/usr/lib/snmp_mibii.so"
# Force a polling rate for the 64-bit interface counters in case
# The Automatic computation is wrong (which may be the case if an Interface
# Announces the wrong bit rate via its MIB ).
# % Mibii
# BegemotIfForcePoll = 2000
#
# Netgraph module
#
# BegemotSnmpdModulePath. "netgraph" = "/usr/lib/snmp_netgraph.so"
#
# % Netgraph
# BegemotNgControlNodeName = "snmpd"
#
# Pf (4) module
#
# BegemotSnmpdModulePath. "pf" = "/usr/lib/snmp_pf.so"
In the preceding settings, mrtg is the read-only community name, Office is the location of your machine, and syscontact is connected to your Eamil string. In addition, we must/Etc/rc. confAdd the following line:
Snmpd_enable = "YES"
Next, execute/Usr/local/etc/rc. d/snmpd. sh startTo start snmpd. If an error occursCd/usr/local/etc/rc. d/, SetSnmpd. shDelete the original content and add the following line:
/usr/local/sbin/snmpd
Then execute/Usr/local/etc/rc. d/snmpd. shYou can start SNMP.
Install MRTG
We use ports to install MRTG:
# cd /usr/ports/net/mrtg# make install
Then the MRTG settings will be generated.
# cd /usr/local/etc/mrtg# rehash# cfgmaker mrtg@alexwang.com >mrtg.cfg
Here, MRTG is the value we set when installing net-snmp. If you use the wrong community name, you may get an error response from the device you want to record. Alexwang.com is the host location you want to record. Mrtg. cfg is the name of the configuration file to be generated.
If you want to record multiple hosts, you only need to add more host names when creating a maker. For example:
# cfgmaker mrtg@alexwang.com public@dns1.alexwang.com >mrtg.cfg
In this way, the traffic of the above two hosts will be recorded at the same time.
After a basic profile is generated, We can edit the profile we just generated.Ee mrtg. cfgAdd custom settings to the beginning of the file:
# If you want to use MRTG in Chinese, add the following line of Language: big5 # Set the directory where your MRTG is to be placed, which should be placed on the webpage # link, the root directory of my webpage is/home/www, so I put # MRTG in the following directory. WorkDIR:/home/www/mrtg # The default MRTG graph time is from right to left # I like it from left to right, so Add the following line Options [_]: growright |
Create a workdir directory that you set in mrtg. cfg:
# mkdir /home/www/mrtg
Then use the indexmaker command to create the homepage of MRTG:
# Indexmaker-title 'traffic statistics'-output/home/www/mrtg/index.html mrtg. cfg
Here, the parameter-title is the title of the index.html file, and-output is the file location to be output. The default parameter is stdio (usually the screen ).
You can also use other Web editing software to modify and beautify the output file index.html. Next, copy some image files of mrtg to the mrtg directory:
# cd /usr/ports/net/mrtg/work/mrtg*# cd images# cp * /home/www/mrtg/
Finally Start MRTG:
# /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg
The first execution of the preceding command may have some error messages. Ignore this because it is the first execution of MRTG and there is no new or old graph. You only need to execute the command several more times. Run the commandCrontab-eTo execute the preceding command every five minutes and add the following line:
*/5 * * * * /usr/local/bin/mrtg /usr/local/etc/mrtg/mrtg.cfg |
Now you can use http: // yourserver/MRTG to connect. Finally, do not forget to remove the temporary archive during the installation process:
# cd /usr/ports/net/mrtg/# make clean