当前位置:网站首页>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带有页面切换示例
- Golang basic learning
- Mapbox GL development tutorial (12): loading surface layer data
- 不同系统下的文件层级符号小结
- [today in history] June 29: SGI and MIPS merged; Microsoft acquires PowerPoint developer; News corporation sells MySpace
- 如何审核 Active Directory 用户账户更改?
- VHDL电话计费系统设计
- leetcode:238. 除自身以外数组的乘积
- MySQL JSON data types & functions
- Is it safe to open an account with flush for stock trading?
猜你喜欢

「运维有小邓」Active Directory批量用户创建

VHDL电话计费系统设计

Practical guide to GStreamer application development (V)

时钟树综合(CTS)

Exit operation in project

高校如何基于云原生构建面向未来的智慧校园?全栈云原生VS传统技术架构

Win10 sets automatic dial-up networking task to realize automatic reconnection after startup and disconnection

Reinforcement learning weekly (issue 51): integration of PAC, ilql, RRL & model free reinforcement learning into micro grid control: overview and Enlightenment

LSF-bsub命令

期末复习【微机原理】
随机推荐
Set up your own website (12)
The reason why the log analysis tool of "operation and maintenance" is used more and more frequently
Mysql Json 数据类型&函数
String类的常用方法
verilog实现串口通信发送到数码管
时钟树综合(CTS)
WPF 测量字符串显示大小
CAD assistant - 3D model format conversion tool
输入年份与月份,求该月共有多少天
炒股开户请问哪个券商佣金是最低最安全的
实现inotify配合rsync实时备份
A keepalived high availability accident made me learn it again!
Leading by 11%, Huawei cloud sky chip AI solver once again topped the international authoritative list
The foundation and application of quantum machine learning: a concise literature review
直播预告 | PostgreSQL 内核解读系列第一讲:PostgreSQL 系统概述
Gstreamer应用开发实战指南(五)
Golang basic learning
leetcode:307. 区域和检索 - 数组可修改
「运维有小邓」实时监控用户登录操作
Is it safe to open an account with flush for stock trading?