当前位置:网站首页>Shell implementation of Memcache cache cache hit rate monitoring script
Shell implementation of Memcache cache cache hit rate monitoring script
2022-06-29 20:57:00 【Brother Xing plays with the clouds】
The company has several The server Open multiple memcached process , In addition to monitoring whether they are normal telnet through , In addition to the existence of instances, their cache hit rate should be monitored . Alarm for their cache hit rate .
There is one on the Internet. perl Written , Build install required . There is one python Written , Paste it and run it , Find out python Wrong library version . Such a simple script takes so much effort , I just wrote it manually .
The more I write, the more I feel shell Processing data , function , String arrays are too weak .
not so bad , Let's use it together . This script is relatively simple , adopt check_tcp Script get memcached Of stats Information . Then format the information into a string , And then get_hits Above cmd_gets You can get the cache hit rate . The basic principle is relatively simple . But it has to be realized nagios Alarm format for , And output of performance data , Support pnp mapping .
For the convenience of the party , Insert the previous function directly into the script on demand , It should be a copy and paste operation .
If there is bug Please feedback !
#!/bin/bash ############################### # Check memcached shooting # load nagios Bring their own utils.sh ############################### source /usr/local/nagios/libexec/utils.sh print_usage() { echo "check_memcached -H IP -P port -w warning -c critical" } ################### # Get command line execution parameters ################### while test -n "$1";do case "$1" in -H) host=$2 shift ;; -P) port=$2 shift ;; -w) warning=$2 shift ;; -c) critical=$2 shift ;; *) echo "Unknown argument:$1" print_usage exit $STATE_UNKNOWN ;; esac shift done ######################## #function div_f() # Inspection parameters , Returns the ratio of two numbers ######################## function div_f() { ref=`awk -v num_a=$1 -v num_b=$2 'BEGIN{printf "%0.2f \n",num_a/num_b}'`; echo $ref; } ################## # Get the hit rate function ################## function getMemcachedHits() { memcachedinfo=`/usr/local/nagios/libexec/check_tcp -H $host -p $port -E -s 'stats\r\nquit\r\n' -e 'uptime' | tr "\r" "@"` get_hits=`echo $memcachedinfo | grep -o "@ STAT get_hits [0-9]*"| awk '{print $4}'` cmd_get=`echo $memcachedinfo | grep -o "@ STAT cmd_get [0-9]*"| awk '{print $4}'` div_f $get_hits $cmd_get; } hits=`getMemcachedHits $host $port`; ################## # Get the hit rate range ################## function re_rang() { rang=$hits; interval_a=$critical; interval_b=$warningl if [[ $rang < $interval_a ]];then echo "0"; elif [[ $rang < $interval_b ]];then echo "1"; elif [[ $rang > $interval_b ]]||[[ $rang == $interval_b ]] ;then echo "2"; else return; fi } res=`re_rang $critical $warning $hits`; case "$res" in 0) echo "Critical memcached_hits=$hits|memcached_hits=$hits;$warning;$critical;" exit $STATE_CRITICAL ;; 1) echo "Warning memcached_hits=$hits|memcached_hits=$hits;$warning;$critical;" exit $STATE_WARNING ;; 2) echo "Ok memcached_hits=$hits|memcached_hits=$hits;$warning;$critical;" exit $STATE_OK ;; *) echo "Unkown" exit $STATE_UNKNOWN ;; esac
边栏推荐
猜你喜欢

Digital password lock Verilog design + simulation + on board verification

A new Polaris has risen!

Chainsafe cross chain bridge deployment tutorial
![Navigation [microcomputer principle]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation [microcomputer principle]

18. `bs object Node name next_ sibling` previous_ Sibling get sibling node

"Xiaodeng" ad domain delegation for operation and maintenance

Verilog realizes serial communication and sends it to the nixie tube

Alibaba cloud released the atlas of China's robot industry (2022), 122 Pages pdf

High energy live broadcast, a gathering of celebrities! We invite you to explore bizdevops.
![[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace](/img/86/abeb82927803712a98d2018421c3a7.png)
[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
随机推荐
leetcode:370. 区间加法
C#_ Convert camera images to bitmap format and draw Crosshairs
String字符串的存储原理
【摸鱼神器】UI库秒变低代码工具——表单篇(一)设计
Mapbox GL development tutorial (12): loading surface layer data
HAproxy + Keepalive实现LDAP代理服务
如何评价科大讯飞AI翻译笔P20系列,值得买吗?
"Xiaodeng" active directory batch user creation in operation and maintenance
CAD assistant - 3D model format conversion tool
STL教程6-deque、stack、queue、list容器
[today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
verilog实现DDS波形发生器模块,可实现频率、相位可调,三种波形
A keepalived high availability accident made me learn it again!
STL tutorial 6-deque, stack, queue, list container
Common methods of string class
如何从外表判断导电滑环的质量
我的创作纪念日
WPF 测量字符串显示大小
期末复习【微机原理】
Jupyter service installation and startup