【简介】
根据接到的需求,需要利用cacti监控web站点的可用性等等。而这些需求需要自己自定义cacti模板来实现。接下来我给大家讲解下如何自定义监控。让cacti更具有魅力。
【具体方法】
第一步:写好cacti采集的脚本。本次讲解中以一个实例作为讲解:
monitor.php
< ?php
/**
* @Script: detect monitor.php
* @Author: XuPeng
* @E-mail: grey.trao@gmail.com
* @Creation Date: 2010/9/16
*/
array_shift($_SERVER["argv"]);
print(call_user_func_array("url", $_SERVER["argv"]));
function url($url) {
$ch = curl_init();
$url = $url;
//Set the URL we want to grab
curl_setopt($ch, CURLOPT_URL, $url);
//Make sure cURL doesn't output anything
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Let cURL do its thing
$result = curl_exec($ch);
// close cURL connection
curl_close($ch);
$comment = str_replace("<!--","",str_replace("-->","",$result));
$comment = explode("},",$comment);
$comment = str_replace("{","",str_replace("}","",$comment));
$comment = str_replace(","," ",str_replace("detect:","",str_replace("\"","",$comment[6])));
$mem = explode(" ", $comment);
$mem = explode(":", $mem[1]);
if(empty($mem[1])){
return "time:0.000 memory:-1 count:0";
}else{
return $comment;
}
}
?> |
1.接下来定制Data Input Methods方法(如下图):
2.定制Data Templates模板
3.定制graph templates模板
到此,自定义模板完成。下面看下效果展示吧:


![[转]常见的nginx的配置选项](http://www.jiunile.com/wp-content/themes/xupeng/images/random/11.jpg)














monitor.php,我运行看了下,没有发现你的memory信息,不知道你咋取出来的
谢谢
你触发monitor.php,被监控的网站你能采集到memory信息吗?网站需要对monitor.php 定制!这个只是监控端处理的,还需要你网站那端进行相关的处理