最近要监控ATS,使用stats_over_http.so模块可以使用url来查看ats的状态,在cacti里面加上了几个值来监控,包含:
proxy.process.http.completed_requests
Cacti利用stats_over_http.so模块监控ats的部分数据下载:
具体下载目录在 /2014年资料/1月/2日/在Cacti中使用ATS的stats_over_http模块进行监控部分性能
所有收到请求,使用count模式统计每秒完成的请求
proxy.process.http.incoming_requests
proxy.process.http.outgoing_requests
进入和出的请求,基本能够描述ats的繁忙程度
proxy.process.http.1xx_responses
proxy.process.http.2xx_responses
proxy.process.http.3xx_responses
proxy.process.http.4xx_responses
proxy.process.http.5xx_responses
给客户端返回的HTTP status code的数量,基本反映服务情况
proxy.process.http.tcp_hit_count_stat    
proxy.process.http.tcp_refresh_hit_count_stat
proxy.process.http.tcp_ims_hit_count_stat
proxy.process.http.tcp_miss_count_stat    
proxy.process.http.tcp_refresh_miss_count_stat
proxy.process.http.tcp_ims_miss_count_stat
6个来计算命中率(命中/(命中+失败)),基本能够反映命中率
ps:cacti,在用php写script/command的时候,echo输出结果必须一次性输出,否则cacti无法接收到结果,比如 echo "a:"."20 ";echo "b:"."30";只能接收到a的值,必须 echo "a:"."20 "."b:"."30";才可以,但在cli里输出是一样的。这点问题折腾了1个上午。
cacti建立模板和输入就大概写个流程,就不仔细写了
1、Data Input Methods,记得选择script/command 就可以了,Input String里对照程序来写比如:
<path_php_binary> -q <path_cacti>/scripts/flashapp_get_ts_stat.php completed_requests <host_ip>
记得填对应的需求就好了,下面的Output fields,大家根据输出来写吧
2、Data Templates
自己起名字了,什么的。不会看前面的文章,注意下面的Data Source Type 选择就好了
3、Graph Templates
这部分 大家根据喜好自己设置吧。
ps附件 cacti模板和php,php放到scripts目录,xml导入就好了
php代码:
<?php 
/* 
* flashapp_ts_get_web_status.php 
* ------------------------------------------------- 
* enable cacti to read ATS status from stats_over_http.so plugin. 
* Originally by tongyuan at flashapp dot cn - 2014/1/2 
* This is simple monitor for ATS,so ...... 
* 
* usage: 
* flashapp_ts_get_web_status.php [completed_requests | hit_ratio | inout_requests | status_code ] [Host_ip] 
* 
* 
* # get from proxy.process.http.completed_requests 
* CMD:    flashapp_ts_get_web_status.php completed_requests [Host_ip] 
* OUTPUT: completed_requests:xxxx 
* CACAI data type:COUNT 
* 
* # get from proxy.process.http.incoming_requests and proxy.process.http.outgoing_requests 
* CMD:    flashapp_ts_get_web_status.php inout_requests [Host_ip] 
* OUTPUT: incoming_requests:xxxx outgoing_requests:xxxx 
* CACTI data type:COUNT 
* 
* # get from proxy.process.http.incoming_requests and proxy.process.http.outgoing_requests 
* CMD:    flashapp_ts_get_web_status.php status_code [Host_ip] 
* OUTPUT: code_axx_responses:xxx code_bxx_responses:xxx code_cxx_responses:xxx code_dxx_responses:xxx code_exx_responses:xxx 
* CACTI data type:COUNT 
* 
* # get simple hit 
* CMD:       flashapp_ts_get_web_status.php hit_ratio [Host_ip] 
* OUTPUT:hit_ratio:0.XXXX 
* CACTI data type:ABSOLUTE 
* EXPRESSION:   (proxy.process.http.tcp_hit_count_stat        + 
*               proxy.process.http.tcp_refresh_hit_count_stat + 
*               proxy.process.http.tcp_ims_hit_count_stat)    / 
* 
*               (proxy.process.http.tcp_hit_count_stat        + 
*               proxy.process.http.tcp_refresh_hit_count_stat + 
*               proxy.process.http.tcp_ims_hit_count_stat     + 
*               
*               proxy.process.http.tcp_miss_count_stat        + 
*               proxy.process.http.tcp_refresh_miss_count_stat+ 
*               proxy.process.http.tcp_ims_miss_count_stat) 
* 
* examle: 
* grant select,show databases on *.* \ 
*   to monitor@'192.168.1.0/255.255.255.0' identified by 'monitor'; 
* 
*/
// read paramater default port 8080, path /_stats 
$server_port=8080; 
$what_get=$_SERVER["argv"][1]; 
$server_ip=$_SERVER["argv"][2]; 
$server_path="_stats"; 
$url = "http://".$server_ip.$server_port."/".$server_path; 
if ($_SERVER["argc"] != 3 ) { 
    echo "Usage : flasahpp_ts_get_web_stats.php  [completed_requests | hit_ratio | inout_requests | status_code ] <Host_ip>\n"; 
    exit(1); 
} 
# deactivate http headers 
$no_http_headers = true; 
# include some cacti files for ease of use
include(dirname(__FILE__) . "/../include/global.php"); 
include(dirname(__FILE__) . "/../lib/snmp.php"); 
// # get stats from server 
$r_str = @file_get_contents($url); 
if (empty($r_str)) {exit(1);} 
// # convert the resault 
$r_str = (array)json_decode($r_str); 
$r_str = (array)$r_str["global"]; 
// count hit ratio 
$hit_hit_count=$r_str["proxy.process.http.tcp_hit_count_stat"]+ 
                $r_str["proxy.process.http.tcp_refresh_hit_count_stat"]+ 
                $r_str["proxy.process.http.tcp_ims_hit_count_stat"]; 
$hit_miss_count=$r_str["proxy.process.http.tcp_miss_count_stat"]+ 
                $r_str["proxy.process.http.tcp_refresh_miss_count_stat"]+ 
                $r_str["proxy.process.http.tcp_ims_miss_count_stat"]; 
$hit_ratio = $hit_hit_count / ($hit_hit_count+$hit_miss_count); 
// get out what u wont. 
if ( $what_get == "completed_requests" ) { 
    echo "completed_requests:".$r_str["proxy.process.http.completed_requests"]; 
    exit(0); 
} 
if ( $what_get == "hit_ratio") { 
    echo "hit_ratio:".$hit_ratio; 
    exit(0); 
} 
if ( $what_get == "inout_requests" ) { 
    $output = "incoming_requests:" . $r_str["proxy.process.http.incoming_requests"]." "
            . "outgoing_requests:" . $r_str["proxy.process.http.outgoing_requests"]."\n"; 
    echo $output; 
    exit(0); 
} 
if ( $what_get == "status_code" ) { 
    $output = "code_axx_responses:" . $r_str["proxy.process.http.1xx_responses"]." "
            . "code_bxx_responses:" . $r_str["proxy.process.http.2xx_responses"]." "
            . "code_cxx_responses:" . $r_str["proxy.process.http.3xx_responses"]." "
            . "code_dxx_responses:" . $r_str["proxy.process.http.4xx_responses"]." "
            . "code_exx_responses:" . $r_str["proxy.process.http.5xx_responses"]."\n"; 
    echo $output; 
    exit(0); 
} 
                       
echo "Usage : flasahpp_ts_get_web_stats.php completed_requests|hit_ratio|inout_requests|status_code <Host_ip> \n"; 
// foreach ($my_fi as $s){ 
//         echo  $s.":".$r_str[$s]." "; 
// } 
?>
