十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
最近一直都在忙工作上的事情,没有时间来写点东西了,公司用的cache是squid,之前有过监控,但是nagios中看不到squid的命中率,于是就写了这么一个脚本来通过pnp4nagios查看squid的一些图。下面是脚本:
目前成都创新互联已为成百上千的企业提供了网站建设、域名、虚拟空间、成都网站托管、企业网站设计、莲花网站维护等服务,公司将坚持客户导向、应用为本的策略,正道将秉承"和谐、参与、激情"的文化,与客户和合作伙伴齐心协力一起成长,共同发展。
- #!/bin/bash
- "Version 1.1"
- "zhhmj (tgariltg@gmail.com)"
- "localhost"
- "$PROGNAME $VERSION $AUTHOR"
- ""
- ""
- "Description:"
- "Gets percentage of hits for a squid reverse proxy"
- "Options:"
- " -h|--help"
- " Print help info."
- " -H|--hostname)"
- " Sets the hostname, default is localhost"
- " -P|--port)"
- " Sets the port, default is 8001"
- " -wd)"
- " Sets the number of available file descriptors to warn at, default 100"
- " -cd)"
- " Sets the number of available file descriptors to go critical at, default 30"
- " -wh)"
- " Sets the percentage of hits to warn at, default 70"
- " -ch)"
- " Sets the percentage of hits to go critical at, default 50"
- ""
- "Example:"
- " ./check_squid -H 127.0.0.1 -P 8001 -wd 100 -cd 30 -wh 70 -ch 50"
- " WARNING - Squid is serving an average of 7.2 per minute since start with 655349 file descriptors left and 0.04 percent of CPU use and Hits as 64% of all requests"
- case"$status_text"in
- "Error gettings metrics.(Access control on squid?)"
- "Error connecting to host"
- minute
- asofallby
- asofby
- asofby
- "${status_text}""Available number of file descriptors"'s/^[ \t]*//'
- "${status_text}""CPU Usage:"'s/^[ \t]*//'
- "${status_text}""Average HTTP requests per minute since start"'s/^[ \t]*//'
- "${status_text}""Hits as % of all requests"'{print $8}''{print $1}'
- "${status_text}""Memory hits as % of hit requests"'{print $9}''{print $1}'
- "${status_text}""Disk hits as % of hit requests"'{print $9}''{print $1}'
- "'avail_descriptors'=$available_descriptors 'cpu_usage'=$cpu_usage 'avg_http_requests'=$avg_http_requests 'all_requests_hits'=$all_requests_hits% 'memory_hits'=$memory_hits% 'disk_hits'=$disk_hits%"
- out"Squid is serving an average of $avg_http_requests per minute since start with $available_descriptors file descriptors left and $cpu_usage percent of CPU use and Hits as $all_requests_hits% of all requests"
- then
- "CRITICAL - ${out} | ${perfdata}"
- then
- "WARNING - ${out} | ${perfdata}"
- else
- "OK - ${out} | ${perfdata}"
- "$1"
- case"$1"in
- --help|-h)
- --version|-v)
- --hostname|-H)
- --port|-P)
- "Unknown argument: $1"
- then
- "Warn descriptors must not be lower than critical and crit hits must not be lower than warn hits!"
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。