监控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. [luoguP3325][HNOI2012]矿场搭建

    P3225 [HNOI2012]矿场搭建 题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤 ...

  2. Android学习笔记_35_PopupWindow泡泡窗口的实现及GridView应用

    1.PopupWindow是一个可以显示在当前Activity之上的浮动容器,PopupWindow弹出的位置是能够改变的,按照有无偏移量,可以分为无偏移和有便宜两种:按照参照对象的不同又可以分为两种 ...

  3. eclipse 安装/卸载插件

    1.通过Help>>Install New Soft 之后弹出对话框,可以通过“Add”按钮添加已经有的插件的(zip等)或者输入安装地址,之后按照要求即可.2.对于安装失败的插件,再次进 ...

  4. 2018年暑假ACM个人训练题7 题解报告

    A:HDU 1060 Leftmost Digit(求N^N的第一位数字 log10的巧妙使用) B:(还需要研究一下.....) C:HDU 1071 The area(求三个点确定的抛物线的面积, ...

  5. putty 启动 linux 下的oracle

    没搞过linux ,仅作记录: 1 打开putty.exe 程序 ,选择 连接 2 输入linux 的用户名和密码后,按下图操作: 3  启动监听 4 命令总结: 1.  sudo su - orac ...

  6. o'Reill的SVG精髓(第二版)学习笔记——第二章

    在网页中使用SVG 将SVG作为图像: SVG是一种图像格式,因此可以使用与其他图像类型相同的方式包含在HTML页面中,具体可以采用两种方法:将图像包含在HTML标记的<img>元素内(当 ...

  7. CentOS 7安装Oracle (CentOS Linux release 7.5.1804)

    从安装操作系统到完成oracle安装 1.安装centos7 下载CentOS7 iso安装包,配置虚拟机,由于只进行oracle安装练习,随便配置20G空间.选择安装文件. 开机,开始安装系统: 直 ...

  8. vue.esm.js:578 [Vue warn]: Missing required prop

    问题: 解决: required: true,属性是,这个必须填写

  9. 【赛时总结】NOIP2018-三校联考1024

    ◇NOIP三校联考-1024◇ 发现以前的博客写得似乎都很水……基本上都没什么阅读量QwQ 决定改过自新╰( ̄ω ̄o) 就从这篇博客开始吧~ 现场考得无地自容,看到题解才发现一些东西……(我第三题还没 ...

  10. ABAP术语-Interface

    Interface 原文:http://www.cnblogs.com/qiangsheng/archive/2008/02/22/1077086.html Information tool that ...