天天看點

自定義 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.

繼續閱讀