Submitted by admin on 2011, December 22, 9:01 PM
Cache就是浏览器的缓存技术,大家肯定不陌生,浏览器在每次加载一个文件的时候,都要去自己的缓存文件夹里面去查找是否存在可用缓存,如果存在,则不再去服务器下载而直接使用本地内容,这是一个很好的节省服务器性能和流量的方式,在网站不做任何设置的情况下,浏览器会根据用户的设置来确定是否使用缓存,可见浏览器的“Internet选项”的“浏览历史纪录”的“设置”部分。
通常来讲,Cache设置有两种方式:第一种是在HTML内容的head之中设置:
<meta http-equiv="Expires" CONTENT="0"> //这一句设置文件的过期时间为0秒
<meta http-equiv="Cache-Control" CONTENT="no-cache"> //这一句设置文件禁止被缓存
第二种是通过HTTP Head来设置,例如在.NET(C#)之中:
Response.Cache.SetExpires(time);//设置文件的过期时间为当前的时间。
我个人比较喜欢通过HTTP HEAD这种方式来设置,因为我觉得这不属于HTML本身的内容,当然,如果是静态文件,就只能通过html head来设置了,在我的网站"地名信息系统"之中,我设置了每个HTML页面在7天后失效,因为该HTML是自动生成的。
在上面的Cache介绍之中,提到了浏览器在存在缓存的时候不去服务器取相关的内容,可是仅仅这样设置,好像有时候这些浏览器还是去服务器请求,有些时候的请求很合理,例如用户点击“刷新”按钮的时候,有些时候我也不知道为什么,因此,我在系统之中进一步使用了HTTP状态码。
HTTP状态码有很多用户不愿意去了解,其实这是很重要的内容,至于怎么个重要法,以及详细的使用说明请大家去参考相关的文档,我这里举几个例子:
1.有的用户在网站页面不存在的时候显示了自己定义的页面,可是忘记使用404状态码,这样浏览器就不知道它下载的内容究竟是正常内容还是页面不存在的提示,可能用户能从页面内容上分辨出来,可是搜索引擎的机器人不会,因此就可能会被搜索引擎列入“无法检索”的黑名单。
2.在页面转向的时候不使用301或者302的状态码,造成搜索引擎不知道叶面已经被转向。
我专门要说的304是一个用处和Cache相同的东西,这个状态码的含义是“服务器端没有更新”,也就是说客户端的文件版本是最新的,他的用法是这样的:
1.当用户首次请求该文件的时候,通过HTTP HEAD的Last-Modified字段将该文件的最后修改日期发送到客户端,让客户端知道该文件的版本,例如:
Last-Modified: Tue, 08 Apr 2008 14:48:05 GMT
2.在浏览器再次请求该文件的时候,会自动将该时间作为请求的HTTP HEAD的If-Modified-Since字段内容(有时候根据浏览器的不同,可能会用逗号隔开附加上文件的字节数大小),例如:
If-Modified-Since: Tue, 08 Apr 2008 14:48:05 GMT
3.服务端根据If-Modified-Since字段的内容(如果存在该字段)来判断客户端的文件是否已经过期,如果已经过期,则重新返回新的文件,如果没有,则只需要返回304状态码,就可结束输出,这样代表浏览器端的文件版本是最新的,不需要返回文件内容。
要知道,服务器返回一个304的时间要比返回整个文件的时间要小得多,性能损耗和网络占用也小得多。
Cache和304技术有一定的重复,我选择Cache和304技术一起使用是因为单用Cache好像浏览器有时候还是去取最新内容(尤其是用户点击刷新按钮的时候),而单独使用304则在浏览器向服务器询问的过程还是会占用一定的性能和时间。这两种技术结合起来使用是刚刚好的。
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:895
Submitted by admin on 2011, September 29, 2:53 PM
#cat /var/log/squid/access.log|gawk '{print $4}'|sort|uniq -c|sort -nr
如果看到很多的TCP_MEM_HIT ,这表明该文件是从内存缓存读取的,squid已经起作用了!你再用浏览器打开该文件,应该是快如闪电了。。呵呵,大功告成了!还有其他类型的HIT,如TCP_HIT等等,这些是从磁盘读取的,我觉得加速的意义不大,只不过缓解了apache的压力而已。
相应于HTTP请求,下列标签可能出现在access.log文件的第四个域。
TCP_HIT
Squid发现请求资源的貌似新鲜的拷贝,并将其立即发送到客户端。
TCP_MISS
Squid没有请求资源的cache拷贝。
TCP_REFERSH_HIT
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。原始服务器返回304(未修改)响应,指示squid的拷贝仍旧是新鲜的。
TCP_REF_FAIL_HIT
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。然而,原始服务器响应失败,或者返回的响应Squid不能理解。在此情形下,squid发送现有cache拷贝(很可能是陈旧的)到客户端。
TCP_REFRESH_MISS
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。原始服务器响应新的内容,指示这个cache拷贝确实是陈旧的。
TCP_CLIENT_REFRESH_MISS
Squid发现了请求资源的拷贝,但客户端的请求包含了Cache-Control: no-cache指令。Squid转发客户端的请求到原始服务器,强迫cache确认。
TCP_IMS_HIT
客户端发送确认请求,Squid发现更近来的、貌似新鲜的请求资源的拷贝。Squid发送更新的内容到客户端,而不联系原始服务器。
TCP_SWAPFAIL_MISS
Squid发现请求资源的有效拷贝,但从磁盘装载它失败。这时squid发送请求到原始服务器,就如同这是个cache丢失一样。
TCP_NEGATIVE_HIT
在对原始服务器的请求导致HTTP错误时,Squid也会cache这个响应。在短时间内对这些资源的重复请求,导致了否命中。 negative_ttl指令控制这些错误被cache的时间数量。请注意这些错误只在内存cache,不会写往磁盘。下列HTTP状态码可能导致否定 cache(也遵循于其他约束): 204, 305, 400, 403, 404, 405, 414, 500, 501, 502, 503, 504。
TCP_MEM_HIT
Squid在内存cache里发现请求资源的有效拷贝,并将其立即发送到客户端。注意这点并非精确的呈现了所有从内存服务的响应。例如,某些cache在内存里,但要求确认的响应,会以TCP_REFRESH_HIT, TCP_REFRESH_MISS等形式记录。
TCP_DENIED
因为http_access或http_reply_access规则,客户端的请求被拒绝了。注意被http_access拒绝的请求在第9域的值是NONE/-,然而被http_reply_access拒绝的请求,在相应地方有一个有效值。
TCP_OFFLINE_HIT
当offline_mode激活时,Squid对任何cache响应返回cache命中,而不用考虑它的新鲜程度。
TCP_REDIRECT
重定向程序告诉Squid产生一个HTTP重定向到新的URI(见11.1节)。正常的,Squid不会记录这些重定向。假如要这样做,必须在编译squid前,手工定义LOG_TCP_REDIRECTS预处理指令。
NONE
无分类的结果用于特定错误,例如无效主机名。
相应于ICP查询,下列标签可能出现在access.log文件的第四域。
UDP_HIT
Squid在cache里发现请求资源的貌似新鲜的拷贝。
UDP_MISS
Squid没有在cache里发现请求资源的貌似新鲜的拷贝。假如同一目标通过HTTP请求,就可能是个cache丢失。请对比UDP_MISS_NOFETCH。
UDP_MISS_NOFETCH
跟UDP_MISS类似,不同的是这里也指示了Squid不愿去处理相应的HTTP请求。假如使用了-Y命令行选项,Squid在启动并编译其内存索引时,会返回这个标签而不是UDP_MISS。
UDP_DENIED
因为icp_access规则,ICP查询被拒绝。假如超过95%的到某客户端的ICP响应是UDP_DENIED,并且客户端数据库激活了(见附录A),Squid在1小时内,停止发送任何ICP响应到该客户端。若这点发生,你也可在cache.log里见到一个警告。
UDP_INVALID
Squid接受到无效查询(例如截断的消息、无效协议版本、URI里的空格等)。Squid发送UDP_INVALID响应到客户端。
附:HTTP响应状态码
Table 13-1列出了数字HTTP响应CODE和理由短句。注意Squid和其他HTTP客户端仅仅关注这些数字值。理由短句是纯解释性的,不会影响响应的意义。对每个状态码,也提供了一个到RFC 2616的具体节的索引。注意状态码0和600是squid使用的非标准的值,不会在RFC里提到。
Table 13-1. HTTP response status codes
Code |
Reason phrase |
RFC 2616 section |
0 |
No Response Received (Squid-specific) |
N/A |
1xx |
Informational |
10.1 |
100 |
Continue |
10.1.1 |
101 |
Switching Protocols |
10.1.2 |
2xx |
Successful |
10.2 |
200 |
OK |
10.2.1 |
201 |
Created |
10.2.2 |
202 |
Accepted |
10.2.3 |
203 |
Non-Authoritative Information |
10.2.4 |
204 |
No Content |
10.2.5 |
205 |
Reset Content |
10.2.6 |
206 |
Partial Content |
10.2.7 |
3xx |
Redirection |
10.3 |
300 |
Multiple Choices |
10.3.1 |
301 |
Moved Permanently |
10.3.2 |
302 |
Found |
10.3.3 |
303 |
See Other |
10.3.4 |
304 |
Not Modified |
10.3.5 |
305 |
Use Proxy |
10.3.6 |
306 |
(Unused) |
10.3.7 |
307 |
Temporary Redirect |
10.3.8 |
4xx |
Client Error |
10.4 |
400 |
Bad Request |
10.4.1 |
401 |
Unauthorized |
10.4.2 |
402 |
Payment Required |
10.4.3 |
403 |
Forbidden |
10.4.4 |
404 |
Not Found |
10.4.5 |
405 |
Method Not Allowed |
10.4.6 |
406 |
Not Acceptable |
10.4.7 |
407 |
Proxy Authentication Required |
10.4.8 |
408 |
Request Timeout |
10.4.9 |
409 |
Conflict |
10.4.10 |
410 |
Gone |
10.4.11 |
411 |
Length Required |
10.4.12 |
412 |
Precondition Failed |
10.4.13 |
413 |
Request Entity Too Large |
10.4.14 |
414 |
Request-URI Too Long |
10.4.15 |
415 |
Unsupported Media Type |
10.4.16 |
416 |
Requested Range Not Satisfiable |
10.4.17 |
417 |
Expectation Failed |
10.4.18 |
5xx |
Server Error |
10.5 |
500 |
Internal Server Error |
10.5.1 |
501 |
Not Implemented |
10.5.2 |
502 |
Bad Gateway |
10.5.3 |
503 |
Service Unavailable |
10.5.4 |
504 |
Gateway Timeout |
10.5.5 |
505 |
HTTP Version Not Supported |
10.5.6 |
6xx |
Proxy Error |
N/A |
600 |
Unparseable Response Headers (Squid-specific) |
N/A |
Code Reason phrase RFC 2616 section
0 No Response Received (Squid-specific) N/A
1xx Informational 10.1
100 Continue 10.1.1
101 Switching Protocols 10.1.2
2xx Successful 10.2
200 OK 10.2.1
201 Created 10.2.2
202 Accepted 10.2.3
203 Non-Authoritative Information 10.2.4
204 No Content 10.2.5
205 Reset Content 10.2.6
206 Partial Content 10.2.7
3xx Redirection 10.3
300 Multiple Choices 10.3.1
301 Moved Permanently 10.3.2
302 Found 10.3.3
303 See Other 10.3.4
304 Not Modified 10.3.5
305 Use Proxy 10.3.6
306 (Unused) 10.3.7
307 Temporary Redirect 10.3.8
4xx Client Error 10.4
400 Bad Request 10.4.1
401 Unauthorized 10.4.2
402 Payment Required 10.4.3
403 Forbidden 10.4.4
404 Not Found 10.4.5
405 Method Not Allowed 10.4.6
406 Not Acceptable 10.4.7
407 Proxy Authentication Required 10.4.8
408 Request Timeout 10.4.9
409 Conflict 10.4.10
410 Gone 10.4.11
411 Length Required 10.4.12
412 Precondition Failed 10.4.13
413 Request Entity Too Large 10.4.14
414 Request-URI Too Long 10.4.15
415 Unsupported Media Type 10.4.16
416 Requested Range Not Satisfiable 10.4.17
417 Expectation Failed 10.4.18
5xx Server Error 10.5
500 Internal Server Error 10.5.1
501 Not Implemented 10.5.2
502 Bad Gateway 10.5.3
503 Service Unavailable 10.5.4
504 Gateway Timeout 10.5.5
505 HTTP Version Not Supported 10.5.6
6xx Proxy Error N/A
600 Unparseable Response Headers (Squid-specific) N/A
Code |
Reason phrase |
RFC 2616 section |
0 |
No Response Received (Squid-specific) |
N/A |
1xx |
Informational |
10.1 |
100 |
Continue |
10.1.1 |
101 |
Switching Protocols |
10.1.2 |
2xx |
Successful |
10.2 |
200 |
OK |
10.2.1 |
201 |
Created |
10.2.2 |
202 |
Accepted |
10.2.3 |
203 |
Non-Authoritative Information |
10.2.4 |
204 |
No Content |
10.2.5 |
205 |
Reset Content |
10.2.6 |
206 |
Partial Content |
10.2.7 |
3xx |
Redirection |
10.3 |
300 |
Multiple Choices |
10.3.1 |
301 |
Moved Permanently |
10.3.2 |
302 |
Found |
10.3.3 |
303 |
See Other |
10.3.4 |
304 |
Not Modified |
10.3.5 |
305 |
Use Proxy |
10.3.6 |
306 |
(Unused) |
10.3.7 |
307 |
Temporary Redirect |
10.3.8 |
4xx |
Client Error |
10.4 |
400 |
Bad Request |
10.4.1 |
401 |
Unauthorized |
10.4.2 |
402 |
Payment Required |
10.4.3 |
403 |
Forbidden |
10.4.4 |
404 |
Not Found |
10.4.5 |
405 |
Method Not Allowed |
10.4.6 |
406 |
Not Acceptable |
10.4.7 |
407 |
Proxy Authentication Required |
10.4.8 |
408 |
Request Timeout |
10.4.9 |
409 |
Conflict |
10.4.10 |
410 |
Gone |
10.4.11 |
411 |
Length Required |
10.4.12 |
412 |
Precondition Failed |
10.4.13 |
413 |
Request Entity Too Large |
10.4.14 |
414 |
Request-URI Too Long |
10.4.15 |
415 |
Unsupported Media Type |
10.4.16 |
416 |
Requested Range Not Satisfiable |
10.4.17 |
417 |
Expectation Failed |
10.4.18 |
5xx |
Server Error |
10.5 |
500 |
Internal Server Error |
10.5.1 |
501 |
Not Implemented |
10.5.2 |
502 |
Bad Gateway |
10.5.3 |
503 |
Service Unavailable |
10.5.4 |
504 |
Gateway Timeout |
10.5.5 |
505 |
HTTP Version Not Supported |
10.5.6 |
6xx |
Proxy Error |
N/A |
600 |
Unparseable Response Headers (Squid-specific) |
N/A |
假如Squid从原始服务器没有接受到任何响应,你可在access.log里看到状态码0。假如Squid接受到的响应没有包含HTTP头部,就会出现状态码600。在少数情况下,某些原始服务器仅发送响应body,而忽略了任何头部。
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:1137
Submitted by admin on 2011, August 1, 8:14 PM
实验室一直使用Squid来做代理服务器,今天突发奇想希望统计一下大家的上网情况。故写了一个简单的网络流量分析脚本。拿来和大家分享一下。
首先得打开Squid的access_log功能:
access_log /usr/local/squid/var/logs/access.log squid
默认的日志格式如下:
access.log中的日志规则:time elapsed remotehost code/status bytes method URL rfc931 peerstatus/peerhost type
1 time 表示客户端访问的时间,毫秒,从1970/0101开始
2 elapsed 客户请求所花费的时间,毫秒
3 remotedhost 客户机的IP地址
4 code/status 客户请求类型/HTTP返回码
5 bytes 客户请求的数据大小
6 method 客户请求的方法
7 URL 客户请求的URL
8 rfc931 客户认证信息
9 peerstatus/peerhost 缓冲/目的IP
10 type 客户请求对象类型
查看活跃的客户端
cat access.log | awk '{print$3}' | sort > sortresult.log
cat access.log | awk '{print$3}' | sort -u > iplist.log
sortresult.log中存储就是每次访问来源的IP地址,iplist.log中存储的是sortresult中不重复的IP,也就是客户端IP列表。
查看总的链接请求个数:
cat sortlist.log | wc -l
查看某个IP发出了多少次链接请求:
cat sortlist.log | grep 210.45.***.*** |wc -l
流量统计
统计总的数据流量大小(以M为单位):cat access.log |awk '{print $5}'|awk '{m+=$1}END{print m/1024/1024}'
查看各种请求方式的数量(以POST为例):
cat access.log | awk '{print $6}'|grep "POST"|wc -l
查看有多少链接来自腾讯QQ:cat access.log |grep ".qq.com" |wc -l
最后将希望特别关注的信息写入了一个shell脚本,以日志文件名为参数,产生自己关心的数据。
#!/bin/bash
echo -n "总的网络链接数:"
cat $1 | wc -l
echo -n "访问数据总流量(单位:M)"
cat $1 |awk '{print $5}'|awk '{m+=$1}END{print m/1024/1024}'
echo -n "访问 renren.com的链接数:"
cat $1 | grep ".renren."|wc -l
echo -n "访问 xiaonei.com的链接数:"
cat $1 | grep ".xiaonei."|wc -l
echo -n "访问 qq.com的链接数:"
cat $1 |grep ".qq."|wc -l
echo -n "访问 taobao.com的链接数:"
cat $1 | grep ".taobao."|wc -l
echo -n "访问 youku.com的链接数:"
cat $1 | grep ".youku."|wc -l
echo -n "访问 ykimg.com(youku的镜像站点)的链接数:"
cat $1 | grep ".ykimg."|wc -l
echo -n "访问 ku6.com的链接数:"
cat $1 |grep ".ku6."|wc -l
echo -n "访问 tudou.com的链接数:"
cat $1 |grep ".tudou."|wc -l
echo -n "访问 paipai.com的链接数:"
cat $1 |grep ".paipai."|wc -l
echo -n "访问 sina.com的链接数:"
cat $1 | grep ".sina."|wc -l
echo -n "访问 163.com的链接数:"
cat $1 | grep ".163."|wc -l
echo -n "访问 sohu.com的链接数:"
cat $1 | grep ".sohu."|wc -l
echo -n "访问 xunlei.com的链接数:"
cat $1 |grep ".xunlei."|wc -l
echo -n "访问 baidu.com的链接数:"
cat $1 |grep ".baidu."|wc -l
echo -n "访问 google.com的链接数:"
cat $1 |grep ".google."|wc -l
echo -n "访问 neu6.edu的链接数:"
cat $1 |grep ".neu6."|wc -l
对下午4个小时的网络日志进行分析的结果是:
总的网络链接数:48441
访问数据总流量(单位:M)1587.98
访问 renren.com的链接数:1253
访问 xiaonei.com的链接数:94
访问 qq.com的链接数:6461
访问 taobao.com的链接数:3544
访问 youku.com的链接数:1610
访问 ykimg.com(youku的镜像站点)的链接数:953
访问 ku6.com的链接数:54
访问 tudou.com的链接数:113
访问 paipai.com的链接数:1349
访问 sina.com的链接数:1602
访问 163.com的链接数:1692
访问 sohu.com的链接数:501
访问 xunlei.com的链接数:58
访问 baidu.com的链接数:2375
访问 google.com的链接数:1464
访问 neu6.edu的链接数:388
转
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:1079
Submitted by admin on 2011, August 1, 8:13 PM
以前写了个Squid防盗链,不好用,现在更新了一下,有更加好用的。呵呵.
见下面的内容。我设置的例子是在squid上对mp3和wma进行控制防盗链.其实原理很容易啦,主要是对referer进行控制,更加高级的大家可以研究一下用cookie来进行控制。有空我也写个出来.
acl wmvurl url_regex -i \.mp3$ \.wma$ \.exe$
#要控制的后缀
acl phpoaref referer_regex -i ^http://.*\.php-oa\.com
#可以链接的网站
acl legalplayer browser -i Firefox ^NSPlayer ^contype$ ^rma ^windows-media-player ^foobar2000 ^RealMedia ^RealPlayer
#要在线直播的软件
http_access allow legalplayer wmvurl
http_access allow phpoaref wmvurl
#先让上面这些条件都可以的,让他们可以通过
http_access deny !phpoaref wmvurl
http_access deny !legalplayer wmvurl
#先accept后deny.
deny_info http://www.php-oa.com/error.jpg phpoaref
#deny时出错时,给显示的出错的图
转
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:1022
Submitted by admin on 2011, August 1, 8:12 PM
squid日志里面默认记录的时间都是根据标准时间计算后加上毫秒记录的,不便于查看。
网上搜了搜,仿佛有许多方法都可以进行转换,但是想想还是麻烦,其实squid可以直接改日志的记录格式的。
打开squid的配置文件/etc/squid/squid.conf
找到下面这句,并取消注释
#logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%S
再找到:
access_log /var/log/squid/access.log squid
修改成
access_log /var/log/squid/access.log combined
重启squid
得到的日志格式就跟apache日志格式相似了
转
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:1025
Submitted by admin on 2011, August 1, 8:11 PM
在squid中access访问日志最为重要,位于/var/log/squid/access.log,常用的记录格式如下
例如:
下面来看看意思
1206507660.803 84367 192.168.1.114 TCP_MISS/502 1486 GET
http://123.138.238.114/QQ2008SpringKB1.exe - DIRECT/123.138.238.114 text/html
logformat squid %ts.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
解释如下:
%ts Seconds since epoch;
%03tu subsecond time (milliseconds);
%6tr Response time (milliseconds);
%>a Client source IP address;
%Ss Squid request status (TCP_MISS etc);
%03Hs HTTP status code;
%<st Reply size including HTTP headers;
%rm Request method (GET/POST etc) ;
%ru Request URL;
%un User name;
%Sh Squid hierarchy status (DEFAULT_PARENT etc);
%<A Client FQDN;
%mt MIME content type
我喜欢下面这样,可以输出 squid 日志的请求头
logformat squid_test_log %{%y%m%d%H%M%S}tl.%03tu %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt "%>h"
>h Request header. Optional header name argument on the format header[:[separator]element]
<h Reply header. Optional header name argument as for >h
squid的日志很重要。常常要了解的,其中最重要的就是命中率啦,不然反向代理做的用就不大。
#cat access.log|gawk ‘{print $4}’|sort|uniq -c|sort -nr
9568 TCP_IMS_HIT/304
6313 TCP_HIT/200
2133 TCP_MISS/200
1568 TCP_MISS/206
587 TCP_MEM_HIT/200
531 TCP_MISS/304
207 TCP_REFRESH_HIT/200
152 TCP_REFRESH_HIT/304
86 TCP_NEGATIVE_HIT/404
69 TCP_MISS/404
9 TCP_MISS/000
4 TCP_MISS/503
1 TCP_REFRESH_MISS/000
1 TCP_DENIED/400
可以使用上面的方法,大约的分析一下命令中比。什么意思就看下面的详解.
#cat /var/log/squid/access.log |grep TCP_MEM_HIT
如果看到很多的TCP_MEM_HIT ,这表明该文件是从内存缓存读取的,squid已经起作用了!你再用浏览器打开该文件,应该是快如闪电了。。呵呵,大功告成了!还有其他类型的HIT,如TCP_HIT等等,这些是从磁盘读取的,我觉得加速的意义不大,只不过缓解了apache的压力而已。
相应于HTTP请求,下列标签可能出现在access.log文件的第四个域。
TCP_HIT
Squid发现请求资源的貌似新鲜的拷贝,并将其立即发送到客户端。
TCP_MISS
Squid没有请求资源的cache拷贝。
TCP_REFERSH_HIT
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。原始服务器返回304(未修改)响应,指示squid的拷贝仍旧是新鲜的。
TCP_REF_FAIL_HIT
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。然而,原始服务器响应失败,或者返回的响应Squid不能理解。在此情形下,squid发送现有cache拷贝(很可能是陈旧的)到客户端。
TCP_REFRESH_MISS
Squid发现请求资源的貌似陈旧的拷贝,并发送确认请求到原始服务器。原始服务器响应新的内容,指示这个cache拷贝确实是陈旧的。
TCP_CLIENT_REFRESH_MISS
Squid发现了请求资源的拷贝,但客户端的请求包含了Cache-Control: no-cache指令。Squid转发客户端的请求到原始服务器,强迫cache确认。
TCP_IMS_HIT
客户端发送确认请求,Squid发现更近来的、貌似新鲜的请求资源的拷贝。Squid发送更新的内容到客户端,而不联系原始服务器。
TCP_SWAPFAIL_MISS
Squid发现请求资源的有效拷贝,但从磁盘装载它失败。这时squid发送请求到原始服务器,就如同这是个cache丢失一样。
TCP_NEGATIVE_HIT
在对原始服务器的请求导致HTTP错误时,Squid也会cache这个响应。在短时间内对这些资源的重复请求,导致了否命中。 negative_ttl指令控制这些错误被cache的时间数量。请注意这些错误只在内存cache,不会写往磁盘。下列HTTP状态码可能导致否定 cache(也遵循于其他约束): 204, 305, 400, 403, 404, 405, 414, 500, 501, 502, 503, 504。
TCP_MEM_HIT
Squid在内存cache里发现请求资源的有效拷贝,并将其立即发送到客户端。注意这点并非精确的呈现了所有从内存服务的响应。例如,某些cache在内存里,但要求确认的响应,会以TCP_REFRESH_HIT, TCP_REFRESH_MISS等形式记录。
TCP_DENIED
因为http_access或http_reply_access规则,客户端的请求被拒绝了。注意被http_access拒绝的请求在第9域的值是NONE/-,然而被http_reply_access拒绝的请求,在相应地方有一个有效值。
TCP_OFFLINE_HIT
当offline_mode激活时,Squid对任何cache响应返回cache命中,而不用考虑它的新鲜程度。
TCP_REDIRECT
重定向程序告诉Squid产生一个HTTP重定向到新的URI(见11.1节)。正常的,Squid不会记录这些重定向。假如要这样做,必须在编译squid前,手工定义LOG_TCP_REDIRECTS预处理指令。
NONE
无分类的结果用于特定错误,例如无效主机名。
相应于ICP查询,下列标签可能出现在access.log文件的第四域。
UDP_HIT
Squid在cache里发现请求资源的貌似新鲜的拷贝。
UDP_MISS
Squid没有在cache里发现请求资源的貌似新鲜的拷贝。假如同一目标通过HTTP请求,就可能是个cache丢失。请对比UDP_MISS_NOFETCH。
UDP_MISS_NOFETCH
跟UDP_MISS类似,不同的是这里也指示了Squid不愿去处理相应的HTTP请求。假如使用了-Y命令行选项,Squid在启动并编译其内存索引时,会返回这个标签而不是UDP_MISS。
UDP_DENIED
因为icp_access规则,ICP查询被拒绝。假如超过95%的到某客户端的ICP响应是UDP_DENIED,并且客户端数据库激活了(见附录A),Squid在1小时内,停止发送任何ICP响应到该客户端。若这点发生,你也可在cache.log里见到一个警告。
转
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:941
Submitted by admin on 2011, July 20, 5:19 PM
1.修改squid的squid.conf文件
acl snmppublic snmp_community public #设置snmp监控的共同体为public
snmp_port 3401 #设置snmp监控端口
snmp_access allow snmppublic all #允许所有的计算机访问snmppublic
重启squid
2.生成MRTG配置文件
进入mrtg目录命令行下---->
cfgmaker public@localhost --global "WorkDir: /root/www/mrtg" --output mrtg.cfg
在/root/www/mrtg下生成监控的页面,可订制
3.将squid目录下的mib.txt文件改名为squid.mib,复制到mrtg/bin下
4.修改mrtg/bin下的mrtg.cfg配置文件
EnableIPv6: no
RunAsDaemon: yes #设置mrtg后台运行,默认5分钟刷新一次
Options[_]: growright, bits
Language: GB2312
LoadMIBs: squid.mib #装载复制过来的mib文件
WorkDir: C:\www\mrtg #设置页面存放的路径
PageFoot[^]: <i>Page managed by <a href="mailto:houw@yingnet.com">houw</a></i>
Target[cacheServerRequests]: cacheServerRequests&cacheServerRequests:public@localhost:3401
MaxBytes[cacheServerRequests]: 10000000
Title[cacheServerRequests]: Server Requests @ localhost
Options[cacheServerRequests]: growright, nopercent
PageTop[cacheServerRequests]: <h1>Server Requests @ localhost</h1>
YLegend[cacheServerRequests]: requests/sec
ShortLegend[cacheServerRequests]: req/s
LegendI[cacheServerRequests]: Requests
LegendO[cacheServerRequests]:
Legend1[cacheServerRequests]: Requests
Legend2[cacheServerRequests]:
Target[cacheServerErrors]: cacheServerErrors&cacheServerErrors:public@localhost:3401
MaxBytes[cacheServerErrors]: 10000000
Title[cacheServerErrors]: Server Errors @ localhost
Options[cacheServerErrors]: growright, nopercent
PageTop[cacheServerErrors]: <h1>Server Errors @ localhost</h1>
YLegend[cacheServerErrors]: errors/sec
ShortLegend[cacheServerErrors]: err/s
LegendI[cacheServerErrors]: Errors
LegendO[cacheServerErrors]:
Legend1[cacheServerErrors]: Errors
Legend2[cacheServerErrors]:
Target[cacheServerInOutKb]: cacheServerInKb&cacheServerOutKb:public@localhost:3401 * 1024
MaxBytes[cacheServerInOutKb]: 1000000000
Title[cacheServerInOutKb]: Server In/Out Traffic @ localhost
Options[cacheServerInOutKb]: growright, nopercent
PageTop[cacheServerInOutKb]: <h1>Server In/Out Traffic @ localhost</h1>
YLegend[cacheServerInOutKb]: Bytes/sec
ShortLegend[cacheServerInOutKb]: Bytes/s
LegendI[cacheServerInOutKb]: Server In
LegendO[cacheServerInOutKb]: Server Out
Legend1[cacheServerInOutKb]: Server In
Legend2[cacheServerInOutKb]: Server Out
Target[cacheHttpHits]: cacheHttpHits&cacheHttpHits:public@localhost:3401
MaxBytes[cacheHttpHits]: 10000000
Title[cacheHttpHits]: HTTP Hits @ localhost
Options[cacheHttpHits]: growright, nopercent
PageTop[cacheHttpHits]: <h1>HTTP Hits @ localhost</h1>
YLegend[cacheHttpHits]: hits/sec
ShortLegend[cacheHttpHits]: hits/s
LegendI[cacheHttpHits]: Hits
LegendO[cacheHttpHits]:
Legend1[cacheHttpHits]: Hits
Legend2[cacheHttpHits]:
Target[cacheHttpErrors]: cacheHttpErrors&cacheHttpErrors:public@localhost:3401
MaxBytes[cacheHttpErrors]: 10000000
Title[cacheHttpErrors]: HTTP Errors @ localhost
Options[cacheHttpErrors]: growright, nopercent
PageTop[cacheHttpErrors]: <h1>HTTP Errors @ localhost</h1>
YLegend[cacheHttpErrors]: errors/sec
ShortLegend[cacheHttpErrors]: err/s
LegendI[cacheHttpErrors]: Errors
LegendO[cacheHttpErrors]:
Legend1[cacheHttpErrors]: Errors
Legend2[cacheHttpErrors]:
Target[cacheIcpPktsSentRecv]: cacheIcpPktsSent&cacheIcpPktsRecv:public@localhost:3401
MaxBytes[cacheIcpPktsSentRecv]: 10000000
Title[cacheIcpPktsSentRecv]: ICP Packets Sent/Received
Options[cacheIcpPktsSentRecv]: growright, nopercent
PageTop[cacheIcpPktsSentRecv]: <h1>ICP Packets Sent/Recieved @ localhost</h1>
YLegend[cacheIcpPktsSentRecv]: packets/sec
ShortLegend[cacheIcpPktsSentRecv]: pkts/s
LegendI[cacheIcpPktsSentRecv]: Pkts Sent
LegendO[cacheIcpPktsSentRecv]: Pkts Received
Legend1[cacheIcpPktsSentRecv]: Pkts Sent
Legend2[cacheIcpPktsSentRecv]: Pkts Received
Target[cacheIcpKbSentRecv]: cacheIcpKbSent&cacheIcpKbRecv:public@localhost:3401 * 1024
MaxBytes[cacheIcpKbSentRecv]: 1000000000
Title[cacheIcpKbSentRecv]: ICP Bytes Sent/Received
Options[cacheIcpKbSentRecv]: growright, nopercent
PageTop[cacheIcpKbSentRecv]: <h1>ICP Bytes Sent/Received @ localhost</h1>
YLegend[cacheIcpKbSentRecv]: Bytes/sec
ShortLegend[cacheIcpKbSentRecv]: Bytes/s
LegendI[cacheIcpKbSentRecv]: Sent
LegendO[cacheIcpKbSentRecv]: Received
Legend1[cacheIcpKbSentRecv]: Sent
Legend2[cacheIcpKbSentRecv]: Received
Target[cacheHttpInOutKb]: cacheHttpInKb&cacheHttpOutKb:public@localhost:3401 * 1024
MaxBytes[cacheHttpInOutKb]: 1000000000
Title[cacheHttpInOutKb]: HTTP In/Out Traffic @ localhost
Options[cacheHttpInOutKb]: growright, nopercent
PageTop[cacheHttpInOutKb]: <h1>HTTP In/Out Traffic @ localhost</h1>
YLegend[cacheHttpInOutKb]: Bytes/second
ShortLegend[cacheHttpInOutKb]: Bytes/s
LegendI[cacheHttpInOutKb]: HTTP In
LegendO[cacheHttpInOutKb]: HTTP Out
Legend1[cacheHttpInOutKb]: HTTP In
Legend2[cacheHttpInOutKb]: HTTP Out
Target[cacheCurrentSwapSize]: cacheCurrentSwapSize&cacheCurrentSwapSize:public@localhost:3401
MaxBytes[cacheCurrentSwapSize]: 1000000000
Title[cacheCurrentSwapSize]: Current Swap Size @ localhost
Options[cacheCurrentSwapSize]: gauge, growright, nopercent
PageTop[cacheCurrentSwapSize]: <h1>Current Swap Size @ localhost</h1>
YLegend[cacheCurrentSwapSize]: swap size
ShortLegend[cacheCurrentSwapSize]: Bytes
LegendI[cacheCurrentSwapSize]: Swap Size
LegendO[cacheCurrentSwapSize]:
Legend1[cacheCurrentSwapSize]: Swap Size
Legend2[cacheCurrentSwapSize]:
Target[cacheNumObjCount]: cacheNumObjCount&cacheNumObjCount:public@localhost:3401
MaxBytes[cacheNumObjCount]: 10000000
Title[cacheNumObjCount]: Num Object Count @ localhost
Options[cacheNumObjCount]: gauge, growright, nopercent
PageTop[cacheNumObjCount]: <h1>Num Object Count @ localhost</h1>
YLegend[cacheNumObjCount]: # of objects
ShortLegend[cacheNumObjCount]: objects
LegendI[cacheNumObjCount]: Num Objects
LegendO[cacheNumObjCount]:
Legend1[cacheNumObjCount]: Num Objects
Legend2[cacheNumObjCount]:
Target[cacheCpuUsage]: cacheCpuUsage&cacheCpuUsage:public@localhost:3401
MaxBytes[cacheCpuUsage]: 100
AbsMax[cacheCpuUsage]: 100
Title[cacheCpuUsage]: CPU Usage @ localhost
Options[cacheCpuUsage]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheCpuUsage]: dwmy
PageTop[cacheCpuUsage]: <h1>CPU Usage @ localhost</h1>
YLegend[cacheCpuUsage]: usage %
ShortLegend[cacheCpuUsage]:%
LegendI[cacheCpuUsage]: CPU Usage
LegendO[cacheCpuUsage]:
Legend1[cacheCpuUsage]: CPU Usage
Legend2[cacheCpuUsage]:
Target[cacheMemUsage]: cacheMemUsage&cacheMemUsage:public@localhost:3401 * 1024
MaxBytes[cacheMemUsage]: 2000000000
Title[cacheMemUsage]: Memory Usage
Options[cacheMemUsage]: gauge, growright, nopercent
PageTop[cacheMemUsage]: <h1>Total memory accounted for @ localhost</h1>
YLegend[cacheMemUsage]: Bytes
ShortLegend[cacheMemUsage]: Bytes
LegendI[cacheMemUsage]: Mem Usage
LegendO[cacheMemUsage]:
Legend1[cacheMemUsage]: Mem Usage
Legend2[cacheMemUsage]:
Target[cacheSysPageFaults]: cacheSysPageFaults&cacheSysPageFaults:public@localhost:3401
MaxBytes[cacheSysPageFaults]: 10000000
Title[cacheSysPageFaults]: Sys Page Faults @ localhost
Options[cacheSysPageFaults]: growright, nopercent
PageTop[cacheSysPageFaults]: <h1>Sys Page Faults @ localhost</h1>
YLegend[cacheSysPageFaults]: page faults/sec
ShortLegend[cacheSysPageFaults]: PF/s
LegendI[cacheSysPageFaults]: Page Faults
LegendO[cacheSysPageFaults]:
Legend1[cacheSysPageFaults]: Page Faults
Legend2[cacheSysPageFaults]:
Target[cacheSysVMsize]: cacheSysVMsize&cacheSysVMsize:public@localhost:3401 * 1024
MaxBytes[cacheSysVMsize]: 1000000000
Title[cacheSysVMsize]: Storage Mem Size @ localhost
Options[cacheSysVMsize]: gauge, growright, nopercent
PageTop[cacheSysVMsize]: <h1>Storage Mem Size @ localhost</h1>
YLegend[cacheSysVMsize]: mem size
ShortLegend[cacheSysVMsize]: Bytes
LegendI[cacheSysVMsize]: Mem Size
LegendO[cacheSysVMsize]:
Legend1[cacheSysVMsize]: Mem Size
Legend2[cacheSysVMsize]:
Target[cacheSysStorage]: cacheSysStorage&cacheSysStorage:public@localhost:3401
MaxBytes[cacheSysStorage]: 1000000000
Title[cacheSysStorage]: Storage Swap Size @ localhost
Options[cacheSysStorage]: gauge, growright, nopercent
PageTop[cacheSysStorage]: <h1>Storage Swap Size @ localhost</h1>
YLegend[cacheSysStorage]: swap size (KB)
ShortLegend[cacheSysStorage]: KBytes
LegendI[cacheSysStorage]: Swap Size
LegendO[cacheSysStorage]:
Legend1[cacheSysStorage]: Swap Size
Legend2[cacheSysStorage]:
Target[cacheSysNumReads]: cacheSysNumReads&cacheSysNumReads:public@localhost:3401
MaxBytes[cacheSysNumReads]: 10000000
Title[cacheSysNumReads]: HTTP I/O number of reads @ localhost
Options[cacheSysNumReads]: growright, nopercent
PageTop[cacheSysNumReads]: <h1>HTTP I/O number of reads @ localhost</h1>
YLegend[cacheSysNumReads]: reads/sec
ShortLegend[cacheSysNumReads]: reads/s
LegendI[cacheSysNumReads]: I/O
LegendO[cacheSysNumReads]:
Legend1[cacheSysNumReads]: I/O
Legend2[cacheSysNumReads]:
Target[cacheCpuTime]: cacheCpuTime&cacheCpuTime:public@localhost:3401
MaxBytes[cacheCpuTime]: 1000000000
Title[cacheCpuTime]: Cpu Time
Options[cacheCpuTime]: gauge, growright, nopercent
PageTop[cacheCpuTime]: <h1>Amount of cpu seconds consumed @ localhost</h1>
YLegend[cacheCpuTime]: cpu seconds
ShortLegend[cacheCpuTime]: cpu seconds
LegendI[cacheCpuTime]: Mem Time
LegendO[cacheCpuTime]:
Legend1[cacheCpuTime]: Mem Time
Legend2[cacheCpuTime]:
Target[cacheMaxResSize]: cacheMaxResSize&cacheMaxResSize:public@localhost:3401 * 1024
MaxBytes[cacheMaxResSize]: 1000000000
Title[cacheMaxResSize]: Max Resident Size
Options[cacheMaxResSize]: gauge, growright, nopercent
PageTop[cacheMaxResSize]: <h1>Maximum Resident Size @ localhost</h1>
YLegend[cacheMaxResSize]: Bytes
ShortLegend[cacheMaxResSize]: Bytes
LegendI[cacheMaxResSize]: Size
LegendO[cacheMaxResSize]:
Legend1[cacheMaxResSize]: Size
Legend2[cacheMaxResSize]:
Target[cacheCurrentUnlinkRequests]: cacheCurrentUnlinkRequests&cacheCurrentUnlinkRequests:public@localhost:3401
MaxBytes[cacheCurrentUnlinkRequests]: 1000000000
Title[cacheCurrentUnlinkRequests]: Unlinkd Requests
Options[cacheCurrentUnlinkRequests]: growright, nopercent
PageTop[cacheCurrentUnlinkRequests]: <h1>Requests given to unlinkd @ localhost</h1>
YLegend[cacheCurrentUnlinkRequests]: requests/sec
ShortLegend[cacheCurrentUnlinkRequests]: reqs/s
LegendI[cacheCurrentUnlinkRequests]: Unlinkd requests
LegendO[cacheCurrentUnlinkRequests]:
Legend1[cacheCurrentUnlinkRequests]: Unlinkd requests
Legend2[cacheCurrentUnlinkRequests]:
Target[cacheClients]: cacheClients&cacheClients:public@localhost:3401
MaxBytes[cacheClients]: 1000000000
Title[cacheClients]: Number of Clients
Options[cacheClients]: growright, nopercent
PageTop[cacheClients]: <h1>Number of clients accessing cache @ localhost</h1>
YLegend[cacheClients]: clients/sec
ShortLegend[cacheClients]: clients/s
LegendI[cacheClients]: Num Clients
LegendO[cacheClients]:
Legend1[cacheClients]: Num Clients
Legend2[cacheClients]:
Target[cacheHttpAllSvcTime]: cacheHttpAllSvcTime.5&cacheHttpAllSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpAllSvcTime]: 1000000000
Title[cacheHttpAllSvcTime]: HTTP All Service Time
Options[cacheHttpAllSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpAllSvcTime]: <h1>HTTP all service time @ localhost</h1>
YLegend[cacheHttpAllSvcTime]: svc time (ms)
ShortLegend[cacheHttpAllSvcTime]: ms
LegendI[cacheHttpAllSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpAllSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpAllSvcTime]: Median Svc Time
Legend2[cacheHttpAllSvcTime]: Median Svc Time
Target[cacheHttpMissSvcTime]: cacheHttpMissSvcTime.5&cacheHttpMissSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpMissSvcTime]: 1000000000
Title[cacheHttpMissSvcTime]: HTTP Miss Service Time
Options[cacheHttpMissSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpMissSvcTime]: <h1>HTTP miss service time @ localhost</h1>
YLegend[cacheHttpMissSvcTime]: svc time (ms)
ShortLegend[cacheHttpMissSvcTime]: ms
LegendI[cacheHttpMissSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpMissSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpMissSvcTime]: Median Svc Time
Legend2[cacheHttpMissSvcTime]: Median Svc Time
Target[cacheHttpNmSvcTime]: cacheHttpNmSvcTime.5&cacheHttpNmSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpNmSvcTime]: 1000000000
Title[cacheHttpNmSvcTime]: HTTP Near Miss Service Time
Options[cacheHttpNmSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpNmSvcTime]: <h1>HTTP near miss service time @ localhost</h1>
YLegend[cacheHttpNmSvcTime]: svc time (ms)
ShortLegend[cacheHttpNmSvcTime]: ms
LegendI[cacheHttpNmSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpNmSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpNmSvcTime]: Median Svc Time
Legend2[cacheHttpNmSvcTime]: Median Svc Time
Target[cacheHttpHitSvcTime]: cacheHttpHitSvcTime.5&cacheHttpHitSvcTime.60:public@localhost:3401
MaxBytes[cacheHttpHitSvcTime]: 1000000000
Title[cacheHttpHitSvcTime]: HTTP Hit Service Time
Options[cacheHttpHitSvcTime]: gauge, growright, nopercent
PageTop[cacheHttpHitSvcTime]: <h1>HTTP hit service time @ localhost</h1>
YLegend[cacheHttpHitSvcTime]: svc time (ms)
ShortLegend[cacheHttpHitSvcTime]: ms
LegendI[cacheHttpHitSvcTime]: Median Svc Time (5min)
LegendO[cacheHttpHitSvcTime]: Median Svc Time (60min)
Legend1[cacheHttpHitSvcTime]: Median Svc Time
Legend2[cacheHttpHitSvcTime]: Median Svc Time
Target[cacheIcpQuerySvcTime]: cacheIcpQuerySvcTime.5&cacheIcpQuerySvcTime.60:public@localhost:3401
MaxBytes[cacheIcpQuerySvcTime]: 1000000000
Title[cacheIcpQuerySvcTime]: ICP Query Service Time
Options[cacheIcpQuerySvcTime]: gauge, growright, nopercent
PageTop[cacheIcpQuerySvcTime]: <h1>ICP query service time @ localhost</h1>
YLegend[cacheIcpQuerySvcTime]: svc time (ms)
ShortLegend[cacheIcpQuerySvcTime]: ms
LegendI[cacheIcpQuerySvcTime]: Median Svc Time (5min)
LegendO[cacheIcpQuerySvcTime]: Median Svc Time (60min)
Legend1[cacheIcpQuerySvcTime]: Median Svc Time
Legend2[cacheIcpQuerySvcTime]: Median Svc Time
Target[cacheIcpReplySvcTime]: cacheIcpReplySvcTime.5&cacheIcpReplySvcTime.60:public@localhost:3401
MaxBytes[cacheIcpReplySvcTime]: 1000000000
Title[cacheIcpReplySvcTime]: ICP Reply Service Time
Options[cacheIcpReplySvcTime]: gauge, growright, nopercent
PageTop[cacheIcpReplySvcTime]: <h1>ICP reply service time @ localhost</h1>
YLegend[cacheIcpReplySvcTime]: svc time (ms)
ShortLegend[cacheIcpReplySvcTime]: ms
LegendI[cacheIcpReplySvcTime]: Median Svc Time (5min)
LegendO[cacheIcpReplySvcTime]: Median Svc Time (60min)
Legend1[cacheIcpReplySvcTime]: Median Svc Time
Legend2[cacheIcpReplySvcTime]: Median Svc Time
Target[cacheDnsSvcTime]: cacheDnsSvcTime.5&cacheDnsSvcTime.60:public@localhost:3401
MaxBytes[cacheDnsSvcTime]: 1000000000
Title[cacheDnsSvcTime]: DNS Service Time
Options[cacheDnsSvcTime]: gauge, growright, nopercent
PageTop[cacheDnsSvcTime]: <h1>DNS service time @ localhost</h1>
YLegend[cacheDnsSvcTime]: svc time (ms)
ShortLegend[cacheDnsSvcTime]: ms
LegendI[cacheDnsSvcTime]: Median Svc Time (5min)
LegendO[cacheDnsSvcTime]: Median Svc Time (60min)
Legend1[cacheDnsSvcTime]: Median Svc Time
Legend2[cacheDnsSvcTime]: Median Svc Time
Target[cacheRequestHitRatio]: cacheRequestHitRatio.5&cacheRequestHitRatio.60:public@localhost:3401
MaxBytes[cacheRequestHitRatio]: 100
AbsMax[cacheRequestHitRatio]: 100
Title[cacheRequestHitRatio]: Request Hit Ratio @ localhost
Options[cacheRequestHitRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestHitRatio]: dwmy
PageTop[cacheRequestHitRatio]: <h1>Request Hit Ratio @ localhost</h1>
YLegend[cacheRequestHitRatio]: %
ShortLegend[cacheRequestHitRatio]: %
LegendI[cacheRequestHitRatio]: Median Hit Ratio (5min)
LegendO[cacheRequestHitRatio]: Median Hit Ratio (60min)
Legend1[cacheRequestHitRatio]: Median Hit Ratio
Legend2[cacheRequestHitRatio]: Median Hit Ratio
Target[cacheRequestByteRatio]: cacheRequestByteRatio.5&cacheRequestByteRatio.60:public@localhost:3401
MaxBytes[cacheRequestByteRatio]: 100
AbsMax[cacheRequestByteRatio]: 100
Title[cacheRequestByteRatio]: Byte Hit Ratio @ localhost
Options[cacheRequestByteRatio]: absolute, gauge, noinfo, growright, nopercent
Unscaled[cacheRequestByteRatio]: dwmy
PageTop[cacheRequestByteRatio]: <h1>Byte Hit Ratio @ localhost</h1>
YLegend[cacheRequestByteRatio]: %
ShortLegend[cacheRequestByteRatio]:%
LegendI[cacheRequestByteRatio]: Median Hit Ratio (5min)
LegendO[cacheRequestByteRatio]: Median Hit Ratio (60min)
Legend1[cacheRequestByteRatio]: Median Hit Ratio
Legend2[cacheRequestByteRatio]: Median Hit Ratio
Target[cacheBlockingGetHostByAddr]: cacheBlockingGetHostByAddr&cacheBlockingGetHostByAddr:public@localhost:3401
MaxBytes[cacheBlockingGetHostByAddr]: 1000000000
Title[cacheBlockingGetHostByAddr]: Blocking gethostbyaddr
Options[cacheBlockingGetHostByAddr]: growright, nopercent
PageTop[cacheBlockingGetHostByAddr]: <h1>Blocking gethostbyaddr count @ localhost</h1>
YLegend[cacheBlockingGetHostByAddr]: blocks/sec
ShortLegend[cacheBlockingGetHostByAddr]: blocks/s
LegendI[cacheBlockingGetHostByAddr]: Blocking
LegendO[cacheBlockingGetHostByAddr]:
Legend1[cacheBlockingGetHostByAddr]: Blocking
Legend2[cacheBlockingGetHostByAddr]:
5.执行mrtg监控
mrtg目录命令行下----> mrtg mrtg.cfg
6.indexmaker --output="C:\www\mrtg\index.html" --title=windowMRTG mrtg.cfg
生成索引页面,可以通过这一个页面访问其他监控页面
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:862
Submitted by admin on 2011, July 20, 2:25 PM
上回编译加载tcmalloc后,效果各有不同,所以还得细分具体运行情况,以便之后继续优化。
之前的架构是1个lvs下挂6台leaf+1台parent。现在已经给7台squid都加载tcmalloc了。leaf运行上佳,CPU占用率甚至降到了2%,loadavg也不过0.2。但parent的CPU占用率虽然降低,loadavg却依然在1以上——这对于单核服务器来说,可不是什么好事
分析日志,或者用squidclient分析cache情况,leaf如下:
$ cat access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.981347
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 97.8%, 60min: 98.3%
Byte Hit Ratios: 5min: 97.8%, 60min: 98.2%
Request Memory Hit Ratios: 5min: 85.8%, 60min: 86.8%
Request Disk Hit Ratios: 5min: 9.8%, 60min: 9.1%
Storage Swap size: 19891740 KB
Storage Mem size: 1048572 KB
Mean Object Size: 9.67 KB
可以看到缓存文件的平均大小不足10KB,绝大多数的请求都在内存中处理掉了。所以在加载了优化内存反应速度的tcmalloc后,效果那么明显。
parent如下:
$ cat access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.179209
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 31.1%, 60min: 32.3%
Byte Hit Ratios: 5min: 38.4%, 60min: 36.9%
Request Memory Hit Ratios: 5min: 7.8%, 60min: 12.2%
Request Disk Hit Ratios: 5min: 32.7%, 60min: 37.9%
Storage Swap size: 40300232 KB
Storage Mem size: 524284 KB
Mean Object Size: 11.68 KB
只有30%的缓存命中,而且基本还都是从磁盘读取的(awk结果排除了REFRESH_HIT,所以更低)。难怪上次优化没什么效用了……
为了保证服务,先给这组服务器加上了round-robin的双parent。新parent的硬件情况和老的一样。而squid配置上,则采用了aufs方式,不再使用diskd方式。运行到现在30个小时,分析如下:
$ cat /cache/logs/access.log |awk '{if(/NONE/){a[NONE]++}}END{print a[NONE]/NR}'
0.238754
$ squidclient -p 80 mgr:info
Cache information for squid:
Request Hit Ratios: 5min: 22.7%, 60min: 22.8%
Byte Hit Ratios: 5min: 22.9%, 60min: 20.1%
Request Memory Hit Ratios: 5min: 22.2%, 60min: 24.3%
Request Disk Hit Ratios: 5min: 64.4%, 60min: 65.0%
Storage Swap size: 4640308 KB
Storage Mem size: 1048588 KB
Mean Object Size: 9.08 KB
看起来差不多的样子。
因为确认mem没怎么用上,下一步看disk的I/O。
采用diskd的parent如下:
[root@tinysquid2 ~]# iostat -x /dev/xvdb2 5 5
Linux 2.6.18-128.el5xen (tinysquid2) 02/06/2010
avg-cpu: %user %nice %system %iowait %steal %idle
1.03 0.00 0.24 2.71 0.03 95.99
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.14 1.78 1.60 2.21 27.27 30.20 15.10 0.22 56.62 7.26 2.76
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 10.00 0.00 90.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 5.00 8.60 46.60 81.60 412.80 8.96 0.32 5.80 1.75 9.68
^[ORavg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 5.41 0.00 94.59
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 15.23 6.41 25.25 60.92 323.85 12.15 0.07 2.28 1.82 5.77
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 14.00 0.00 86.00
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 3.20 8.60 1.60 84.80 38.40 12.08 0.15 14.35 14.12 14.40
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 15.37 0.00 84.63
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 8.18 13.77 8.38 122.95 132.53 11.53 0.17 7.64 7.10 15.73
采用aufs的parent如下:
[root@tinysquid3 ~]# iostat -x /dev/xvdb2 5 5
Linux 2.6.18-128.el5xen (tinysquid3) 02/06/2010
avg-cpu: %user %nice %system %iowait %steal %idle
0.45 0.00 0.16 1.40 0.05 97.95
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.01 3.84 0.16 2.11 2.38 41.61 19.39 0.07 29.11 5.27 1.20
avg-cpu: %user %nice %system %iowait %steal %idle
0.20 0.00 0.40 1.60 0.20 97.60
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 8.58 3.19 6.19 25.55 118.16 15.32 0.02 2.47 1.70 1.60
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.60 0.00 99.40
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 14.20 2.00 6.20 16.00 163.20 21.85 0.01 1.27 0.68 0.56
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.60 0.00 99.40
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 15.23 1.40 5.61 12.83 166.73 25.60 0.01 1.37 1.03 0.72
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 2.79 0.00 97.21
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s avgrq-sz avgqu-sz await svctm %util
xvdb2 0.00 17.76 4.99 19.56 47.90 298.60 14.11 0.03 1.37 1.04 2.55
以上结果的解释如下:
- rrqm/s: 每秒进行 merge 的读操作数目。即 delta(rmerge)/s
- wrqm/s: 每秒进行 merge 的写操作数目。即 delta(wmerge)/s
- r/s: 每秒完成的读 I/O 设备次数。即 delta(rio)/s
- w/s: 每秒完成的写 I/O 设备次数。即 delta(wio)/s
- rsec/s: 每秒读扇区数。即 delta(rsect)/s
- wsec/s: 每秒写扇区数。即 delta(wsect)/s
- rkB/s: 每秒读K字节数。是 rsect/s 的一半,因为每扇区大小为512字节。(需要计算)
- wkB/s: 每秒写K字节数。是 wsect/s 的一半。(需要计算)
- avgrq-sz: 平均每次设备I/O操作的数据大小 (扇区)。delta(rsect+wsect)/delta(rio+wio)
- avgqu-sz: 平均I/O队列长度。即 delta(aveq)/s/1000 (因为aveq的单位为毫秒)。
- await: 平均每次设备I/O操作的等待时间 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)
- svctm: 平均每次设备I/O操作的服务时间 (毫秒)。即 delta(use)/delta(rio+wio)
- %util: 一秒中有百分之多少的时间用于 I/O 操作,或者说一秒中有多少时间 I/O 队列是非空的。即 delta(use)/s/1000 (因为use的单位为毫秒)
从上面的运行情况看,都是w操作为主,但diskd比aufs每秒w的次数要大,而每次w的服务时间也大——大的同时波动性也不太稳定——由此导致rw时的等待时间也延长——进一步的结果就是I/O非空时间变少——最后的结果就是disk的I/O压力变大!
因为现在已经双parent,loadavg降低,所以不好看出之前的高loadavg问题关键。不过至少从现在的运行来看,aufs比diskd要好。
squid/缓存 | 评论:0
| Trackbacks:0
| 阅读:787