共计 5884 个字符,预计需要花费 15 分钟才能阅读完成。
最近要监控 ATS,使用 stats_over_http.so 模块可以使用 url 来查看 ats 的状态,在 cacti 里面加上了几个值来监控,包含:
proxy.process.http.completed_requests
Cacti 利用 stats_over_http.so 模块监控 ats 的部分数据下载:
免费下载地址在 http://linux.linuxidc.com/
用户名与密码都是www.linuxidc.com
具体下载目录在 /2014 年资料 / 1 月 / 2 日 / 在 Cacti 中使用 ATS 的 stats_over_http 模块进行监控部分性能
下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm
所有收到请求,使用 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].” “;
// }
?>
Cacti 的详细介绍:请点这里
Cacti 的下载地址:请点这里
相关阅读:
RHEL6.4 环境 Cacti 中 spine 安装 http://www.linuxidc.com/Linux/2013-11/92797.htm
RHEL6.4 中使用 Cacti+Spine 监控主机实现发送邮件报警 http://www.linuxidc.com/Linux/2013-11/92795.htm
CentOS 5.5 完整安装 Cacti+Spine http://www.linuxidc.com/Linux/2011-12/49701.htm
CentOS 6 下 Cacti 搭建文档 http://www.linuxidc.com/Linux/2013-06/86595.htm
RHEL5.9 下 Cacti 监控部署详解 http://www.linuxidc.com/Linux/2013-06/85427.htm
CentOS 6.3 下 Cacti 安装详解 http://www.linuxidc.com/Linux/2013-05/84279.htm
CentOS Linux 下快速安装配置 Cacti 中文版 http://www.linuxidc.com/Linux/2013-03/81627.htm
更多 RedHat 相关信息见RedHat 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=10