├── zabbix-redis.conf ├── redis └── redis-status.sh └── zabbix-redis-template.xml /zabbix-redis.conf: -------------------------------------------------------------------------------- 1 | #Redis 2 | UserParameter=redis.discovery,/etc/zabbix/script/redis/redis-status.sh localhost list_key_space_db 3 | UserParameter=redis[*],/etc/zabbix/script/redis/redis-status.sh $1 $2 $3 4 | -------------------------------------------------------------------------------- /redis/redis-status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | #Redis status 4 | 5 | METRIC="$2" 6 | SERV="$1" 7 | DB="$3" 8 | 9 | PORT="6379" 10 | 11 | if [[ -z "$1" ]]; then 12 | echo "Please set server" 13 | exit 1 14 | fi 15 | 16 | CACHETTL="55" # Duration cache in seconds (a little less than the period of the survey items) 17 | CACHE="/tmp/redis-status-`echo $SERV | md5sum | cut -d" " -f1`.cache" 18 | 19 | if [ -s "$CACHE" ]; then 20 | TIMECACHE=`stat -c"%Z" "$CACHE"` 21 | else 22 | TIMECACHE=0 23 | fi 24 | 25 | TIMENOW=`date '+%s'` 26 | 27 | if [ "$(($TIMENOW - $TIMECACHE))" -gt "$CACHETTL" ]; then 28 | (echo -en "INFO\r\nQUIT\r\n") | nc -w1 $SERV $PORT > $CACHE || exit 1 29 | fi 30 | 31 | FIRST_ELEMENT=1 32 | function json_head { 33 | printf "{"; 34 | printf "\"data\":["; 35 | } 36 | 37 | function json_end { 38 | printf "]"; 39 | printf "}"; 40 | } 41 | 42 | function check_first_element { 43 | if [[ $FIRST_ELEMENT -ne 1 ]]; then 44 | printf "," 45 | fi 46 | FIRST_ELEMENT=0 47 | } 48 | 49 | function databse_detect { 50 | json_head 51 | for dbname in $LIST_DATABSE 52 | do 53 | local dbname_t=$(echo $dbname| sed 's!\n!!g') 54 | check_first_element 55 | printf "{" 56 | printf "\"{#DBNAME}\":\"$dbname_t\"" 57 | printf "}" 58 | done 59 | json_end 60 | } 61 | 62 | case $METRIC in 63 | 'redis_version') 64 | cat $CACHE | grep "redis_version:" | cut -d':' -f2 65 | ;; 66 | 'redis_git_sha1') 67 | cat $CACHE | grep "redis_git_sha1:" | cut -d':' -f2 68 | ;; 69 | 'redis_git_dirty') 70 | cat $CACHE | grep "redis_git_dirty:" | cut -d':' -f2 71 | ;; 72 | 'redis_mode') 73 | cat $CACHE | grep "redis_mode:" | cut -d':' -f2 74 | ;; 75 | 'arch_bits') 76 | cat $CACHE | grep "arch_bits:" | cut -d':' -f2 77 | ;; 78 | 'multiplexing_api') 79 | cat $CACHE | grep "multiplexing_api:" | cut -d':' -f2 80 | ;; 81 | 'gcc_version') 82 | cat $CACHE | grep "gcc_version:" | cut -d':' -f2 83 | ;; 84 | 'uptime_in_seconds') 85 | cat $CACHE | grep "uptime_in_seconds:" | cut -d':' -f2 86 | ;; 87 | 'lru_clock') 88 | cat $CACHE | grep "lru_clock:" | cut -d':' -f2 89 | ;; 90 | 'connected_clients') 91 | cat $CACHE | grep "connected_clients:" | cut -d':' -f2 92 | ;; 93 | 'client_longest_output_list') 94 | cat $CACHE | grep "client_longest_output_list:" | cut -d':' -f2 95 | ;; 96 | 'client_biggest_input_buf') 97 | cat $CACHE | grep "client_biggest_input_buf:" | cut -d':' -f2 98 | ;; 99 | 'used_memory') 100 | cat $CACHE | grep "used_memory:" | cut -d':' -f2 101 | ;; 102 | 'used_memory_peak') 103 | cat $CACHE | grep "used_memory_peak:" | cut -d':' -f2 104 | ;; 105 | 'mem_fragmentation_ratio') 106 | cat $CACHE | grep "mem_fragmentation_ratio:" | cut -d':' -f2 107 | ;; 108 | 'loading') 109 | cat $CACHE | grep "loading:" | cut -d':' -f2 110 | ;; 111 | 'rdb_changes_since_last_save') 112 | cat $CACHE | grep "rdb_changes_since_last_save:" | cut -d':' -f2 113 | ;; 114 | 'rdb_bgsave_in_progress') 115 | cat $CACHE | grep "rdb_bgsave_in_progress:" | cut -d':' -f2 116 | ;; 117 | 'rdb_last_bgsave_status') 118 | cat $CACHE | grep "rdb_last_bgsave_status:" | cut -d':' -f2 119 | ;; 120 | 'rdb_last_save_time') 121 | cat $CACHE | grep "rdb_last_save_time:" | cut -d':' -f2 122 | ;; 123 | 'aof_rewrite_in_progress') 124 | cat $CACHE | grep "aof_rewrite_in_progress:" | cut -d':' -f2 125 | ;; 126 | 'aof_enabled') 127 | cat $CACHE | grep "aof_enabled:" | cut -d':' -f2 128 | ;; 129 | 'aof_rewrite_scheduled') 130 | cat $CACHE | grep "aof_rewrite_scheduled:" | cut -d':' -f2 131 | ;; 132 | 'total_connections_received') 133 | cat $CACHE | grep "total_connections_received:" | cut -d':' -f2 134 | ;; 135 | 'total_commands_processed') 136 | cat $CACHE | grep "total_commands_processed:" | cut -d':' -f2 137 | ;; 138 | 'instantaneous_ops_per_sec') 139 | cat $CACHE | grep "instantaneous_ops_per_sec:" | cut -d':' -f2 140 | ;; 141 | 'rejected_connections') 142 | cat $CACHE | grep "rejected_connections:" | cut -d':' -f2 143 | ;; 144 | 'expired_keys') 145 | cat $CACHE | grep "expired_keys:" | cut -d':' -f2 146 | ;; 147 | 'evicted_keys') 148 | cat $CACHE | grep "evicted_keys:" | cut -d':' -f2 149 | ;; 150 | 'keyspace_hits') 151 | cat $CACHE | grep "keyspace_hits:" | cut -d':' -f2 152 | ;; 153 | 'keyspace_misses') 154 | cat $CACHE | grep "keyspace_misses:" | cut -d':' -f2 155 | ;; 156 | 'pubsub_channels') 157 | cat $CACHE | grep "pubsub_channels:" | cut -d':' -f2 158 | ;; 159 | 'pubsub_patterns') 160 | cat $CACHE | grep "pubsub_patterns:" | cut -d':' -f2 161 | ;; 162 | 'latest_fork_usec') 163 | cat $CACHE | grep "latest_fork_usec:" | cut -d':' -f2 164 | ;; 165 | 'role') 166 | cat $CACHE | grep "role:" | cut -d':' -f2 167 | ;; 168 | 'connected_slaves') 169 | cat $CACHE | grep "connected_slaves:" | cut -d':' -f2 170 | ;; 171 | 'used_cpu_sys') 172 | cat $CACHE | grep "used_cpu_sys:" | cut -d':' -f2 173 | ;; 174 | 'used_cpu_user') 175 | cat $CACHE | grep "used_cpu_user:" | cut -d':' -f2 176 | ;; 177 | 'used_cpu_sys_children') 178 | cat $CACHE | grep "used_cpu_sys_children:" | cut -d':' -f2 179 | ;; 180 | 'used_cpu_user_children') 181 | cat $CACHE | grep "used_cpu_user_children:" | cut -d':' -f2 182 | ;; 183 | 'key_space_db_keys') 184 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $1}'|cut -d'=' -f2 185 | ;; 186 | 'key_space_db_expires') 187 | cat $CACHE | grep $DB:|cut -d':' -f2|awk -F, '{print $2}'|cut -d'=' -f2 188 | ;; 189 | 'list_key_space_db') 190 | LIST_DATABSE=`cat $CACHE | grep '^db.:'|cut -d: -f1` 191 | databse_detect 192 | ;; 193 | 'master_last_io_seconds_ago') 194 | cat $CACHE | grep "master_last_io_seconds_ago:" | cut -d':' -f2 195 | ;; 196 | 'cluster_state') 197 | cluster_enabled=$(cat $CACHE | grep "cluster_enabled:" | cut -d':' -f2 | tr -d '\r') 198 | if [ "$cluster_enabled" = 0 ]; then 199 | echo "disabled" 200 | else 201 | cat $CACHE | grep "cluster_state:" | cut -d':' -f2 202 | fi 203 | ;; 204 | *) 205 | echo "Not selected metric" 206 | exit 0 207 | ;; 208 | esac 209 | -------------------------------------------------------------------------------- /zabbix-redis-template.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 2.0 4 | 2013-01-19T20:39:15Z 5 | 6 | 7 | Templates 8 | 9 | 10 | 11 | 1622 | 1623 | 1624 | 1625 | {Template Redis 2:net.tcp.port[127.0.0.1,6379].last(0)}=0 1626 | Redis is down on {HOSTNAME} 1627 | 1628 | 0 1629 | 4 1630 | 1631 | 0 1632 | 1633 | 1634 | 1635 | 1636 | --------------------------------------------------------------------------------