記錄是一種精神,是加深理解最好的方式之一。
最近學習了怎么使用RedisLive對Redis進行運行監控,提筆記下。
曹金桂 cao_jingui@163.com(如有遺漏之處還請指教)
時間:2016年11月26日10:30
本文參考自http://www.nkrode.com/article/real-time-dashboard-for-redis
1. 概述
Redis Live是一個用來監控redis實例,分析查詢語句并且有web界面的監控工具,使用python編寫。
本文編寫時使用環境為Centos 64位系統。
2. 安裝python環境
RedisLive使用python編寫,運行時需要python環境支持
- yum install python-setuptools
- easy_install pip
- pip install tornado
- pip install redis
- pip install python-dateutil
- pip install argparse (python版本低于2.7需要安裝,可使用python查看版本)
3. 安裝RedisLive
- git clone https://github.com/kumarnitin/RedisLive.git (使用yum install git按照git環境)
- 修改redis-live.conf配置文件,說明如下
{
"RedisServers": //數組配置多個待監控的Reids實例
[
{
"server": "192.168.2.128",
"port" : 6379
},
{
"server": "localhost",
"port" : 6380,
"password" : "some-password" //指定Redis服務連接密碼
}
],
"DataStoreType" : "sqlite", //監控數據存儲[redis|sqlite]
"RedisStatsServer": //DataStoreType=redis時候,指定redis連接地址
{
"server" : "127.0.0.1",
"port" : 6385
},
"SqliteStatsStore" : //DataStoreType=sqlite,指定db路徑
{
"path": "/usr/local/RedisLive/src/db/redislive.db"
}
}
4. 啟動監控程序
- ./redis-monitor.py --duration=120 & #啟動監控腳本 [duration監控持續時間(秒)]
- ./redis-live.py & #啟動web服務
- 使用瀏覽器打開http://localhost:8888/index.html查看監控頁面
4. 注意
- 監控開啟后會影響到Redis的性能,所以建議定時監控而不是實時監控。
- 定時運行nohup ./redis-monitor.py --duration=秒數 & (建議使用crontab定時運行)
- 做采樣時,請合理配置采樣秒數;系統定時運行采樣腳本的頻率建議不要太頻繁
官方參考
http://www.nkrode.com/article/real-time-dashboard-for-redis