zabbix 监控 redis
生活随笔
收集整理的這篇文章主要介紹了
zabbix 监控 redis
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
通過redis自帶的info命令來監(jiān)控redis的健康狀態(tài),通過redis-cli PING命令來監(jiān)控redis的存活狀態(tài)。
附件中有監(jiān)控模板,將監(jiān)控腳本放在redis服務(wù)器的自定義的/scripts/zabbix_redis/下:
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #!?/bin/bash #Name:?redismontior.sh REDISCLI="/usr/bin/redis-cli" HOST="127.0.0.1" PORT=6379 if?[[?$#?==?1?]];then ????case?$1?in ????????version) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"redis_version"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????uptime) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"uptime_in_seconds"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????connected_clients) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"connected_clients"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????blocked_clients) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"blocked_clients"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_memory) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_memory"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_memory_rss) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_memory_rss"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_memory_peak) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_memory_peak"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_memory_lua) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_memory_lua"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_cpu_sys) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_cpu_sys"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_cpu_user) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_cpu_user"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_cpu_sys_children) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_cpu_sys_children"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????used_cpu_user_children) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"used_cpu_user_children"?|?awk?-F':'?'{print?$2}'` ????????????echo?$result ????????;; ????????rdb_last_bgsave_status) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info??|?grep?-w?"rdb_last_bgsave_status"?|?awk?-F':'?'{print?$2}'?|?grep?-c?ok` ????????????echo?$result ????????;; ????????aof_last_bgrewrite_status) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info??|?grep?-w?"aof_last_bgrewrite_status"?|?awk?-F':'?'{print?$2}'?|?grep?-c?ok` ????????????echo?$result ????????;; ????????aof_last_write_status) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info??|?grep?-w?"aof_last_write_status"?|?awk?-F':'?'{print?$2}'?|?grep?-c?ok` ????????????echo?$result ????????;; ????????*) ????????????echo?-e?"\033[33mUsage:?$0?{connected_clients|blocked_clients|used_memory|used_memory_rss|used_memory_peak|used_memory_lua|used_cpu_sys|used_cpu_user|used_cpu_sys_children|used_cpu_user_children|rdb_last_bgsave_status|aof_last_bgrewrite_status|aof_last_write_status}\033[0m"? ????????;; ????esac elif?[[?$#?==?2?]];then ????case?$2?in ????????keys) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"$1"?|?grep?-w?"keys"?|?awk?-F'=|,'?'{print?$2}'` ????????????echo?$result ????????;; ????????expires) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"$1"?|?grep?-w?"keys"?|?awk?-F'=|,'?'{print?$4}'` ????????????echo?$result ????????;; ????????avg_ttl) ????????????result=`$REDISCLI?-h?$HOST?-p?$PORT?info?|?grep?-w?"$1"?|?grep?-w?"avg_ttl"?|?awk?-F'=|,'?'{print?$6}'` ????????????echo?$result ????????;; ????????*) ????????????echo?-e?"\033[33mUsage:?$0?{db0?keys|db0?expires|db0?avg_ttl}\033[0m"? ????????;; ????esac fi |
zabbix參數(shù)key的設(shè)置:
| 1 2 3 4 | #?cat?/etc/zabbix/zabbix_agentd.d/userparameter_redis.conf? UserParameter=Redis.Status,?redis-cli?PING|grep?-c?"PONG" UserParameter=Redis.Info[*],?/bin/sh?/scripts/zabbix_redis/zabbix_redis.sh?$1 |
模板見附件.其中對腳本傳入兩個參數(shù)的部分,對于不同的環(huán)境可能會不太兼容,可以對模板和腳本進行修改,或者直接在模板中禁用對應(yīng)的item。
附件:http://down.51cto.com/data/2366694
?本文轉(zhuǎn)自 酥心糖 51CTO博客,原文鏈接:http://blog.51cto.com/tryingstuff/1929435
總結(jié)
以上是生活随笔為你收集整理的zabbix 监控 redis的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: SVR4/4.3BSD与Linux对待伪
- 下一篇: linux中常用的压缩、解压命令详解