zabbix监控PHP APC缓存
参考文章
http://john88wang.blog.51cto.com/2165294/1579158
https://github.com/zbal/zabbix/blob/master/scripts/zabbix_php-apc_check.sh
1.监控原理
将APC源码包中的apc.php放到/usr/local/bin/ 目录下
添加nginx子配置文件php-apc_status.conf
server{listen80;server_name127.0.0.1;access_logoff;client_max_body_size5m;autoindexoff;location/{root/usr/local/zabbix/bin/;indexindex.php;autoindexoff;}location~\.php${root/usr/local/zabbix/bin/;fastcgi_pass127.0.0.1:9000;fastcgi_indexindex.php;fastcgi_paramSCRIPT_FILENAME$document_root/$fastcgi_script_name;includefastcgi_params;}}
通过links这个命令可以在命令行下方为HTML页面
links 127.0.0.1/apc.php -dump 2>/dev/null
如果没有这个命令可以用过yum -y install links 安装
2.编写PHP-APC状态信息获取脚本
php-apc_status.sh
#!/bin/bash#Thisscriptisusedtogetphpapccachedatafromapc.phppage#youneedputnginxsub-configfilephp-apc_status.confunderconf/conf.d/directoryapc_metric=$1apc_status_url="http://127.0.0.1/apc.php"apc_status_file=/tmp/php-apc_status.txt/usr/bin/links$apc_status_url-dump2>/dev/null>$apc_status_file#echo$apc_status#weneedtoconvertGBytes,Mbytes,KBytestoBytes#echo"308.345*1024*1024*1024"|bc|cut-f1-d.#331082922721convert_size(){value=$1unit=$2echo$value|grep-E'^[0-9.]+$'2>&1>/dev/nullif[$?-ne0];thenecho"$valueisnotnumber"exit1ficase$unitinBytes)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}#getapcmetricdatacase$apc_metricinversion)cat$apc_status_file|grep"APCVersion"|awk'{print$3}';;cached_files_count)cat$apc_status_file|grep"CachedFiles"|head-1|awk'{print$3}';;cached_files_size)convert_size$(cat$apc_status_file|grep"CachedFiles"|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/(//'-es'/)//'-e's/%//';;misses)cat$apc_status_file|grep"Misses"|head-1|awk'{print$2}';;request_rate)cat$apc_status_file|grep"RequestRate"|head-1|awk'{print$5}';;hit_rate)cat$apc_status_file|grep"HitRate"|head-1|awk'{print$3}';;miss_rate)cat$apc_status_file|grep"MissRate"|head-1|awk'{print$3}';;insert_rate)cat$apc_status_file|grep"InsertRate"|head-1|awk'{print$3}';;cache_full_count)cat$apc_status_file|grep"Cachefullcount"|head-1|awk'{print$4}';;shm_size)#apc.shm_sizecanbe400Mor2G,convertMorGtoBytesshm=$(cat$apc_status_file|grep"apc.shm_size"|head-1|awk'{print$2}')if[$(echo"$shm"|grep'M$')];thensize=$(echo$shm|sed's/M//')echo"$size*1024*1024"|bcelif[$(echo"$shm"|grep'G$')];thensize=$(echo$shm|sed's/G//')echo"$size*1024*1024*1024"|bcfi;;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"pleaseinputtherightparameter";;esac
3.添加zabbix 子配置文件php-apc_status_zabbix.conf
UserParameter=php-apc[*],/usr/local/zabbix/bin/php-apc_status.sh$1
4.创建zabbix的PHP-APC 模板
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。