博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义 mrtg 数据
阅读量:4078 次
发布时间:2019-05-25

本文共 6988 字,大约阅读时间需要 23 分钟。

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.

转载地址:http://dqnni.baihongyu.com/

你可能感兴趣的文章
Pixhawk解锁常见错误
查看>>
Pixhawk无人机教程-8.1 在Mission Planner中下载与分析日志(转载)
查看>>
pixhawk 用MissionPlanner查看日志的一些总结(我个人的)
查看>>
现在意识到了研究定位的重要性和意义
查看>>
乐迪遥控器可以显示GPS卫星数,还有电压回传。
查看>>
我个人觉得pixhawk合适的飞行模式设置顺序
查看>>
飞定高的无人机还是用双回中遥控器好一些
查看>>
手不要碰高速运行的浆,会被浆打出血
查看>>
我发现无人机把Pixhawk2.4.8换成pixhawk4 不需要换很多东西,也不需要再焊什么东西
查看>>
**当你做东西卡住的时候,也是在提醒你需要花时间沉下来深入学东西了,不然做不出来的
查看>>
1-13 笔记
查看>>
pixhawk的offboard模式其实是和定高(AltHold) 定点(loiter) 这些模式平级的一个模式
查看>>
我发觉大家都在讲VINS
查看>>
OpenCV编程中的C++语法知识点回顾
查看>>
C++的模板化等等的确实比C用起来方便多了
查看>>
ROS是不是可以理解成一个虚拟机,就是操作系统之上的操作系统
查看>>
用STL algorithm轻松解决几道算法面试题
查看>>
ACfly之所以不怕炸机因为它觉得某个传感器数据不安全就立马不用了
查看>>
我发觉,不管是弄ROS OPENCV T265二次开发 SDK开发 caffe PX4 都是用的C++
查看>>
ROS的安装(包含文字和视频教程,我的ROS安装教程以这篇为准)
查看>>