监控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. Angularjs实例4

    <!DOCTYPE html><html lang="zh-cn" ng-app=""><head><meta htt ...

  2. 课时90.div和span(掌握)

    为什么在这里讲解div和span呢,而不在html中讲解呢? 因为在我们的开发中div和span一般是配合css来使用的,来完成一定的效果,来设置一些属性,在前面我们没有学习css,所以体会不到它的效 ...

  3. GoBelieve JS IM SDK接入备忘

    类IMService 构造函数 参数说明: * `observer` 回调对象(可选) 设置当前用户的access token 属性名:String accessToken 功能:在调用start之前 ...

  4. SpringBoot非官方教程 | 第二十四篇: springboot整合docker

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot24-docker/ 本文出自方志朋的博客 这篇文 ...

  5. SpringBoot非官方教程 | 第十六篇:用restTemplate消费服务

    转载请标明出处: 原文首发于:https://www.fangzhipeng.com/springboot/2017/07/11/springboot11-restTemplate/ 本文出自方志朋的 ...

  6. django-基于中间件实现限制ip频繁访问

    ########django-基于中间件写一个限制频繁登陆######## 额额,标题已经很醒目了,通过中间件去实现,其他方法也可以实现 浏览器前端传来的请求,必须通过中间件,才能到后面路由,视图函数 ...

  7. Angularjs基础(六)

    AngularJS HTML DOM AngularJS为HTML DOM 元素的属性提供了绑定应用数据的指令. ng-disabled指令 ng-disabled指令直接绑定应用数据到HTML的di ...

  8. LeetCode 中级 - 第k个排列(60)

    可以用数学的方法来解, 因为数字都是从1开始的连续自然数, 排列出现的次序可以推 算出来, 对于n=4, k=15 找到k=15排列的过程: 1 + 对2,3,4的全排列 (3!个) 2 + 对1,3 ...

  9. Git push提示pre-receive hook declined

    master:local auto@ubuntu:~/src/code/ git push Counting objects: 5, done. Delta compression using up ...

  10. 5820. 【NOIP提高A组模拟2018.8.16】 非法输入(模拟,字符串)

    5820. [NOIP提高A组模拟2018.8.16] 非法输入 (File IO): input:aplusb.in output:aplusb.out Time Limits: 1000 ms   ...