Redis圖形監控工具--RedisLive
阿新 • • 發佈:2018-12-25
一、簡介
RedisLive是一款用Python編寫的Redis圖形監控工具,其原始碼在這裡,英文文件在這裡。RedisLive的原理很簡單,就是通過監控指令碼來利用Redis提供的MONITOR命令從被監控Redis例項中獲取資料並存儲到Redis的監控例項中來做資料分析。RedisLive以視覺化的方式展示了Redis例項中的資料,分析查詢模式和峰值,下圖是官方提供的效果圖:
圖1 RedisLive監控介面 有如此好槍,還等什麼,趕緊行動吧,喂,哥們兒,不是搶銀行,別誤會了。
二、安裝
下面以CentOS Linux release 6.0 (Final)為例,介紹如何安裝RedisLive:
(1)Python
既然RedisLive由Python編寫,那麼Python環境是必不可少的,一般Linux預設都安裝了Python,比如:CentOS Linux release 6.0 (Final)預設安裝的就是Python 2.6.5。在終端敲如下命令,可以驗證是否已經安裝了Python:
#python
Python 2.6.5 (r265:79063, Nov 12 2010, 00:52:45)
[GCC 4.4.4 20100525 (Red Hat 4.4.4-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
出現如上資訊說明已經安裝了Python,否則如下安裝Python:
#yum install python
(2)python-setuptools
執行如下指令安裝python-setuptools:
#yum install python-setuptools
(3)pip-python
按照如下步驟下載並安裝pip-python:
#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/python-pip-0.8-1.el6.noarch.rpm
#rpm -ivh python-pip-0.8-1.el6.noarch.rpm
#pip-python install tornado
#wget https://github.com/andymccurdy/redis-py.git
#wget https://github.com/andymccurdy/redis-py/archive/master.zip
#unzip master
#cd redis-py-master/
#python setup.py install
#cd ..
#pip-python install python-dateutil
#pip-python install argparse
(4)RedisLive
前面的那些前戲只不過是環境部署,男一號終於要上正席了:
#git clone https://github.com/kumarnitin/RedisLive.git
#cd RedisLive/src
#vi redis-live.conf
{
"RedisServers":
[
{
"server": "127.0.0.1",
"port" : 6379
}
],
"DataStoreType" : "redis",
"RedisStatsServer":
{
"server" : "127.0.0.1",
"port" : 6381
}
}
修改監控和被監控Redis例項的配置資訊並分別啟動這兩個Redis例項。
RedisServer是被監控Redis例項的配置,RedisStatsServer是監控Redis例項的配置,如果不希望將監控資訊儲存在Redis中,則需要將DataStoreType由redis改為sqlite型別即可,這樣RedisStatsServer也就不用配置了。
如果被監控Redis需要密碼才能訪問,則需要在RedisServers部分如下來配置:
"RedisServers":
[
{
"server": "127.0.0.1",
"port" : 6379
“password”: "xxxxxx"
}
],
配置好之後就可以如下來啟動服務了:
(A)開啟監控指令碼
#./redis-monitor.py --duration 120 &
(B)開啟webserver
#./redis-live.py &
(C)在瀏覽器中輸入如下地址來檢視RedisLive
http://localhost:8888/index.html
銷魂的圖1出現了。
需要注意的是:
(1)如果在瀏覽器調入地址後出現無法訪問的現象請關閉防火牆或者開埠8888。
(2)如果在執行./redis-live.py &後出現如下錯誤:
ImportError: No module named dateutil.parser
則需要如此這般:
(A)下載新版python-dateutil並安裝
#wget http://labix.org/download/python-dateutil/python-dateutil-2.0.tar.gz
#tar -zxvf python-dateutil-2.0.tar.gz
#cd python-dateutil-2.0
#python setup.py install
#cd ..
(B)重新開啟監控指令碼和webserver即可:
#./redis-monitor.py --duration 120 &
#./redis-live.py &
(3)啟動服務之後,如果訪問web頁面,則會在當前終端輸出日誌,如果不想在終端輸出,可以檢視redis-live.py的引數
#./redis-live.py --help
Usage: ./redis-live.py [OPTIONS]
Options:
--debug debug mode (default 0)
--help show this help information
--port run on the given port (default 8888)
/usr/lib/python2.6/site-packages/tornado/log.py options:
--log_file_max_size max size of log files before rollover
(default 100000000)
--log_file_num_backups number of log files to keep (default 10)
--log_file_prefix=PATH Path prefix for log files. Note that if you
are running multiple tornado processes,
log_file_prefix must be different for each
of them (e.g. include the port number)
--log_to_stderr Send log output to stderr (colorized if
possible). By default use stderr if
--log_file_prefix is not set and no other
logging is configured.
--logging=debug|info|warning|error|none
Set the Python log level. If 'none', tornado
won't touch the logging configuration.
(default info)
可以到有日誌檔案大小、備份日誌檔案數、日誌檔案路徑、錯誤日誌輸出、日誌等級等資訊。
(4)監控開啟後會影響到Redis的效能,所以建議定時監控而不是實時監控。
三、附註
更多監控解決方案原文見這裡,譯文見這裡。
RedisLive是一款用Python編寫的Redis圖形監控工具,其原始碼在這裡,英文文件在這裡。RedisLive的原理很簡單,就是通過監控指令碼來利用Redis提供的MONITOR命令從被監控Redis例項中獲取資料並存儲到Redis的監控例項中來做資料分析。RedisLive以視覺化的方式展示了Redis例項中的資料,分析查詢模式和峰值,下圖是官方提供的效果圖:
圖1 RedisLive監控介面 有如此好槍,還等什麼,趕緊行動吧,喂,哥們兒,不是搶銀行,別誤會了。
二、安裝
下面以CentOS Linux release 6.0 (Final)為例,介紹如何安裝RedisLive:
(1)Python
既然RedisLive由Python編寫,那麼Python環境是必不可少的,一般Linux預設都安裝了Python,比如:CentOS Linux release 6.0 (Final)預設安裝的就是Python 2.6.5。在終端敲如下命令,可以驗證是否已經安裝了Python:
#python
Python 2.6.5 (r265:79063, Nov 12 2010, 00:52:45)
[GCC 4.4.4 20100525 (Red Hat 4.4.4-5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
出現如上資訊說明已經安裝了Python,否則如下安裝Python:
#yum install python
(2)python-setuptools
執行如下指令安裝python-setuptools:
#yum install python-setuptools
(3)pip-python
按照如下步驟下載並安裝pip-python:
#wget http://dl.fedoraproject.org/pub/epel/6/x86_64/python-pip-0.8-1.el6.noarch.rpm
#rpm -ivh python-pip-0.8-1.el6.noarch.rpm
#pip-python install tornado
#wget https://github.com/andymccurdy/redis-py.git
#wget https://github.com/andymccurdy/redis-py/archive/master.zip
#unzip master
#cd redis-py-master/
#python setup.py install
#cd ..
#pip-python install python-dateutil
#pip-python install argparse
(4)RedisLive
前面的那些前戲只不過是環境部署,男一號終於要上正席了:
#git clone https://github.com/kumarnitin/RedisLive.git
#cd RedisLive/src
#vi redis-live.conf
{
"RedisServers":
[
{
"server": "127.0.0.1",
"port" : 6379
}
],
"DataStoreType" : "redis",
"RedisStatsServer":
{
"server" : "127.0.0.1",
"port" : 6381
}
}
修改監控和被監控Redis例項的配置資訊並分別啟動這兩個Redis例項。
RedisServer是被監控Redis例項的配置,RedisStatsServer是監控Redis例項的配置,如果不希望將監控資訊儲存在Redis中,則需要將DataStoreType由redis改為sqlite型別即可,這樣RedisStatsServer也就不用配置了。
如果被監控Redis需要密碼才能訪問,則需要在RedisServers部分如下來配置:
"RedisServers":
[
{
"server": "127.0.0.1",
"port" : 6379
“password”: "xxxxxx"
}
],
配置好之後就可以如下來啟動服務了:
(A)開啟監控指令碼
#./redis-monitor.py --duration 120 &
(B)開啟webserver
#./redis-live.py &
(C)在瀏覽器中輸入如下地址來檢視RedisLive
http://localhost:8888/index.html
銷魂的圖1出現了。
需要注意的是:
(1)如果在瀏覽器調入地址後出現無法訪問的現象請關閉防火牆或者開埠8888。
(2)如果在執行./redis-live.py &後出現如下錯誤:
ImportError: No module named dateutil.parser
則需要如此這般:
(A)下載新版python-dateutil並安裝
#wget http://labix.org/download/python-dateutil/python-dateutil-2.0.tar.gz
#tar -zxvf python-dateutil-2.0.tar.gz
#cd python-dateutil-2.0
#python setup.py install
#cd ..
(B)重新開啟監控指令碼和webserver即可:
#./redis-monitor.py --duration 120 &
#./redis-live.py &
(3)啟動服務之後,如果訪問web頁面,則會在當前終端輸出日誌,如果不想在終端輸出,可以檢視redis-live.py的引數
#./redis-live.py --help
Usage: ./redis-live.py [OPTIONS]
Options:
--debug debug mode (default 0)
--help show this help information
--port run on the given port (default 8888)
/usr/lib/python2.6/site-packages/tornado/log.py options:
--log_file_max_size max size of log files before rollover
(default 100000000)
--log_file_num_backups number of log files to keep (default 10)
--log_file_prefix=PATH Path prefix for log files. Note that if you
are running multiple tornado processes,
log_file_prefix must be different for each
of them (e.g. include the port number)
--log_to_stderr Send log output to stderr (colorized if
possible). By default use stderr if
--log_file_prefix is not set and no other
logging is configured.
--logging=debug|info|warning|error|none
Set the Python log level. If 'none', tornado
won't touch the logging configuration.
(default info)
可以到有日誌檔案大小、備份日誌檔案數、日誌檔案路徑、錯誤日誌輸出、日誌等級等資訊。
(4)監控開啟後會影響到Redis的效能,所以建議定時監控而不是實時監控。
三、附註
更多監控解決方案原文見這裡,譯文見這裡。