自定义 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:public@10.1.1.1:3401 (我的 squid 缓存命中率)

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

.1.3.6.1.4.1.2021.4.6.0&.1.3.6.1.4.1.2021.4.6.0:public@10.1.1.1 (我的 CPU 信息)

  3. 利用自定义脚本

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


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


常见语法:

WorkDir: /www/mrtg/mysql
EnableIPv6: no

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]: &nbsp;eee:
LegendO[mysqlqcache]:


注释:

target 能够返回数据
MaxBytes 定义最大返回数据大小
Options (最重要, 定义了数据类型)
title 图片标签, 任意字符
ShortLegend 量度单位
Legend1[mysqlqcache]:  target 中第一条返回数据值 (重要)
Legend2[mysqlqcache]:  target 中第二条返回数据值  (重要)
Legend3[mysqlqcache]:
Legend4[mysqlqcache]:
LegendI[mysqlqcache]: 图片中颜色数据注释 (不能够为空)
LegendO[mysqlqcache]: 图片中颜色数据注释 (不能够为空)
 


效果:




Options

growright

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

bits

以 BIT 作为单位, 不以 BYTES 作为单位

perminute

每分钟 (默认每秒).

perhour

每小时 (默认每秒)

noinfo

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

nopercent

不显示百分比.

transparent

后台生成 GIF 图片.

integer

以整数打印.

dorelpercent

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.

avgpeak

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!)

gauge

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

absolute

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.

derive

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.

unknaszero

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.

withzeroes

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

noborder

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.

noarrow

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.

noi

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.

noo

Same as above, except relating to the 'O' or second variable.

nobanner

When using rateup for graph generation, this option disables MRTG adding theMRTG banner to the HTML pages it generates.

nolegend

When using rateup for graph generation, this option will stop MRTG from creatinga legend at the bottom of the HTML pages it generates.

printrouter

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

pngdate

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

logscale

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.

expscale

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.

secondmean

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.



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Terry_Tsang

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值