阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Zabbix监控Nginx、PHP和Memcached状态

144次阅读
没有评论

共计 3374 个字符,预计需要花费 9 分钟才能阅读完成。

创建 zabbix_agentd 的子配置文件

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

zabbix-agent 配置文件的自定义 key:

  1. userparameter_nginx.conf
    [root@spark ~]# 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

  1. userparameter_php-fpm.conf
    [root@spark ~]# cat /etc/zabbix/zabbix_agentd.d/userparameter_php-fpm_status.conf
    #UserParameter=idle.processe,/etc/zabbix/scripts/php-fpm_status.sh idle
    #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 版本信息

  2. 确认子配置文件被 zabbix_agentd 配置文件包含
    确认在 /usr/local/zabbix/etc/zabbix_agentd.conf 中包含:Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/ 且没有被注释。

Zabbix 监控 Nginx、PHP 和 Memcached 状态
zabbix 服务端的 get 数值
[root@mha ~]# zabbix_get -s 192.168.198.131 -k ‘nginx.status[ping]’
1
Zabbix 监控 Nginx、PHP 和 Memcached 状态

zabbix 页面:
nginx:
添加 nginx status 监控模板
Zabbix 监控 Nginx、PHP 和 Memcached 状态
新建 nginx status 模板
Zabbix 监控 Nginx、PHP 和 Memcached 状态
定义 nginx status 模板
Zabbix 监控 Nginx、PHP 和 Memcached 状态
新建 nginxApplication
Zabbix 监控 Nginx、PHP 和 Memcached 状态
定义 nginx status items,这里我使用的是被动临控
Zabbix 监控 Nginx、PHP 和 Memcached 状态
增加 nginx status 状态码映射
Zabbix 监控 Nginx、PHP 和 Memcached 状态
nginx trigger 定义
Zabbix 监控 Nginx、PHP 和 Memcached 状态
定义 nginx 监控视图

添加 php-fpm status 监控模板
php-fpm status 的模板添加步骤和上述方法一样,此处不在赘述。
Zabbix 监控 Nginx、PHP 和 Memcached 状态

Zabbix 监控 Nginx、PHP 和 Memcached 状态

Zabbix 监控 Nginx、PHP 和 Memcached 状态

Zabbix 监控 Nginx、PHP 和 Memcached 状态

1、选择相应的主机或主机组关联上相应的模板
Zabbix 监控 Nginx、PHP 和 Memcached 状态

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

nginx 的监控数据

也可以通过定义的 Graphs 查看监控效果:
nginx status 监控视图
Zabbix 监控 Nginx、PHP 和 Memcached 状态
nginx request 监控视图
Zabbix 监控 Nginx、PHP 和 Memcached 状态

php 的监控数据
Zabbix 监控 Nginx、PHP 和 Memcached 状态

Zabbix 监控 Nginx、PHP 和 Memcached 状态

memcached 监控数据
Zabbix 监控 Nginx、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 监控模板可以到 Linux 公社资源站下载:

—————————————— 分割线 ——————————————

免费下载地址在 http://linux.linuxidc.com/

用户名与密码都是www.linuxidc.com

具体下载目录在 /2018 年资料 / 3 月 / 7 日 /Zabbix 监控 Nginx、PHP 和 Memcached 状态 /

下载方法见 http://www.linuxidc.com/Linux/2013-07/87684.htm

—————————————— 分割线 ——————————————

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-21发表,共计3374字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中