天天看点

Redis图形监控工具--RedisLive

一、简介

Redis图形监控工具--RedisLive

图1 RedisLive监控界面

        有如此好枪,还等什么,赶紧行动吧

Redis图形监控工具--RedisLive

,喂,哥们儿,不是抢银行

Redis图形监控工具--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出现了

Redis图形监控工具--RedisLive

        需要注意的是:

        (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的性能,所以建议定时监控而不是实时监控。

三、附注