一直觉得缓存这东西,一般公司用用就行了,没什么必要做监控吧。可是当有一天缓存越来越重要,缓存挂了,全线崩溃时,监控就是必须的了。 一:安装使用 1 安装,其实安装就是令人发指的简单 pip install tornadopip install redispip install python-dateuti
一直觉得缓存这东西,一般公司用用就行了,没什么必要做监控吧。可是当有一天缓存越来越重要,缓存挂了,全线崩溃时,监控就是必须的了。
一:安装使用
1 安装,其实安装就是令人发指的简单
pip install tornado pip install redis pip install python-dateutil git clone https://github.com/kumarnitin/redislive.git
2 配置使用
a 修改redis-live.conf如下:
cd redislive/src/
vim redis-live.conf
{
"redisservers":
[
{
"server": "127.0.0.1",
"port" : 6379
}
],
"datastoretype" : "redis",
"redisstatsserver":
{
"server" : "127.0.0.1",
"port" : 6379
}
}
b 开始监控持续120s
./redis-monitor.py --duration=120
把监控加入crontab
*/30 * * * * cd /root/src/redislive/src && /usr/local/python2.7/bin/python2.7 redis-monitor.py --duration=120 > /dev/null 2>&1 &
c 开启web服务器
./redis-live.py
d 请访问 http://yourip:8888/index.html
二:遇到的坑
1 使用sqlite时老是报错
importerror: no module named _sqlite3
查资料这个应该是python 2.7.3的一个bug
先安装sqlite-devel,然后重新编译python的方法不可行,最后是下面的方法解决
在网上查了一下解决办法:编辑源码下的connection.c这个文件 vi python-2.7.3/modules/_sqlite/connection.c 在 #include "cache.h" #include "module.h" #include "connection.h" #include "statement.h" #include "cursor.h" #include "prepare_protocol.h" #include "util.h" #include "sqlitecompat.h" #include "pythread.h" #define action_finalize 1 #define action_reset 2 #if sqlite_version_number >= 3003008 #ifndef sqlite_omit_load_extension #define have_load_extension #endif #endif 下面添加 #ifdef sqlite_int64_type typedef sqlite_int64_type sqlite_int64; typedef unsigned sqlite_int64_type sqlite_uint64; #elif defined(_msc_ver) || defined(__borlandc__) typedef __int64 sqlite_int64; typedef unsigned __int64 sqlite_uint64; #else typedef long long int sqlite_int64; typedef unsigned long long int sqlite_uint64; #endif typedef sqlite_int64 sqlite3_int64; typedef sqlite_uint64 sqlite3_uint64; 然后重新编译python问题解决
三:是时候结束了
自言自语:
这个监控用起来真是令人发指的简单,功能也简单。不过看到使用的技术只能独自叹息,什么时候可以去看看tornado的源码呢?
参考资料:
作者博客:http://www.nkrode.com/article/real-time-dashboard-for-redis
作者github: https://github.com/nkrode/redislive
sqlite问题: http://my.oschina.net/541996928/blog/159837
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!