天天看点

自定义 mrtg 数据

mrtg 工作原理

1. 利用 snmp 返回数据

2. 利用 自定义脚本进行数据返回

example:

希望监控当前 mysql  query cache 使用中的内存大小.

默认状态下, mrtg 希望返回 4 条数据

1. 数据变量1 例如 input 流量

2. 数据变量2 例如 output 流量,

3. uptime

4. 对应目标名称, 例如主机名, ip 等资料

由于 query cache 不存在多变量返回, 则, 随便返回一个变量则可

脚本返回效果如下:

[root@station10 mrtg]# /etc/mrtg/mrtg-query.sh qcache_free_memory localhost

16460120               (当前使用率)

16460120               (可忽略)

18804 seconds          (uptime)

station10.cluster.com  (hostname)

mrtg.cfg 定义规则

全局定义, 如

workdir: /www/mrtg/mysql 

#网页与日志存放位置, 可分离, 如利用

#imagedir: /www/mrtg/images

#logdir: /www/mrtg/logs

#htmldir: /www/mrtg/

#refresh: 600

maxage: 7200

language: chinese

enableipv6: no

图片输出自定义

target  <- 用于定义如何获得数据方法

  1, 利用自定义 mib 获得数据方法, 如

cacherequesthitratio.5&cacherequesthitratio.60:[email protected]:3401 (我的 squid 缓存命中率)

  2. 利用 snmp 获得数据方法 如

.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:[email protected] (我的 cpu 信息)

  3. 利用自定义脚本

/etc/mrtg/mrtg-query.sh qcache_free_memory localhost

注意: mib, snmp 只获得需要的相关数据, 无法返回主机 uptime, 需要额外定义

常见语法:

workdir: /www/mrtg/mysql

target[mysqlqcache]: `/etc/mrtg/mrtg-query.sh qcache_free_memory localhost`

maxbytes[mysqlqcache]: 20000000

options[mysqlqcache]:  nopercent,growright,gauge,noinfo

title[mysqlqcache]: qcache size

pagetop[mysqlqcache]: <h1>10.1.1.10 free memory</h1>

ylegend[mysqlqcache]: memory free

shortlegend[mysqlqcache]: m/s

legend1[mysqlqcache]: aaaaaaa

legend2[mysqlqcache]:

legend3[mysqlqcache]:

legend4[mysqlqcache]:

legendi[mysqlqcache]:  eee:

legendo[mysqlqcache]:

注释:

target 能够返回数据

maxbytes 定义最大返回数据大小

options (最重要, 定义了数据类型)

title 图片标签, 任意字符

shortlegend 量度单位

legend1[mysqlqcache]:  target 中第一条返回数据值 (重要)

legend2[mysqlqcache]:  target 中第二条返回数据值  (重要)

legendi[mysqlqcache]: 图片中颜色数据注释 (不能够为空)

legendo[mysqlqcache]: 图片中颜色数据注释 (不能够为空) 

效果:

自定义 mrtg 数据

<dl></dl>

<dt>growright</dt>

<dd></dd>

希望数据从右边出现, 默认从左出现

<dt>bits</dt>

以 bit 作为单位, 不以 bytes 作为单位

<dt>perminute</dt>

每分钟 (默认每秒).

<dt>perhour</dt>

每小时 (默认每秒)

<dt>noinfo</dt>

禁止 uptime 及主机名信息进行显示

<dt>nopercent</dt>

不显示百分比.

<dt>transparent</dt>

后台生成 gif 图片.

<dt>integer</dt>

以整数打印.

<dt>dorelpercent</dt>

the relative percentage of in-traffic to out-traffic is calculatedand displayed in the graph as an additional line.note: only a fixed scale is available (from 0 to 100%). thereforeif in-traffic is greater than out-traffic

then 100% is displayed.if you suspect that your in-traffic is not always less than or equalto your out-traffic you are urged to not use this options.note: if you use this option in combination with thecoloursoptions, a fifth colour-name colour-value

pair is required there.

<dt>avgpeak</dt>

there are some isps who use the average peak values to bill their customers.using this option mrtg displays these values for each graph. the value isbuilt by averaging the max 5 minute traffic average for each 'step' shown

inthe graph. for the weekly graph this means that it builds the average of all2 hour intervals 5 minute peak values. (confused? thought so!)

<dt>gauge</dt>

从 target 返回值, 并把返回值作为 '当前状态' 测量结果, 而不作为递增计数器, 该参数常用语 磁盘空间, 进程负载, 温度及类似监控

<dt>absolute</dt>

this is for counter type data sources which reset their value when they areread. this means that rateup does not have to build the difference betweenthe current and the last value read from the data source. the value obtained

isstill divided by the elapsed time between the current and the last reading, which makesit different from the 'gauge' option. useful for external data gatherers.

<dt>derive</dt>

if you are using rrdtool as logger/grapher you can use a third type of datasource. derive is like counter, except that it is not required to go up allthe time. it is useful for situations where the change of some value should

begraphed.

<dt>unknaszero</dt>

log unknown data as zero instead of the default behaviour of repeating thelast value seen. be careful with this, often a flat line in the graph ismuch more obvious than a line at 0.

<dt>withzeroes</dt>

normally we ignore all values which are zero when calculating the averagetransfer rate on a line. if this is not desirable use this option.

<dt>noborder</dt>

if you are using rateup to log data, mrtg will create the graph images.normally these images have a shaded border around them. if you do not want theborder to be drawn, enable this option. this option has no effect if you

arenot using rateup.

<dt>noarrow</dt>

as with the option above, this effects rateup graph generation only. normallyrateup will generate graphs with a small arrow showing the direction of thedata. if you do not want this arrow to be drawn, enable this option.

thisoption has no effect if you are not using rateup.

<dt>noi</dt>

when using rateup for graph generation, you can use this option to stop rateupdrawing a graph for the 'i' or first variable. this also removes entries forthis variable in the html page mrtg generates, and will remove the

peaks forthis variable if they are enabled. this allows you to hide this data, or canbe very useful if you are only graphing one line of data rather than two.this option is not destructive - any data received for the the variablecontinued to be logged, it

just isn't shown.

<dt>noo</dt>

same as above, except relating to the 'o' or second variable.

<dt>nobanner</dt>

when using rateup for graph generation, this option disables mrtg adding themrtg banner to the html pages it generates.

<dt>nolegend</dt>

when using rateup for graph generation, this option will stop mrtg from creatinga legend at the bottom of the html pages it generates.

<dt>printrouter</dt>

when using rateup for graph generation, this option will print the routername in the graph it generates. this option is overridden by the value ofpngtitle if one is given

<dt>pngdate</dt>

when using rateup for graph generation, this option will print atimestamp in the graph it generates, including a timezone if one is specifiedby the 'timezone' parameter. this is aequivalent to setting timestrpost[x]: ru

<dt>logscale</dt>

the logscale option causes rateup to display the data with the y axisscaled logarithmically. doing so allows the normal traffic to occupythe majority of the vertical range, while still showing any spikes

attheir full height.

logscale displays all the available data and will always producewell-behaved graphs. people often consider a logarithmically scaled graphcounterintuitive, however, and thus hard to interpret.

<dt>expscale</dt>

the expscale option causes rateup to display the data with the y axisscaled exponentially. doing so emphasizes small changes at the top ofthe scale; this can be useful when graphing values that fluctuate

bya small amount near the top of the scale, such as line voltage.

expscale is essentially the inverse of

logscale.

<dt>secondmean</dt>

the secondmean option sets the maximum value on the graph to the meanof the data greater than the mean of all data. this produces a graphthat focuses more on the typical data, while clipping large peaks.

using secondmean will give a more intutive linearlyscaled graph, but can result in a uselessly high or low scale in somerare situations (specifically, when the data includes a large portionof values far from

the actual mean)

if a target includes both logscale and

secondmean in the options, thesecondmean takes precedence.

继续阅读