MRTG 系列 :参数设定(上篇)

{ Posted on 星期六, 十二月 11, 2010 by Kaiser.XKw }
MRTG 系列 :参数设定(上篇)

mrtg-reference

 

Overview

 

The runtime behaviour of MRTG is governed by a configuration file. Run-of- ther-mill configuration files can be generated with cfgmaker. (Check the cfgmaker manpage). But for more elaborate configurations some hand-tuning is required.

This document describes all the configuration options understood by the mrtg software.

 

# 注释 :该文档描述了 MRTG 所知道的所有配置文件的选项

 


 

Syntax

 

MRTG configuration file syntax follows some simple rules:

 

# 注释 :MRTG 配置文件的语法有如下几个规则 :

 

#     -)第一是所有的 keyword 必须从行首开始

 

#     -)如果一个行以空白(空格或者tab)开始,而上一行不是空白行,则被追加到上一行的行尾。这点和 sendmail.cf 的一样

 

#     -)空行被忽略

 

#     -)以 # 开头的行被认为是注释

 

#     -)可以在配置文件中插入其他文件,就是使用 Include:指令

  • Keywords must start at the beginning of a line.
  • Lines which follow a keyword line which start with a blank are appended to the keyword line
  • Empty Lines are ignored
  • Lines starting with a # sign are comments.
  • You can add other files into the configuration file using

Include: <file>

 

Example:

Include: base-options.inc

 

If included files are specified with relative paths, both the current working directory and the directory containing the main config file will be searched for the files.

 

# 注释 :如果 Include:给出的文件是相对路径的,则当前工作目录和存放主要配置文件的目录都会被搜索

 


 

Global keywords

 

#  注释 :下面介绍全局性的关键字

 

WorkDir

 

WorkDir specifies where the logfiles and the webpages should be created.

Example:

 

WorkDir: /usr/tardis/pub/www/stats/mrtg

 

# 注释 :首先是 WorkDir:选项 ,这是必须的一个选项,表示 MRTG 的日志文件和 HTML 页面放在那里


 

Optional global keywords

 

# 注释 :下面这些是可选的全局选项

 

HtmlDir

 

HtmlDir specifies the directory where the html (or shtml, but we'll get on to those later) lives.

NOTE: Workdir overrides the settings for htmldir, imagedir and logdir.

 

Example:

 

Htmldir: /www/mrtg/

 

# 注释 :Hmtldir  表示 HTML 文件放在那里。

 

# 注意,WorkDir 将覆盖 Htmldir 、Imagedir、Logdir  这三个选项。

 

# 所以如果要指定其中一个,就需要三个单独定义

 


ImageDir

 

ImageDir specifies the directory where the images live. They should be under the html directory.

Example:

 

Imagedir: /www/mrtg/images

 

# 注释 :Imagedir 表示那里存放生成的图片。不过要注意,该目录必须是 HtmlDir 所指定的目录下的一个子目录

 


LogDir

 

LogDir specifies the directory where the logs are stored. This need not be under htmldir directive.

Example:

 

Logdir: /www/mrtg/logs

 

# 注释 :Logdir 选项指定日志存放的目录,同样也必须是 Htmdir 所指定的目录的一个子目录

 


Forks (UNIX only)

 

With system that supports fork (UNIX for example), mrtg can fork itself into multiple instances while it is acquiring data via snmp.

For situations with high latency or a great number of devices this will speed things up considerably. It will not make things faster, though, if you query a single switch sitting next door.

As far as I know NT can not fork so this option is not available on NT.

Example:

 

# 注释 :Forks 选项是 UNIX 才有的。MRTG 可以在通过 SNMP 获取数据的同时 fork 出多个实例。

 

# 对于网络延迟较大或者需要轮询的设备数量众多的情况,该选项可以一定程度的减少所需要的时间

 

# forks:后面加上要 fork 的实例的数目

 

 

Forks: 4

 

EnableIPv6

 

When set to yes, IPv6 support is enabled if the required libraries are present (see the the mrtg-ipv6 manpage manpage). When IPv6 is enabled, mrtg can talk to routers using SNMP over IPv6 and targets may be specified by their numeric IPv6 addresses as well as by hostname or IPv4 address.

If IPv6 is enabled and the target is a hostname, mrtg will try to resolve the hostname to an IPv6 address and, if this fails, to an IPv4 address. Note that mrtg will only use IPv4 if you specify an IPv4 address or a hostname with no corresponding IPv6 address; it will not fall back to IPv4 if it simply fails to communicate with the target using IPv6. This is by design.

Note that many routers do not currently support SNMP over IPv6. Use the IPv4Only per target option for these routers.

IPv6 is disabled by default.

Example:

 

EnableIPv6: Yes

 


 

EnableSnmpV3

When set to yes, uses the Net::SNMP module instead of the SNMP_SESSION module for generating snmp queries. This allows the use of SNMPv3 if other snmpv3 parameters are set.

SNMPv3 is disabled by default.

Example:

 

EnableSnmpV3: yes

 

 Refresh

 

How many seconds apart should the browser (Netscape) be instructed to reload the page? If this is not defined, the default is 300 seconds (5 minutes).

Example:

 

# 注释 :Refresh 选项设置 MRTG 多长时间 reload 页面。也就是更新图表和日志。

 

# 默认是会议300秒,也就是5分钟

 

Refresh: 600

 

 


Interval

 

How often do you call mrtg? The default is 5 minutes. If you call it less often, you should specify it here. This does two things:

  • The generated HTML page contains the right information about the calling interval ...
  • A META header in the generated HTML page will instruct caches about the time-to-live of this page .....

# 注释: Interval 设置多长时间调用一次 MRTG 。默认也是5分钟,和 Refresh 一致。 这样可以做到及时更新。

 

# 该选项将会做两件事 :

 

#    -)生成的 HTML 页面将包括 Interval 的设置

 

#     -)HTML 页面中的 META header 将会告诉 cache 多长时间更新一次

 

In this example, we tell mrtg that we will be calling it every 10 minutes. If you are calling mrtg every 5 minutes, you can leave this line commented out.

Example:

 

Interval: 10

 

Note that unless you are using rrdtool you can not set Interval to less than 5 minutes. If you are using rrdtool you can set interval down to 1 minute. Note though, setting the Interval for an rrdtool/mrtg setup will influence the initial creation of the database. If you change the interval later, all existing databases will remain at the resolution they were initially created with.

 

# 注释 :注意,除非是使用 rrdtool ,否则 Interval 不能小于5分钟

 

# 如果使用 rrdtool ,可以调整为 1分钟

 

# 在安装 rrdtool/mrtg 时指定 Interval 会影响到数据库一开始的建立。

 

# 假如在后期改变了 Interval ,则原先的数据库仍然被保留


 


 

MaxAge

MRTG relies heavily on the real time clock of your computer. If the time is set to a wrong value, especially if it is advanced far into the future, this will cause mrtg to expire lots of supposedly old data from the log files.

To prevent this, you can add a 'reasonability' check by specifying a maximum age for log files. If a file seems to be older, mrtg will not touch it but complain instead, giving you a chance to investigate the cause.

Example:

 

# 问题 :MaxAge 选项的作用是什么?

 

MaxAge: 7200

 

The example above will make mrtg refuse to update log files older than 2 hours (7200 seconds).

 


 

WriteExpires

 

With this switch mrtg will generate .meta files for CERN and Apache servers which contain Expiration tags for the html and gif files. The *.meta files will be created in the same directory as the other files, so you will have to set ``MetaDir .'' and ``MetaFiles on'' in your apache.conf or .htaccess file for this to work

NOTE: If you are running Apache-1.2 or later, you can use the mod_expire to achieve the same effect ... see the file htaccess.txt

Example:

 

WriteExpires: Yes

 

NoMib2

 

Normally we ask the SNMP device for 'sysUptime' and 'sysName' properties. Some do not have these. If you want to avoid getting complaints from mrtg about these missing properties, specify the nomib2 option.

An example of agents which do not implement base mib2 attributes are Computer Associates - Unicenter TNG Agents. CA relies on using the base OS SNMP agent in addition to its own agents to supplement the management of a system.

Example:

 

# 注释 :有些设备并不具备 sysUptime 或者 sysName 这些特性。为了防止 MRTG 报错,可以使用 NoMibs2 选项。

 

NoMib2: Yes

 

SingleRequest

 

Some SNMP implementations can not deal with requests asking for multiple snmp variables in one go. Set this in your cfg file to force mrtg to only ask for one variable per request.

Examples :

 

# 注释 :有些 SNMP 的实现不能一次性查询多个 SNMP 对象。所以用 SingleRequest 选项来强迫 MRTG 每个请求只查询一个对象

 

SingleRequest: Yes

 

SnmpOptions

Apart from the per target timeout options, you can also configure the behaviour of the snmpget process on a more profound level. SnmpOptions accepts a hash of options. The following options are currently supported:

 

timeout                   => $default_timeout,

retries                   => $default_retries,

backoff                   => $default_backoff,

default_max_repetitions   => $max_repetitions,

use_16bit_request_ids     => 1,

lenient_source_port_matching => 0,

lenient_source_address_matching => 1

 

The values behind the options indicate the current default value. Note that these settings OVERRIDE the per target timeout settings.

A per-target SnmpOptions[] keyword will override the global settings. That keyword is primarily for SNMPv3.

The 16bit request ids are the only way to query the broken SNMP implementation of SMC Barricade routers.

Example:

 

SnmpOptions: retries => 2, only_ip_address_matching => 0

 

Note that AS/400 snmp seems to be broken in a way which prevents mrtg from working with it unless

 

SnmpOptions: lenient_source_port_matching => 1

 

is set.

 


 

IconDir

If you want to keep the mrtg icons in someplace other than the working (or imagedir) directory, use the IconDir variable for defining the url of the icons directory.

Example:

 

# 注释 :IconDir 选项设置 MRTG 所使用的图标的目录

 

# 默认是在 WorkDir 或者 Imagedir

 

IconDir: /mrtgicons/

 

LoadMIBs

 

Load the MIB file(s) specified and make its OIDs available as symbolic names. For better efficiancy, a cache of MIBs is maintained in the WorkDir.

 

Example:

 

# 注释 :LoadMIBs 表示加载那些 MIB 。MRTG 会同时把这些 mib 拷贝一份放在 WorkDir 目录下

 

LoadMIBs: /dept/net/mibs/netapp.mib,/usr/local/lib/ft100m.mib

 


Language

Switch output format to the selected Language (Check the translate directory to see which languages are supported at the moment. In this directory you can also find instructions on how to create new translations).

 

Currently the following laguages are supported:

 

big5 brazilian bulgarian catalan chinese croatian czech danish dutch eucjp french galician gb gb2312 german greek hungarian icelandic indonesia iso2022jp italian korean lithuanian malay norwegian polish portuguese romanian russian russian1251 serbian slovak slovenian spanish swedish turkish ukrainian

 

Example:

 

# 注释 :Language 设置 HTML 页面的语言。

 

# 要看当前支持那些语言,可以查看 translate 目录

 

# 当前支持的语言如上,中文就是 chinese ,gb,gb2312 ,繁体中文是 big5


 

Language: danish

 

LogFormat

Setting LogFormat to 'rrdtool' in your mrtg.cfg file enables rrdtool mode. In rrdtool mode, mrtg relies on rrdtool to do its logging. See the mrtg-rrd manpage.

Example:

 

# 注释 :如果 LogFormat 为 rrdtool ,则 mrtg.cfg 允许 rrdtool 模式的日志,不过要依赖于 rrdtool 来生成日志

 

LogFormat: rrdtool

 

LibAdd

If you are using rrdtool mode and your rrdtool Perl module (RRDs.pm) is not installed in a location where perl can find it on its own, you can use LibAdd to supply an appropriate path.

Example:

 

LibAdd: /usr/local/rrdtool/lib/perl/

 

 

PathAdd

If the rrdtool executable can not be found in the normal PATH, you can use this keyword to add a suitable directory to your path.

Example:

PathAdd: /usr/local/rrdtool/bin/

 

 

RunAsDaemon

 

The RunAsDaemon keyword enables daemon mode operation. The purpose of daemon mode is that MRTG is launched once and not repeatedly (as it is with cron). This behavior saves computing resourses as loading and parsing of configuration files happens only once.

 

# 注释 :RunAsDaemon 关键字允许 MRTG 以守护进程的模式运行。要注意同 cron 运行的方式区别开来。

 

# 以守护进程模式运行有一个好处就是不用频繁地启动 mrtg 程序,不用重复的读取配置文件,可以节省资源

 

Using daemon mode MRTG itself is responible for timing the measurement intervals. Therfore its important to set the Interval keyword to an apropiate value.

 

# 注释 :由于不是由 crond 控制多长时间调用 mrtg 程序一次,所以 daemon 模式下的 mrtg 就必须设置好 Interval 这个参数

 

# 由 mrtg 程序自己负责计时工作


 

Note that when using daemon mode MRTG should no longer be started from cron as each new process runs forever. Instead MRTG should be started from the command prompt or by a system startup script.

 

# 注释 :要注意一点,一旦使用了 daemon 模式,mrtg 就不应该以 cron 的方式来启动。

 

# 应该从命令行启动(并进入 daeon 模式),或者通过 /etc/rc.d/init.d/ 下类似的方式来启动

 

If you want mrtg to run under a particular user and group (it is not recomended to run MRTG as root) then you can use the --user=user_name and --group=group_name options on the mrtg commandline.

 

# 注释 :假如你想要 mrtg 以某个特定的身份来运行(不推荐以 root 身份来运行 mrtg),则需要用到 --user= 和 --group= 两个命令行的选项


 

mrtg --user=mrtg_user --group=mrtg_group mrtg.cfg

 

Also note that in daemon mode restarting the process is required in order to activate changes in the config file.

 

# 注释 :由于处于 daemon 模式,mrtg 并不会自动定时 reload 配置文件,需要手工重启进程

 

Under UNIX, the Daemon switch causes mrtg to fork into background after checking its config file. On Windows NT the MRTG process will detach from the console, but because the NT/2000 shell waits for its children you have to use this special start sequence when you launch the program:

 

# 注释 :在 unix 下,RunAsDaemon 会促使 mrtg 在读取配置文件后自动进入后台,

 

# 但在  windows NT/2000 下,需要执行 "start /b mrtg mrtg.cf" 命令,才能进入后台,否则会一直处于 cmd 命令窗口下

 

start /b perl mrtg mrtg.cfg

 

You may have to add path information equal to what you add when you run mrtg from the commandline.

Example

 

RunAsDaemon: Yes

Interval:    5

 

This makes MRTG run as a daemon beginning data collection every 5 minutes

 

# 注释 :上面的配置将使 MRTG 运行在 daemon 模式,每隔5分钟就收集一次数据。

 

# 所以 MRTG 不会自动去收集数据的,而是通过 Interval 来“强迫” MRTG 去收集数据

 

# 这和 refresh 是不同的,refresh 是多长时间刷新页面,如果 interval > refresh ,则图表的更新比较及时

 

# 如果 interval < refresh ,则图表的更新较数据的收集慢,最好是两者差不多

 

If you are daemontools and still want to run mrtg as a daemon you can additionally specify

 

NoDetach:     Yes

 

this will make mrtg run but without detaching it from the terminal.



No Response to "MRTG 系列 :参数设定(上篇)"