最近一直都在忙工作上的事情,沒(méi)有時(shí)間來(lái)寫(xiě)點(diǎn)東西了,公司用的cache是squid,之前有過(guò)監(jiān)控,但是nagios中看不到squid的命中率,于是就寫(xiě)了這么一個(gè)腳本來(lái)通過(guò)pnp4nagios查看squid的一些圖。下面是腳本:
目前成都創(chuàng)新互聯(lián)已為成百上千的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、成都網(wǎng)站托管、企業(yè)網(wǎng)站設(shè)計(jì)、蓮花網(wǎng)站維護(hù)等服務(wù),公司將堅(jiān)持客戶(hù)導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶(hù)和合作伙伴齊心協(xié)力一起成長(zhǎng),共同發(fā)展。
- #!/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!"
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線(xiàn),公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性?xún)r(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專(zhuān)為企業(yè)上云打造定制,能夠滿(mǎn)足用戶(hù)豐富、多元化的應(yīng)用場(chǎng)景需求。