当前位置:网站首页>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
边栏推荐
- flutter BottomNavigationBar切换页面保持状态
- PostgreSQL每周新闻—6月22日
- Analysis on the true topic of "cost management" by Guangdong second-class cost engineer
- How to judge the quality of conductive slip ring from its appearance
- 一次 Keepalived 高可用的事故,让我重学了一遍它!
- 跳转打开新窗口
- 「运维有小邓」日志分析工具使用越来越频繁的原因
- Navigation [microcomputer principle]
- annotation
- VHDL电话计费系统设计
猜你喜欢

「运维有小邓」审核并分析文件和文件夹访问权限

分析影响导电滑环传输信号的因素
![Navigation experiment [microcomputer principle] [experiment]](/img/79/8311a409113331e72f650a83351b46.png)
Navigation experiment [microcomputer principle] [experiment]

Liunx instruction

leetcode:724. 寻找数组的中心下标

导航 实验【微机原理】【实验】

Clock tree synthesis (CTS)

解释PBR纹理贴图(texture-maps)

VHDL电话计费系统设计

"Xiaodeng" active directory password expiration notification function is available for operation and maintenance
随机推荐
VoIP Push 在海外音视频业务中的应用
高校如何基于云原生构建面向未来的智慧校园?全栈云原生VS传统技术架构
Three. JS development: drawing of thick lines
How to evaluate iFLYTEK AI translation pen P20 series? Is it worth buying?
「运维有小邓」实时监控用户登录操作
WPF measurement string display size
GoAhead 翻译—Active Server Pages
String类的常用方法
跳转打开新窗口
Exit operation in project
MySQL JSON data types & functions
Logical structure and physical structure
Verilog implements DDS waveform generator module, which can realize adjustable frequency and phase, three waveforms
透过华为军团看科技之变(五):智慧园区
"Xiaodeng" ad domain delegation for operation and maintenance
String字符串的存储原理
Selection of materials for space conductive disc slip ring
At least 3 years for learning amplifier?
Cmake development - Multi Directory Project
Golang basic learning