排第四偶家 发表于 2018-11-13 12:48:56

zabbix监控nginx和php、memcached(discuz)

  创建zabbix_agentd的子配置文件
  在/etc/zabbix/zabbix_agentd.d/中创建关联nginx status和php-fpm status的子配置文件,创建一个,或者在已有的某配置文件中增加也可以,我这里分别为它们创建配置文件,文件名可自定义,只要确保此文件夹全部内容在zabbix_agentd.conf中包含(include)了。
  zabbix-agent配置文件的自定义key:

[*]userparameter_nginx.conf  # cat /etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf
  #/usr/local/zabbix/bin/nginx_status.sh
  #UserParameter=nginx.status
[*],/etc/zabbix/scripts/nginx_status.sh $1
  #这种写法比较简洁,参考zabbix 3.2.4中自带的的userparameter_examples.conf
  UserParameter=nginx.version,/usr/sbin/nginx -v
  #UserParameter=nginx.accepts,/etc/zabbix/scripts/check_nginx_status.sh accepts
  #UserParameter=nginx.handled,/etc/zabbix/scripts/check_nginx_status.sh handled
  #UserParameter=nginx.requests,/etc/zabbix/scripts/check_nginx_status.sh requests
  #UserParameter=nginx.connections.active,/etc/zabbix/scripts/check_nginx_status.sh active
  #UserParameter=nginx.connections.reading,/etc/zabbix/scripts/check_nginx_status.sh reading
  #UserParameter=nginx.connections.writing,/etc/zabbix/scripts/check_nginx_status.sh writing
  #UserParameter=nginx.connections.waiting,/etc/zabbix/scripts/check_nginx_status.sh waiting

[*]  userparameter_php-fpm.conf
  # cat /etc/zabbix/zabbix_agentd.d/userparameter_php-fpm_status.conf

  #UserParameter=idle.processe,/etc/zabbix/scripts/php-fpm_status.sh>  #UserParameter=total.processes,/etc/zabbix/scripts/php-fpm_status.sh total
  #UserParameter=active.processes,/etc/zabbix/scripts/php-fpm_status.sh active
  #UserParameter=max.active.processes,/etc/zabbix/scripts/php-fpm_status.sh mactive
  #UserParameter=listen.queue.len,/etc/zabbix/scripts/php-fpm_status.sh listenqueuelen
  #UserParameter=listen.queue,/etc/zabbix/scripts/php-fpm_status.sh listenqueue
  #UserParameter=start.since,/etc/zabbix/scripts/php-fpm_status.sh since
  #UserParameter=accepted.conn,/etc/zabbix/scripts/php-fpm_status.sh conn
  UserParameter=max.children.reached,/etc/zabbix/scripts/php-fpm_status.sh reached
  UserParameter=slow.requests[],/etc/zabbix/scripts/php-fpm_status.sh requests
  #/usr/local/zabbix/bin/php_fpm_status.sh
  UserParameter=php-fpm.status[],/etc/zabbix/scripts/php-fpm_status.sh $1
  UserParameter=php-fpm.version,/usr/local/php56/sbin/php-fpm -v | awk 'NR==1{print $0}'
  #获取php-fpm版本信息
[*]确认子配置文件被zabbix_agentd配置文件包含  确认在/usr/local/zabbix/etc/zabbix_agentd.conf中包含:Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/且没有被注释。

  zabbix服务端的get数值
  # zabbix_get-s 192.168.198.131-k'nginx.status'
  1

  zabbix页面:
  nginx:
  添加nginx status监控模板

  新建nginx status模板

  定义nginx status模板

  新建nginxApplication

  定义nginx status items,这里我使用的是被动临控

  增加nginx status状态码映射

  nginx trigger定义

  定义nginx监控视图
  添加php-fpm status监控模板
  php-fpm status的模板添加步骤和上述方法一样,此处不在赘述。




  1、 选择相应的主机或主机组关联上相应的模板


[*]实际监控效果展示(不知道为什么我的latest data没数据出来)  查看监控效果可以通过查看Monitoring---->Latest data,过滤出相应的主机及应用名进行查看,最新收集的各item的监控结果,凡是监控到数据的item会显示数据,出现灰色的表示没有监控到数据,需要排查原因。如下所示:
  nginx的监控数据
  也可以通过定义的Graphs查看监控效果:
  nginx status监控视图

  nginx request监控视图

  php的监控数据


  memcached监控数据

  zabbix-agent配置添加memcached
  在客户端到/usr/local/zabbix/conf/zabbix_agentd.conf里添加:
  UserParameter=memcached_stats
[*],(echo stats; sleep 1) | telnet 127.0.0.1 $1 2>&1 | awk '/STAT $2 / {print $NF}'
  保存完毕后重启memcached和nginx
  memcached监控模板
  https://pan.baidu.com/s/1mik9jMK

页: [1]
查看完整版本: zabbix监控nginx和php、memcached(discuz)