在cacti中使用ATS的stats_over_http模塊進行監控部分性能

最近要監控ATS,使用stats_over_http.so模塊可以使用url來查看ats的狀態,在cacti裏面加上了幾個值來監控,包含:

proxy.process.http.completed_requests

所有收到請求,使用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]." ";
// }
?>


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章