溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

zabbix監(jiān)控PHP APC緩存

發(fā)布時(shí)間:2020-06-20 09:51:16 來源:網(wǎng)絡(luò) 閱讀:1051 作者:自由linux 欄目:web開發(fā)

參考文章

http://john88wang.blog.51cto.com/2165294/1579158

https://github.com/zbal/zabbix/blob/master/scripts/zabbix_php-apc_check.sh



1.監(jiān)控原理

將APC源碼包中的apc.php放到/usr/local/bin/ 目錄下

添加nginx子配置文件php-apc_status.conf

server
{
        listen      80;
        server_name 127.0.0.1;
        access_log  off;
        client_max_body_size 5m;

        autoindex off;
        location / {
            root  /usr/local/zabbix/bin/;
            index index.php;
            autoindex off;
        }

        location ~ \.php$ {
            root           /usr/local/zabbix/bin/;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            include        fastcgi_params;
        }

}


通過links這個(gè)命令可以在命令行下方為HTML頁面

links 127.0.0.1/apc.php -dump 2>/dev/null


如果沒有這個(gè)命令可以用過yum -y install links 安裝


2.編寫PHP-APC狀態(tài)信息獲取腳本

php-apc_status.sh

#!/bin/bash
#This script is used to get php apc cache data from  apc.php page
#you need put nginx sub-config file php-apc_status.conf under conf/conf.d/ directory
apc_metric=$1
apc_status_url="http://127.0.0.1/apc.php"
apc_status_file=/tmp/php-apc_status.txt
/usr/bin/links $apc_status_url -dump 2>/dev/null > $apc_status_file
#echo $apc_status

#we need to convert GBytes,Mbytes,KBytes to Bytes
#echo "308.345 * 1024 * 1024 * 1024"|bc|cut -f1 -d.
#331082922721
convert_size() {
  value=$1
  unit=$2

  echo $value | grep -E '^[0-9.]+$' 2>&1 > /dev/null
  if [ $? -ne 0 ]; then
    echo "$value is not number"
    exit 1
  fi

  case $unit in
    Bytes)
          echo "$value"
        ;;
   KBytes) 
          echo "$value * 1024" | bc | cut -f1 -d. 
        ;;
   MBytes) 
          echo "$value * 1024 * 1024" | bc | cut -f1 -d. 
        ;;
   GBytes) 
          echo "$value * 1024 * 1024 * 1024" | bc | cut -f1 -d. 
        ;;
  esac
}

#get apc metric data 
case $apc_metric in
            version)
                  cat $apc_status_file|grep "APC Version"|awk '{print $3}'
                 ;;
 cached_files_count)
                  cat $apc_status_file|grep "Cached Files"|head -1|awk '{print $3}'
                 ;;
  cached_files_size)
                  convert_size   $(cat $apc_status_file|grep "Cached Files"|awk '{print $4 " " $5}'|sed -e 's/(//' -e 's/)//')        
                 ;;
               hits)
                  cat $apc_status_file|grep  "Hits"|head -1|awk '{print $2}' 
                 ;;
              phits)
                  cat $apc_status_file|grep "Free"|head -1|awk '{print $7}'|sed -e 's/(//' -e s'/)//' -e 's/%//'
                 ;;
             misses)
                  cat $apc_status_file|grep  "Misses"|head -1|awk '{print $2}'
                 ;;
       request_rate)
                  cat $apc_status_file|grep  "Request Rate"|head -1|awk '{print $5}'
                 ;;        
           hit_rate)
                  cat $apc_status_file|grep "Hit Rate"|head -1|awk '{print $3}'
                 ;;
          miss_rate)
                  cat $apc_status_file|grep "Miss Rate"|head -1| awk '{print $3}'
                 ;;
        insert_rate)
                  cat $apc_status_file|grep "Insert Rate"|head -1| awk '{print $3}'
                 ;;
   cache_full_count) 
                  cat $apc_status_file|grep "Cache full count"|head -1|awk '{print $4}'
                 ;;
           shm_size)
                   #apc.shm_size can be 400M or 2G , convert M or G to Bytes
                   shm=$(cat $apc_status_file|grep "apc.shm_size"|head -1| awk '{print $2}')
                   if [ $(echo "$shm"|grep 'M$') ];then 
                     size=$(echo $shm|sed 's/M//')
                     echo "$size * 1024 * 1024"|bc
                   elif [ $(echo "$shm"|grep 'G$') ];then
                     size=$(echo $shm|sed 's/G//')
                     echo "$size * 1024 * 1024 * 1024"|bc
                   fi
                 ;;      
           mem_free) 			
                  convert_size $(cat $apc_status_file|grep "Free"|head -1|awk '{print $2 " " $3}')
                 ;;
           mem_used) 			
                  convert_size $(cat $apc_status_file|grep "Used"|head -1|awk '{print $2 " " $3}')
                 ;;
          mem_pused)
                  cat $apc_status_file|grep "Used"|head -1|awk '{print $4}'|sed -e 's/(//' -e 's/)//' -e 's/%//'
                 ;;
          
      fragmentation) 		
                  cat $apc_status_file|grep "Fragmentation:"|head -1|awk '{print $2}'|sed -e 's/%//'
                 ;;
                  *)
                  echo "please input the right parameter"
                 ;;     
esac

3.添加zabbix 子配置文件php-apc_status_zabbix.conf

UserParameter=php-apc[*],/usr/local/zabbix/bin/php-apc_status.sh $1


4.創(chuàng)建zabbix的PHP-APC 模板

zabbix監(jiān)控PHP  APC緩存

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI