生产环境如下:
操作系统:CentOS release 6.8 (Final)
实战任务:实现Cacti监控nginx运行状态
前期以实现Cacti对操作系统、数据库、Apache等象监,如下图:
对nginx安装编译过程省略,但要注意,编译安装nginx时,要开启此项--with-http_stub_status_module。
在/application/nginx/conf/extra/nginx_vhosts.conf,在该文件配置如下:
server
{
listen 9090;
server_name 117.40.239.9;
location /NginxStatus {
stub_status on;
access_log off;
}
}
[[email protected]]# ../../sbin/nginx -t
nginx:the configuration file /application/nginx-1.10.1/conf/nginx.confsyntax is ok
nginx:configuration file /application/nginx-1.10.1/conf/nginx.conftest is successful
[[email protected]]# ../../sbin/nginx -s reload
测试nginx运行状态页面: http://117.40.239.9:9090/NginxStatus
#下载cacti for nginx 插件包
[[email protected]]# wget http://www.oschina.net/uploads/code/cacti-nginx.tar.gz
[[email protected]]# tree
.
├──cacti_graph_template_nginx_clients_stat.xml
├──cacti_graph_template_nginx_sockets_stat.xml
├── cacti-nginx-readme
├── get_nginx_clients_status.pl
└── get_nginx_socket_status.pl
0 directories,5 files
解压后一共有5个文件,首先把get_nginx_socket_status.pl
以及 get_nginx_clients_status.pl 上传至服务器cacti 目录下scripts 并设置可执行权限跟755读写权限。
[[email protected] scripts]#./get_nginx_clients_status.pl http://117.40.239.9:9090/NginxStatus
nginx_active:1 nginx_reading:0 nginx_writing:1nginx_waiting:0
接下来在cacti管理面板导入两个xml文件
导入的方式是 Import Templates > Import Template from LocalFile (浏览导入插件包另外2个文件)
cacti_graph_template_nginx_clients_stat.xml
cacti_graph_template_nginx_sockets_stat.xml
1.创建device:
3.Graph Trees
测试结果如下:
附:nginx 运行状态信息详解
Active connections: 3 #活跃的连接数量
server accepts handled requests#连接32 ,握手32, 请求处理27
32 32 27
Reading: 0 Writing: 1Waiting: 2
reading — 读取客户端的连接数0
writing — 响应数据到客户端的数量2
waiting — 开启 keep-alive 的情况下,这个值等于 active= (reading+writing)=3