监控memcache服务
监控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服务的更多相关文章
- [Cacti] memcache安装执行、cacti监控memcache实战
简单介绍 Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的.眼下全世界不少人使用这个缓存项目来构建自己大负载的站点,来分担数据库的压力. Memcache官方站 ...
- Zabbix 3.4.11监控 apache服务,ftp服务的配置
一 zabbix 的安装部署 略 二监控 apache服务的配置 首先在本机下载模板:https://github.com/rdvn/zabbix-templates/archive/m aster. ...
- Python 监控nginx服务是否正常
Python 监控nginx服务是否正常 #!/usr/bin/env python import os, sys, time from time import strftime while True ...
- shell脚本监控MySQL服务是否正常
监控MySQL服务是否正常,通常的思路为:检查3306端口是否启动,ps查看mysqld进程是否启动,命令行登录mysql执行语句返回结果,php或jsp程序检测(需要开发人员开发程序)等等: 方法1 ...
- linux shell脚本守护进程监控svn服务
最近搭建的svn服务不知道什么原因服务总是被关闭(如果你不知道怎么搭建svn可以参考linux下搭建svn版本控制软件),因此用shell脚本实现一个守护进程.用于监控svn服务是否启动,如果服务不在 ...
- 使用脚本监控windows服务的方法
以下脚本可监控某一个windows服务,发现其停止就立即重启之. @echo off rem 定义循环间隔时间和监测的服务: set secs=60 set srvname="NetWin ...
- linux上部署rmi+memcache服务
本文是在学习中的总结,欢迎转载但请注明出处:http://blog.csdn.net/pistolove/article/details/50020437 最近在学习linux上搭建Rmi+Memca ...
- 21.Pod的limit和request和资源监控收集服务Heapster
容器的资源需求,资源限制 requests:需求,最低保障: limits:限制,硬限制: CPU: 1颗逻辑CPU =,millicores 500m=.5CPU 内存: E.P.T.G.M.K E ...
- centos 安装memcache服务后memcahce本机连接Permission
自己手动在虚拟机下装了下memcache,整个过程真是充满波折,本身用php5.3安装memcache扩展就麻烦很多,无法通过yum直接安装,安装方法详见http://chenwei.me/blog/ ...
随机推荐
- Python条件判断
计算机之所以能做很多自动化的任务,因为它可以自己做条件判断. 比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现: age = 20 if age >= 18: p ...
- ListItem Updating事件监视有没有上传附件
using System; using System.Collections.Generic; using System.Text; using Microsoft.SharePoint; using ...
- Redis集群的安装和使用
- linux 怎么查看系统的环境变量 与设置jdk 系统环境变量
1.win 7 ,win10 怎么查看,添加系统环境的变量,大家都非常清楚的.但是linux 的 却不一定哦. 打开终端输入 : “echo $PATH “ or “export ” 如 ...
- java之递归学习
递归思想(2018-10-22): 递归就是方法里调用自身 在使用递归策略时,必须有一个明确的递归结束条件,称为递归出口 递归算法代码显得很简洁,但递归算法解题的运行效率较低.所以不提倡用递归设计程序 ...
- idea常用技巧
1.如何设置,使IntelliJ IDEA智能提示忽略大小写 打开设置(CTRL+ALT+S)搜索editor,找到“Code Completion”->点击Case sensitive com ...
- Django模板简介
在settings.py中有个TEMPLATES的设置,其中BACKEND用来配置Django模板引擎, DIRS 定义了一个目录列表,模板引擎按列表顺序搜索这些目录以查找模板源文件 一般我们都会把模 ...
- 日常工作linux常用命令
1:cp 复制文件/文件夹 cp -r 源目录 目标目录 2:mv 文件重命名 mv 源文件/源目录 目标文件/目标目录 3:du -sh 查看当前目录大小 du -l 查看当前目录下文件大小 d ...
- python字符串的格式化输出
很多时候我们在打印输入内容时希望有简单格式而不是拼接 一般做法: name = input("name:").strip() age = input("age:" ...
- 使用docker安装和运行常用的数据库和中间件
mysql: docker pull mysql: docker run --name mysql -p : -v /usr/share/zoneinfo/Asia/Shanghai:/etc/loc ...