Redis服务端状态与性能监控(二)

来源:互联网 发布:阿加莎克里斯蒂知乎 编辑:程序博客网 时间:2024/06/11 08:39
一、简介

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

三、附注
        更多监控解决方案原文见这里,译文见这里


转自:http://blog.chinaunix.net/uid-22312037-id-3580019.html

http://www.linuxyan.com/cacti-nagios/231.html


0 0