Zabbix監控之Redis自動探索並監控

來源:互聯網
上載者:User

Zabbix監控之Redis自動探索並監控

系統版本CentOS5.10
Python版本2.4.3

1、python支援
yum -y install python-simplejson

2、discovery指令碼
[root@localhost etc]# cat  redis_port.py

#!/usr/bin/env python
import os
#import json
import simplejson as json  #特別要注意的地方
t=os.popen("""sudo netstat -tlpn |grep codis-server|grep 0.0.0.0|awk '{print $4}'|awk -F: '{print $2}' """)
ports = []
for port in  t.readlines():
        r = os.path.basename(port.strip())
        ports += [{'{#REDISPORT}':r}]
print json.dumps({'data':ports},sort_keys=True,indent=4,separators=(',',':'))

3,、試執行指令碼
[root@localhost etc]# python redis_port.py
{
    "data":[
        {
            "{#REDISPORT}":"6379"
        }
    ]
}

4,zabbix_agent設定
[root@localhost ~]# tail -n 2 /usr/local/zabbix/etc/zabbix_agentd.conf
UserParameter=redis.discovery,/usr/local/zabbix/etc/redis_port.py
UserParameter=redis_stats[*],redis-cli -h 127.0.0.1 -a redis_passwd -p $1 info|grep $2|cut -d : -f2
[root@localhost ~]# chmod a+x /usr/local/zabbix/etc/redis_port.py

5,sudo許可權
[root@localhost ~]# tail -n 1 /etc/sudoers
zabbix ALL=(root) NOPASSWD:/bin/netstat
[root@localhost ~]# sed -i 's/^Defaults.*.requiretty/#Defaults    requiretty/' /etc/sudoers
[root@localhost ~]# grep requiretty /etc/sudoers
#Defaults    requiretty
# changed in order to be able to use sudo without a tty. See requiretty above.

6,服務端驗證
[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k redis.discovery
{
    "data":[
        {
            "{#REDISPORT}":"6379"
        }
    ]
}

[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k redis_stats[6379,used_memory:]
651534360
[root@zabbixserver-nginx ~]# zabbix_get -s 172.17.2.114 -k "redis_stats[6379,blocked_clients]"
0

7,zabbix web介面匯入下載的模板,添加監控項後檢查監控映像

redis模板下載見下:

------------------------------------------分割線------------------------------------------

免費在 http://linux.bkjia.com/

使用者名稱與密碼都是www.bkjia.com

具體下載目錄在 /2015年資料/7月/19日/Zabbix監控之Redis自動探索並監控/

下載方法見

------------------------------------------分割線------------------------------------------

Ubuntu 14.04下Redis安裝及簡單測試

Redis叢集明細文檔

Ubuntu 12.10下安裝Redis(圖文詳解)+ Jedis串連Redis

Redis系列-安裝部署維護篇

CentOS 6.3安裝Redis

Redis安裝部署學習筆記

Redis設定檔redis.conf 詳解

Redis 的詳細介紹:請點這裡
Redis 的:請點這裡

本文永久更新連結地址:

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.