寂寞大萝卜 发表于 2019-1-9 12:16:12

实现Cacti监控nginx运行状态

  生产环境如下:
  操作系统:CentOS release 6.8 (Final)
  实战任务:实现Cacti监控nginx运行状态
前期以实现Cacti对操作系统、数据库、Apache等象监,如下图:
http://s4.运维网.com/wyfs02/M01/83/79/wKiom1d0a8LR0DUmAAGUaEICQcc006.jpg-wh_500x0-wm_3-wmp_4-s_3393215506.jpg
  对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;
     }
  }
  # ../../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
  # ../../sbin/nginx -s reload
  测试nginx运行状态页面: http://117.40.239.9:9090/NginxStatus
http://s3.运维网.com/wyfs02/M02/83/79/wKiom1d0bA7iGaMiAABbPYuI_C0679.jpg-wh_500x0-wm_3-wmp_4-s_821844493.jpg
  #下载cacti for nginx 插件包
  # wgethttp://www.oschina.net/uploads/code/cacti-nginx.tar.gz
  # 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读写权限。
  #./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:
http://s4.运维网.com/wyfs02/M01/83/77/wKioL1d0bH7RhVMtAAIHm2ZxWAo633.jpg-wh_500x0-wm_3-wmp_4-s_4164628811.jpg
  2.Create Graphs for this Host
http://s5.运维网.com/wyfs02/M01/83/79/wKiom1d0bKjBp5-xAACa0Z6Hlzs511.jpg-wh_500x0-wm_3-wmp_4-s_3363512851.jpg
  3.Graph Trees
http://s4.运维网.com/wyfs02/M00/83/79/wKiom1d0bNKj4CQdAAChlhLaTss350.jpg-wh_500x0-wm_3-wmp_4-s_820881488.jpg
  测试结果如下:
http://s2.运维网.com/wyfs02/M01/83/77/wKioL1d0bPKiA8TBAAFpQtdn4N8411.jpg-wh_500x0-wm_3-wmp_4-s_1353974564.jpg

  附: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



页: [1]
查看完整版本: 实现Cacti监控nginx运行状态