自定義 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]: 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.
最後更新:2017-04-02 06:52:12