当光泽面和网站部署在同一台服务器上的时候,我们不可能随时登录上服务器去查看光泽面的命中率,没想到有大神早就写了出来,今天就分享给大家,使用网页查看光泽面命中率。
系统:centos 5.x软件:清漆-3.0.x
ps:3.0以下的版本可以通过窝连接到光泽面管理端口,通过斯达命令查看,3.0以上没有斯达命令,只能通过下面的方法解决。
复制代码代码如下:PHP $ outfile=shell _ exec('/usr/bin/varnishstat-x ');$ XML=简单的XML _ load _ string($ outfile);echo $xml-getName().br/';foreach($xml-children())作为$ child){//$ TMpname=' ';foreach($ child-children()as $ subChild){ if($ subChild-getName()==' name '){ $ tmpName=$ subChild;} else if($ subChild-getName()==' value '){ if($ tmpName!=' '){ $ arys[' $ TMpname ']=$ subChild;$ tmpName=} } else {继续;} } }函数bytereduce($ bytes){ if($ bytes 1099511627776){ return round($ bytes/1099511627776).结核病;} else if($ 1073741824字节){返回回合($bytes/1073741824).' GB ';} else if($ 1048576字节){ return round($ bytes/1048576).' MB ';} else if($ byte 1024){ return round($ bytes/1024).' KB ';} else {返回$字节.b ';} }回显client_conn:$arys['client_conn'].br/';回显client_req:$arys['client_req'].br/';回显cache_hit:$arys['cache_hit'].br/';回显cache_miss:$arys['cache_miss'].br/';回应"缓存命中率:"。round(($ arys[' cache _ hit ']/$ arys[' client _ req '])* 100).% br/';回声最近最少使用算法核对象: '。$arys[n_lru_nuked].br/';回声' '。byteReduce($ arys[' s _ body bytes ']$ arys[' s _ HDR bytes ']).接受(accept的缩写)内容('。byteReduce($arys['s_hdrbytes']).标题字节减少(arys[' s _ body bytes ']).body)';
效果如下:
ps:为了查看实时情况,可以在这监控页加个超文本标记语言定时刷新。好了,这样就方便我们随时查看光泽面的状态了。