前文讲述了,如何通过snmp的方式取获取并创建自己的Cacti图形,但如果某些数据是无法通过snmp取得的,可以通过脚本的方式来获取,所以只有你想不到,没有你做不到的。
比如你那一天对腾讯的在线人数感兴趣,你可以监视这个页面http://im.qq.com/中下图部分:
监控部的同事估计也是通过这个方式来了解腾讯的在线人数曲线的。
继续正题,比如我要监控squid打开一个特定的页面的速度,虽然前文已经讲述了,你可以通过squid自身提供的信息来绘制,但毕竟这是squid提供的,可能没有考虑到网络等因素,所以你需要模拟一个最终用户打开页面的情况,这就要需要自己写一个特殊的脚本:
1.进入到 /cacti/scripts的目录
创建一个文件,如time_get_page.sh
#!/bin/bash
begin_time=`date +%s%N`
curl -s -H ‘Host: bbs.iammecn.com’ $1 >/tmp/tmp
end_time=`date +%s%N`let time1="$end_time"-"$begin_time"
let time1="time1/1000000"begin_time=`date +%s%N`
curl -s -H ‘Host: www.iammecn.com’ $1 >/tmp/tmp
end_time=`date +%s%N`let time2="$end_time"-"$begin_time"
let time2="time2/1000000"printf misstime:$time1
printf " "hittime:$time2
运行这个脚本的结果,后面加上你要监控的机器的IP后,运行结果如下:
misstime:2913 hittime:2492
获得两个值,我是选取了两个不同的页面,一个是需要不缓存的,一个是需要缓存的,所以分别代表了miss和hit的时间。
2. 登陆cacti,然后在Data Input Methods,添加一个新的数据来源
名字随便起了,然后选择”scripts/command” ,路径那里填写:
sh <path_cacti>/scripts/time_get_page.sh <ip>
Input Fields里添加一个IP,“Special Type Code”里填写hostname
Hostname就是指在你的Devices里指定的主机名了,从来获取你的主机名
Output Fields 里再输出两个值
就是上面脚本里输出的两个值,分别是httime,misstime
3. Data Templates ,创建数据模板
“Data Input Method”就选刚才创建的那个数据来源
下面再添加两个TAB
主要是选对”Output Field”这个值的来源
4.然后再创建“Graph Templates”
同样是创建一个新模板,下面的名字你随便起,如下图:
重点来了,接下来是如何创建图形了,如下图:
ADD一个图形,如下图:
Data Source 选择你刚才创建的数据模板中一个,如我选择了MissTime
颜色随便选择了,只要看着习惯就行。
Graph Item Type 就是你绘制的图形类型,比如是一根线还是面积图?我这里选择的是LINE1,绘制出来的图形如下图所示。
Consolidation Function一般来说选择Aveage,这样会让你的图平滑
“CDEF Function”就除以1024, 我这里是跟据我自己的情况来弄的,因为我上面那个脚本是取了纳秒级的数据,如果不加以处理就会很大,不处理,以秒级的话,区间也太小了,对于某些细微的网络状态可能觉察不出来。
Text Format 就是你的图形说明了,一般来说横坐标是时间,纵坐标就是你的数值了,你可以在纵坐标上放尽可能多的数据,只要不影响你的眼睛。
接下来再打印一些文字,主要就是来说明这个图形的,显示最大,最小,平均值等
如下图:
下图就是取当前值:
类型选择“GPRINT”,并选择“LAST”,最后选择Insert Hard Return,这样是为了换行。
5. 到这里基本上已经完成了图形模板制作的全过程了,你可以在Devices里把所要加的图形附加到设备上,然后和正常的制作一般图片一样了。
以下是我一天时间获取的图形:
你可以清楚地了解到主机的运行和网络状况了。

make money online now for free
October 24, 2011 at 6:13 am
Related……
[...]just beneath, are numerous totally not related sites to ours, however, they are surely worth going over[...]……
treat hypothyroidism
October 24, 2011 at 6:41 am
Visitor recommendations…
[...]one of our visitors recently recommended the following website[...]……
a free online dating site
October 24, 2011 at 7:37 am
Superb website…
[...]always a big fan of linking to bloggers that I love but don’t get a lot of link love from[...]……
Sole E95
October 24, 2011 at 1:51 pm
Websites we think you should visit…
[...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]……
trademark
October 24, 2011 at 2:03 pm
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
black ops auto aim
October 24, 2011 at 2:19 pm
Sites we Like……
[...] Every once in a while we choose blogs that we read. Listed below are the latest sites that we choose [...]……
how to hack gmail account
October 24, 2011 at 2:27 pm
Read was interesting, stay in touch……
[...]please visit the sites we follow, including this one, as it represents our picks from the web[...]……
bornetoj
October 24, 2011 at 2:43 pm
Online Article……
[...]The information mentioned in the article are some of the best available [...]……
web scribble
October 24, 2011 at 3:19 pm
Recent Blogroll Additions……
[...]usually posts some very interesting stuff like this. If you’re new to this site[...]……
bodybuilding forum
October 24, 2011 at 3:29 pm
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
resume objective
October 24, 2011 at 4:37 pm
Recommeneded websites…
[...]Here are some of the sites we recommend for our visitors[...]……
Boca Raton Homes For Sale
October 24, 2011 at 4:38 pm
Sources…
[...]check below, are some totally unrelated websites to ours, however, they are most trustworthy sources that we use[...]……
amberjewelry.net
November 23, 2011 at 4:41 am
Lots of Useful Details….
[...]Some insightful data here. Recommended to visit.[...]…
Boynton Beach Pool Company
December 14, 2011 at 8:42 pm
Websites we think you should visit…
[...]although websites we backlink to below are considerably not related to ours, we feel they are actually worth a go through, so have a look[...]……
sonnenbrillen
December 16, 2011 at 7:24 am
Gems form the internet…
[...]very few websites that happen to be detailed below, from our point of view are undoubtedly well worth checking out[...]……
AMG Services Scott Tucker
December 16, 2011 at 8:30 pm
Awesome website…
[...]the time to read or visit the content or sites we have linked to below the[...]……
Rhinoplasty
December 16, 2011 at 11:26 pm
Recommeneded websites…
[...]Here are some of the sites we recommend for our visitors[...]……
custom bull bar
December 18, 2011 at 1:54 am
Great website…
[...]we like to honor many other internet sites on the web, even if they aren’t linked to us, by linking to them. Under are some webpages worth checking out[...]……
certifed nursing assistant
December 18, 2011 at 4:18 am
Websites you should visit…
[...]below you’ll find the link to some sites that we think you should visit[...]……
nette para kazan
December 18, 2011 at 4:32 am
Cool sites…
[...]we came across a cool site that you might enjoy. Take a look if you want[...]……
valuation model
December 18, 2011 at 5:18 am
Links…
[...]Sites of interest we have a link to[...]……
Hojo magnetic motor
December 18, 2011 at 8:12 pm
Websites worth visiting…
[...]here are some links to sites that we link to because we think they are worth visiting[...]……