监控memcache服务是否正常,模拟用户(web客户端)检测。 
使用nc命令加上set/get来模拟检测,以及监控响应时间及命中率。

#!/bin/bash

########################
#date:2018-04-20 #
#author:7777 #
#QQ:577545535          #
#E-mail:18401747334@163.com#
########################
#echo -ne "\033[0;33m"
echo -ne "\E[1;32m"
cat<<EOT
_oo0oo_
088888880
88" . "88
(| -_- |)
0\ = /0
___/'---'\___
.' \\\\| |// '.
/ \\\\||| : |||// \\
/_ ||||| -:- |||||- \\
| | \\\\\\ - /// | |
| \_| ''\---/'' |_/ |
\ .-\__ '-' __/-. /
___'. .' /--.--\ '. .'___
."" '< '.___\_<|>_/___.' >' "".
| | : '- \'.;'\ _ /';.'/ - ' : | |
\ \ '_. \_ __\ /__ _/ .-' / /
====='-.____'.___ \_____/___.-'____.-'=====
'=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 iii 服务正常
EOT
echo -ne "\E[0m"
[ -f /etc/init.d/functions ] && . /etc/init.d/functions
###variables
RETVAL=0
###color
RED_COLOR='\E[1;31m'
GREEN_COLOR='\E[1;32m'
YELLOW_COLOR='\E[1;33m'
BLUE_COLOR='\E[1;34m'
RES='\E[0m'
####menu list
menu() {
cat <<EOF
############################
1 memcached status
2 memcached stop
3 memcached get_hits
4 quit
EOF
}
status() {
Set=$(printf "set key1 0 0 6\r\noldboy\r\n"|nc 127.0.0.1 11211|grep STORED|wc -l )
Get=$(printf "get key1\r\n"|nc 127.0.0.1 11211|grep oldboy|wc -l)
Port=$(netstat -lntup|grep memcached|wc -l)
if [ $Port -ge 4 ];then
Num=$(expr $Set + $Get)
if [ $Num -eq 2 ];then
action "Memcached server is running" /bin/true
else
action "Memcached server is not normal" /bin/false
fi
else
action "Memcached server is not running" /bin/false
read -t 10 -p "Memcached server whether open:[y/n]:" b
if [ "$b" == "y" -o "$b" == "Y" ];then
/usr/bin/memcached -m 16m -p 11211 -d -u root -c 8192
action "Memcached server is starting" /bin/true
elif [ "$b" == "n" -o "$b" == "N" ];then
echo -e "$YELLOW_COLOR Goodbye.............$RES"
fi
fi
return $RETVAL
}
stop() {
Port=$(netstat -lntup|grep memcached|wc -l)
if [ $Port -ge 4 ];then
pkill memcached &>/dev/null
RETVAL=$?
if [ $RETVAL -eq 0 ];then
action "Memcached server is stopping" /bin/true
else
action "Memcached server is stopping" /bin/false
fi
else
action "Memcached server not running" /bin/false
fi
}
get_hits() {
Cmd_get=$(printf "stats\r\n"|nc 127.0.0.1 11211|grep "cmd_get"|awk '{print $3}')
Get_hits=$(printf "stats\r\n"|nc 127.0.0.1 11211|grep "get_hits"|awk '{print $3} ')
Get_misses=$(printf "stats\r\n"|nc 127.0.0.1 11211|grep "get_misses"|awk '{print $3}')
Port=$(netstat -lntup|grep memcached|wc -l)
if [ $Port -ge 4 ];then
echo "A total of cmd_get is $Cmd_get"
sleep 1
echo "A total of get_hits is $Get_hits"
sleep 1
echo "A total of get_misses is $Get_misses"
else
action "Memcached is not running" /bin/false
fi
return $RETVAL
}
main() {
while true
do
menu
read -t 10 -p "Please input number:" a
expr $a + 1 &>/dev/null
if [ $? -ne 0 ];then
echo -e "$BLUE_COLOR Please input error,not int $RES"
exit 1
fi
case "$a" in
1)
status
RETVAL=$?
;;
2)
stop
RETVAL=$?
;;
3)
get_hits
RETVAL=$?
;;
4)
clear
echo "##############################################"
echo -e "$GREEN_COLOR `figlet GoodBye` $RES"
echo "##############################################"
exit 0
;;
*)
echo -e "$RED_COLOR input error $RES"
esac
done
}
main
exit $RETVAL

监控memcache服务的更多相关文章

  1. [Cacti] memcache安装执行、cacti监控memcache实战

    简单介绍 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的.眼下全世界不少人使用这个缓存项目来构建自己大负载的站点,来分担数据库的压力. Memcache官方站 ...

  2. Zabbix 3.4.11监控 apache服务,ftp服务的配置

    一 zabbix 的安装部署 略 二监控 apache服务的配置 首先在本机下载模板:https://github.com/rdvn/zabbix-templates/archive/m aster. ...

  3. Python 监控nginx服务是否正常

    Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...

  4. shell脚本监控MySQL服务是否正常

    监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等: 方法1 ...

  5. linux shell脚本守护进程监控svn服务

    最近搭建的svn服务不知道什么原因服务总是被关闭(如果你不知道怎么搭建svn可以参考linux下搭建svn版本控制软件),因此用shell脚本实现一个守护进程.用于监控svn服务是否启动,如果服务不在 ...

  6. 使用脚本监控windows服务的方法

    以下脚本可监控某一个windows服务,发现其停止就立即重启之. @echo off rem 定义循环间隔时间和监测的服务: set secs=60 set srvname="NetWin ...

  7. linux上部署rmi+memcache服务

    本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50020437 最近在学习linux上搭建Rmi+Memca ...

  8. 21.Pod的limit和request和资源监控收集服务Heapster

    容器的资源需求,资源限制 requests:需求,最低保障: limits:限制,硬限制: CPU: 1颗逻辑CPU =,millicores 500m=.5CPU 内存: E.P.T.G.M.K E ...

  9. centos 安装memcache服务后memcahce本机连接Permission

    自己手动在虚拟机下装了下memcache,整个过程真是充满波折,本身用php5.3安装memcache扩展就麻烦很多,无法通过yum直接安装,安装方法详见http://chenwei.me/blog/ ...

随机推荐

  1. 【洛谷P1966】火柴排队

    火柴排队 题目链接 ∑(ai​−bi​)^2=∑ai^2-2*∑ai*bi+∑bi^2 显然∑ai^2+∑bi^2是不变的,我们要让 2*∑ai*bi最大,才能使原式最小 然后我们一眼就可以看出来, ...

  2. 【luogu P3410 拍照】 题解

    题目链接:https://www.luogu.org/problemnew/show/P3410 这个题就是求一个最大权闭合图 在一个图中,一些点构成一个集合,且集合中的出边指向的终点也在这个集合中, ...

  3. ASP.NET MVC中使用表单上传文件时的注意事项

    最近了好久没写ASP.NET 使用HTML的FORM来上传文件了,结果写了个文件上传发现ASP.NET MVC的Controller中老是读取不到上传的文件. MVC的View(Index.cshtm ...

  4. React 相关开发工具

    Gulp:是一个NodeJs项目构建工具,高效易学:把一个开发中的项目构建成一个可以部署在服务器上的项目,压缩 整合 gulp.task('1',['2','3'],function(){});// ...

  5. SQL Server中的三种Join方式

      1.测试数据准备 参考:Sql Server中的表访问方式Table Scan, Index Scan, Index Seek 这篇博客中的实验数据准备.这两篇博客使用了相同的实验数据. 2.SQ ...

  6. flex 遇到white-space:nowrap

    背景,做一个前面图片宽度固定,后面宽度自适应,使用到了flex布局,但是想让后面div里文字不换行,超出以点点表示时,这时布局就乱了,查了下,原来flex布局与white-space:nowrap有影 ...

  7. js省市区级联选择联动

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta http-equiv="Con ...

  8. #leetcode刷题之路29- 两数相除

    给定两个整数,被除数 dividend 和除数 divisor.将两数相除,要求不使用乘法.除法和 mod 运算符.返回被除数 dividend 除以除数 divisor 得到的商. 示例 1:输入: ...

  9. 【ospf-路由过滤】

  10. phpstorm代码提示不小心关了,如何开启

    在phpstrom右下角单击如图 ​ 出现event log窗口 ​ 如果不是​ 单击切换取消节电模式即可开启代码提示.