The most detailed mrtg settings in history

Source: Internet
Author: User
Tags mrtg

Mrtg can be used to monitor linux parameters. If you do not understand the parameters, you can search for them. Today I will mainly explain his setting method.
I. Initial Release
(1) MRTG must be based on the SNMP service. Therefore, make sure that your system has enabled this service and modify the SNMP Configuration:
# Vi/etc/snmp/snmpd. conf
62 rows:
Access notConfigGroup "" any noauth exact systemview none
Change
Access notConfigGroup "" any noauth exact mib2 none
Remove the annotator # before the first line of 89th and change it
View mib2 shortded .iso.org. dod. internet. mgmt. mib-2 fc

(2) linux Mrtg monitors host traffic to start http and snmp services:
First, check whether the two services are enabled when the system starts.
# Chkconfig -- list | grep nginx
If it is not started, you need to modify the startup mode in which you want to start it yourself:
# Chkconfig -- level 35 nginx on
Use the same settings for the snmpd service.
# Service nginx start
# Service snmpd start
After an event is triggered, it is best to use setup to configure the server so that the user can automatically perform the event.

You can also check whether the port is enabled.
# Netstat-tunlp | grep snmp
Tcp 0 0 0.0.0.0: 199 0.0.0.0: * LISTEN 4973/snmpd
Udp 0 0 0.0.0.0: 161 0.0.0.0: * 4973/snmpd

(3) MRTG generation is supported by http Services for Image Browsing, AND gd, libpng, and zlib software packages are also required. Other software is required for the normal operation of gd, (The system recognizes the self-belt. If there is no self-belt, We need to manually install it)
1. Install zlib-1.2.3
# Tar zxvf zlib-1.2.3.tar.gz
# Cd zlib-1.2.3
#./Configure -- prefix =/usr/local/zlib
# Make
# Make install

2. Install httpd-2.2.4
# Tar zxvf httpd-2.2.4.tar.gz
# Cd httpd-2.2.4
#. /Configure -- prefix =/usr/local/apache -- sysconfdir =/etc/httpd -- enable-so -- enable-track-vars -- enable-rewrite -- with-z-dir =/ usr/local/zlib
# Make
# Make install
Start httpd
/Usr/local/apache/bin/apachectl-k start

3. Install libpng-1.2.14
# Tar zxvf libpng-1.2.14.tar.gz
# Cd libpng-1.2.14
# Cp scripts/makefile. linux makefile
# Make (if you are prompted that the zlib library file or header file cannot be found, the default path of zlib in the makefile file is incorrect. You can edit the makefile file, find the zlib item, and re-specify the path to/usr/local/zlib/lib and/usr/local/zlib/include ).
# Make install

4. Install freetype-2.1.10
# Tar-zvxf freetype-2.1.10.tar.gz
# Cd freetype-2.1.10
# Mkdir-p/usr/local/freetype
#./Configure -- prefix =/usr/local/freetype
# Make; make install

5. Install composer SRC. v6b
By default, jpeg does not create user-created directories. Therefore, you need to manually create directories:
# Mkdir-pv/usr/local/IPv6/{, bin, lib, include, man/{, man1}, man1}
Install
# Tar zxvf restart src.v6b.tar.gz
#./Configure -- prefix =/usr/local/defaults 6/-- enable-shared -- enable-static
# Make
# Make install
# Make install-lib

6. Install libxml2-2.6.19
# Tar-zxf libxml2-2.6.19.tar.gz
# Cd libxml2-2.6.19
# Mkdir-p/usr/local/libxml2
#./Configure -- prefix =/usr/local/libxml2
# Make; make install
# Cp xml2-config/usr/bin

7. Install the GD-2.0.33 Library
# Tar-zvxf gd-2.0.33.tar.gz
# Mkdir-p/usr/local/gd2
# Cd gd-2.0.33
#. /Configure -- prefix =/usr/local/gd2 -- with-jpeg =/usr/local/defaults 6/-- with-png =/usr/local/lib/-- with-zlib = /usr/local/zlib/-- with-freetype =/usr/local/freetype/
# Make
# Make install

(4) modify the system statement Configuration
# Vi/etc/profile
Add the following two lines:
LC_ALL = C
LANGUAGE = on

Ii. Start Security Protection
(1) Start mrtg Installation
# Cd/usr/local/src
# Wget http://oss.oetiker.ch/mrtg/pub/mrtg-2.14.5.tar.gz
# Tar zvxf mrtg-2.14.5.tar.gz
# Cd mrtg-2.14.5
#./Configure -- prefix =/usr/local/mrtg note: "-- prefix =/usr/local/mrtg" is the specified installation path
# Make
# Make install

(2) Configure MRTG
First, create a directory for the mrtg homepage under the web Project, for example:/home/wwwroot/
Create the mrtg and sh directories in this directory:
# Cd/home/wwwroot/
# Mkdir mrtg
# Cd mrtg
# Mkdir sh

If the path is too long to be inconvenient, you can create a zookeeper:
# Cd/
# Ln-s/home/wwwroot/mrtg _ mrtg
# Ln-s/usr/local/mrtg/bin _ mrtgbin

Upload some clips.
# Cd/usr/local/src/mrtg-2.14.5 // enter the mrtg Security Program
# Cp./images/*. */_ mrtg/

Create a configuration file:
#/_ Mrtgbin/cfgmaker public @ change cost machine IP -- output =/_ mrtg/lxy. cfg

Modify the configuration file:
# Vi/_ mrtg/lxy. cfg
Remove the # WorkDir:/home/http/mrtg annotation and change it to WorkDir:/home/wwwroot/mrtg (here is the mrtg web directory)
Remove # Before # Options [_]: growright and bits and align it to the left.
Add Language: big5 at the end, and then save

(3) configure the slave node in zookeeper (if the slave node exists, it will be repeated multiple times)
LANG = C/_ mrtgbin/mrtg/_ mrtg/lxy. cfg

========================================================== ==============
(4) The statement below the root cause establishes the sh and pl cases, and then modifies the. sh case to make it accessible (. sh case content is below)
# Cd/_ mrtg/sh
# Chmod 0755 *

(5) generate the MRTG website's first line file: already in the root directory
#/_ Mrtgbin/indexmaker -- output =/_ mrtg/index.html -- title = "Lidalin's MRTG"/_ mrtg/lxy. cfg

(6) run the program
#/_ Mrtgbin/mrtg/_ mrtg/lxy. cfg some people invoke this method # env LANG = C/_ mrtgbin/mrtg/lxy. cfg
If a warning or warning occurs, it will run several more times. When the warning or warning does not appear again, it will be OK.

(7) The web pages generated by MRTG are static. to refresh the pages continuously, add the preceding commands to crontab.
# Crontab-e
Add the following line
*/1 *****/_ mrtgbin/mrtg/_ mrtg/lxy. cfg
Save and reboot
Open the robot and click http: // change the IP address of the machine/mrtg to view the network usage curve. After one minute, check the network usage!

Note: If you have set an intermediate firewall without enabling port 80 access, you need to edit/etc/sysconfig/iptables to allow others to access port 80.

Iii. Meaning of parameters in mrtg. cfg
Target: the script to be executed.
Xsize: horizontal width of the generated chart (up to 600)
Ysize: vertical height of the generated chart (up to 200)
Title: Title
Kmg: Change the default multiplier prefixes
Ytics: vertically divided into several blocks (grids)
MaxBytes: maximum vertical value of a chart
PageTop: the prompt above the page
Kilo: Write 1024. If needed, it is the unit of 1000 in the computer.
LegendI: the first data returned from the SHELL
LegendO: the second data returned from the SHELL
Options: growright, indicating that the chart is extended to the right

4. Configure other samples
Note: If you modify the configuration, you must reset step (3) (4) (5) (6) in step 2.

Other configuration items are stored in this resource.
# Cd/_ mrtg/sh

(1) zookeeper memory usage
Create a script file
# Vi mem. sh

Add (step 5) scripts:
You need to have the primary row permission after saving it.
# Chmod 0755/_ mrtg/sh /*

(2) edit/mrtg/lxy. cfg and add the following content:

5. Various shells (after the configuration is modified, the first shard must be generated again, and then re-merged)
(1) MEMORY: mem. sh
#! /Bin/bash
# This script to monitor the mem usage.
Totalmem = '/usr/bin/free | grep Mem | awk' {print $2 }''
Usef8 = '/usr/bin/free | grep Mem | awk' {print $3 }''
Echo "$ totalmem"
Echo "$ usedmem"

Edit the MRTG configuration file: the root of the value of MaxBytes is actually modified.
# Mem
Target [memory]: '/_ mrtg/sh/mem. Sh'
Unscaled [memory]: dwym
MaxBytes [memory]: 2048000
Title [memory]: Memory
ShortLegend [memory]: &
Kmg [memory]: kB, MB
Kilo <memory]: 1024
YLegend [memory]: & nbsp; Memory Usage:
Legend1 [memory]: & nbsp; Total Memory:
Legend2 [memory]: & nbsp; Used Memory:
LegendI [memory]: & nbsp; Total Memory:
LegendO [memory]: & nbsp; Used Memory:
Options [memory]: growright, gauge, nopercent
PageTop [memory]: <H1> Memory </H1>
(2) SWAP: swap. sh
#! /Bin/bash
# This script to monitor the swap usage.
Totalswap = '/usr/bin/free | grep Swap | awk' {print $2 }''
Usedswap = '/usr/bin/free | grep Swap | awk' {print $3 }''
Echo "$ totalswap"
Echo "$ usedswap"

Edit the MRTG configuration file: The MaxBytes root scripts are actually modified using the dynamic route.
# Swap
Target [swap]: '/_ mrtg/sh/swap. Sh'
Unscaled [swap]: dwym
MaxBytes [swap]: 3048000
Title [swap]: SWAP
ShortLegend [swap]: &
Kmg [swap]: kB, MB
Kilo (swap): 1024
YLegend [swap]: Swap Usage
Legend1 [swap]: Total Swap
Legend2 [swap]: Used Swap
LegendI [swap]: Total Swap
LegendO [swap]: Used Swap
Options [swap]: growright, gauge, nopercent
PageTop [swap]: <H1> Swap </H1>
(3) CPU: cpu. sh
#! /Bin/bash
# Run this script to check the mem usage.
Totalmem = '/usr/bin/free | grep Mem | awk' {print $2 }''
Usef8 = '/usr/bin/free | grep Mem | awk' {print $3 }''
UPtime = '/usr/bin/uptime | awk' {print $3 "" $4 "" $5 }''
Echo $ totalmem
Echo $ usedmem
Echo $ UPtime
Hostname

Edit the MRTG configuration file: The MaxBytes root scripts are actually modified using the dynamic route.
# Cpu
Target [cpu]: '/_ mrtg/sh/cpu. Sh'
MaxBytes [cpu]: 100
Title [cpu]: CPU
Options [cpu]: gauge, nopercent, growright
YLegend [cpu]: CPU loading (%)
Lelegend [cpu]: %
LegendO [cpu]: & CPU USER
LegendI [cpu]: & CPU SYSTEM
PageTop [cpu]: <H1> CPU </H1>
(4) magnetic compaction used: df. pl
#! /Usr/bin/perl
# Output (df-kl) looks like this:
# Filesystem 1k-blocks Used Available Use % Mounted on
#/Dev/md0 95645100 30401312 64272080 33%/
#/Dev/hde1 14119 1159 12231 9%/boot
#
# In which case, this script returns:
#95659219
#30402503
# When run.
Foreach $ filesystem ('df-kl | grep-v "Filesystem "'){
@ Df = split (/\ s +/, $ filesystem );
$ Total + = $ df [1];
$ Usage + = $ df [2];
}
Print "$ total \ n ";
Print "$ usage \ n ";
Hostname

Edit the MRTG configuration file: The MaxBytes root scripts are actually modified using the dynamic route.
# Disk used
Target [disk]: '/_ mrtg/sh/df. pl'
Title [disk]: Disk Space
Unscaled [disk]: dwym
MaxBytes [disk]: 115247550
Kmg [disk]: KB, MB, GB
LegendI [disk]: Total Disk Space
LegendO [disk]: Used Disk Space
Legend1 [disk]: Total Disk Space
Legend2 [disk]: Used Disk Space
YLegend [disk]: Megabytes
ShortLegend [disk]: &
Options [disk]: growright, gauge, nopercent
PageTop [disk]: <H1> Disk Space </H1>
(5) magnetic mirror I/O: io. sh
#! /Bin/bash
# This script will monitor the KBread/sec & KBwriten/sec of Disk.
# Creater: ccc it loren ext: 2288 2005/8/3
# As sda, sdb, sdc, sdd, hda.
# Disk = sda
Hd = sda
Disk =/dev/$ hd
KBread_sec = 'iostat-x $ disk | grep $ hd | awk '{print $8 }''
KBwrite_sec = 'iostat-x $ disk | grep $ hd | awk '{print $9 }''
Echo "$ KBread_sec"
Echo "$ KBwrite_sec"
Hostname

Edit the MRTG configuration file: If you need to partition more partitions, modify io. sh.
# Disk I/O
Target [diskIO]: '/_ mrtg/sh/io. Sh'
Title [diskIO]: Disk hda I/O
Unscaled [diskIO]: dwym
MaxBytes [diskIO]: 100
Kmg [diskIO]: KB, MB, GB
LegendI [diskIO]: Disk I/O KBread/sec
LegendO [diskIO]: Disk I/O KBwrite/sec
Legend1 [diskIO]: Disk I/O KBread/sec
Legend2 [diskIO]: Disk I/O KBwrite/sec
YLegend [diskIO]: Megabytes
ShortLegend [diskIO]: &
Options [diskIO]: growright, gauge, nopercent
PageTop [diskIO]: <H1> Disk I/O </H1>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.