当前位置:网站首页>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
边栏推荐
猜你喜欢

Sentinel's quick start takes you through flow control in three minutes

. NETCORE unified authentication authorization learning - first authorization (2)

CORDIC based Signal Processor desgn

不同系统下的文件层级符号小结

. NETCORE unified authentication authorization learning - run (1)

PostgreSQL weekly news - June 22

ads131a04 ADC verilog实现及仿真

路由汇总带来的三层环路-解决实验

阿里云发布《中国机器人产业图谱(2022)》,122页pdf

「运维有小邓」Active Directory批量用户创建
随机推荐
导航 习题【微机原理】【习题】
Bigder: Automation Test Engineer
Cantata version 9.5 has officially passed the sgs-t Ü V certification and conforms to all major software safety standards
导航 实验【微机原理】【实验】
Explain PBR texture maps
Analysis on the true topic of "cost management" by Guangdong second-class cost engineer
「运维有小邓」日志分析工具使用越来越频繁的原因
Sentinel's quick start takes you through flow control in three minutes
leetcode:307. 区域和检索 - 数组可修改
Shutter bottomnavigationbar with page switching example
WIN10设置自动拨号联网任务,实现开机、断网自动重连
知识蒸馏(Knowledge Distilling)学习笔记
智能门锁主流品牌有哪些?选购门锁时要注重产品的哪些特性?
. NETCORE unified authentication authorization learning - first authorization (2)
Advances in computational imaging
Analysis of the underlying architecture of spark storage system - spark business environment practice
LeetCode 1. 两数之和
Cmake development - Multi Directory Project
PostgreSQL每周新闻—6月22日
Common methods of string class