1. 程式人生 > >zabbix監控nginx和php

zabbix監控nginx和php

scripts 監控nginx 創建配置文件 follow trigge 新建 推薦 status href

創建zabbix_agentd的子配置文件
在/usr/local/zabbix/etc/zabbix_agentd.d/中創建關聯nginx status和php-fpm status的子配置文件,創建一個,或者在已有的某配置文件中增加也可以,我這裏分別為它們創建配置文件,文件名可自定義,只要確保此文件夾全部內容在zabbix_agentd.conf中包含(include)了。

  1. userparameter_nginx.conf
    [root@monitor-server2 zabbix_agentd.conf.d]# cat userparameter_nginx.conf
    #/usr/local/zabbix/bin/nginx_status.sh
    UserParameter=nginx.status[*],/usr/local/zabbix/bin/nginx_status.sh $1
    #這種寫法比較簡潔,參考zabbix 3.2.4中自帶的的userparameter_examples.conf
    UserParameter=nginx.version,/usr/local/nginx/sbin/nginx -v
    #讓zabbix-agentd獲取nginx的版本信息 ,一切shell指令都推薦使用絕對路徑
  2. userparameter_php-fpm.conf
    [root@monitor-server2 zabbix_agentd.conf.d]# cat userparameter_php-fpm.conf
    #/usr/local/zabbix/bin/php_fpm_status.sh
    UserParameter=php-fpm.status[*],/usr/local/zabbix/bin/php_fpm_status.sh $1
    UserParameter=php-fpm.version,/usr/local/php/sbin/php-fpm -v | awk ‘NR==1{print $0}‘
    #獲取php-fpm版本信息
  3. 確認子配置文件被zabbix_agentd配置文件包含
    確認在/usr/local/zabbix/etc/zabbix_agentd.conf中包含:Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/且沒有被註釋。

zabbix-agent配置自定義key:
UserParameter=nginx.status[],/etc/zabbix/scripts/nginx_status.sh $1
UserParameter=php-fpm.status[
],/usr/bin/curl -s -m 5 "http://127.0.0.1/statusx45?xml" | grep "<$1>" | awk -F‘>|<‘ ‘{ print $$3}‘
#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
UserParameter=chatter.pid[*],ps -ef | grep $1 | grep -v grep | grep $2 | grep -v grep | awk ‘{print $$2}‘
技術分享圖片
zabbix服務端的get數值
[root@mha ~]# zabbix_get -s 192.168.198.131 -k ‘nginx.status[ping]‘
1
技術分享圖片

zabbix頁面:
nginx:
添加nginx status監控模板
技術分享圖片
新建nginx status模板
技術分享圖片
定義nginx status模板
技術分享圖片
新建nginxApplication
技術分享圖片
定義nginx status items,這裏我使用的是被動臨控
技術分享圖片
增加nginx status狀態碼映射
技術分享圖片
nginx trigger定義
技術分享圖片
定義nginx監控視圖

zabbix監控nginx和php