zabbix redis模板

本案例以Zabbix-2.2.2为监控平台进行创建,该方法对于zabbix 2.X以及3.X的方法也是一样可以使用,只不过zabbix 2.x平台导入模板的时候,需要编辑模板xml文件将version 3.0改成2.0才可以导入,否则出错。如zabbix V3.X,则可以直接导入并按照如下方法配置使用。这里只是一个通用操作,如需更加完善功能可以自己添加监控项以及触发器等。
1,导入模板
下载链接: http://download.21yunwei.com/zabbix/redis/zbx_template_redis.tar.gz 导入模板成功以后,将需要监控redis的主机添加这个模板。
注意:需 确认监控平台版本,低于3.0的需要编辑xml改成2.0后再去导入。

2,创建采集脚本
我的监控采集脚本都放到了/home/yunwei/redis_zbx.sh,在这里创建脚本保存shell脚本:
vim redis_zbx.sh

  1. !/bin/bash

  2. REDISPATH="/usr/bin/redis-cli"
  3. HOST="127.0.0.1"
  4. PORT="6379"
  5. REDIS_INFO="HOST -p $PORT info"
  6. if [[ $# == 1 ]];then
  7. case $1 in
  8. cluster)
  9. result=$REDIS_INFO|/bin/grep cluster|awk -F":" '{print $NF}'
  10. echo $result
  11. ;;
  12. uptime_in_seconds)
  13. result=$REDIS_INFO|/bin/grep uptime_in_seconds|awk -F":" '{print $NF}'
  14. echo $result
  15. ;;
  16. connected_clients)
  17. result=$REDIS_INFO|/bin/grep connected_clients|awk -F":" '{print $NF}'
  18. echo $result
  19. ;;
  20. client_longest_output_list)
  21. result=$REDIS_INFO|/bin/grep client_longest_output_list|awk -F":" '{print $NF}'
  22. echo $result
  23. ;;
  24. client_biggest_input_buf)
  25. result=$REDIS_INFO|/bin/grep client_biggest_input_buf|awk -F":" '{print $NF}'
  26. echo $result
  27. ;;
  28. blocked_clients)
  29. result=$REDIS_INFO|/bin/grep blocked_clients|awk -F":" '{print $NF}'
  30. echo $result
  31. ;;
  32. 内存

  33. used_memory)
  34. result=$REDIS_INFO|/bin/grep used_memory|awk -F":" '{print $NF}'|awk 'NR==1'
  35. echo $result
  36. ;;
  37. used_memory_human)
  38. result=$REDIS_INFO|/bin/grep used_memory_human|awk -F":" '{print $NF}'|awk -F'K' '{print $1}'
  39. echo $result
  40. ;;
  41. used_memory_rss)
  42. result=$REDIS_INFO|/bin/grep used_memory_rss|awk -F":" '{print $NF}'
  43. echo $result
  44. ;;
  45. used_memory_peak)
  46. result=$REDIS_INFO|/bin/grep used_memory_peak|awk -F":" '{print $NF}'|awk 'NR==1'
  47. echo $result
  48. ;;
  49. used_memory_peak_human)
  50. result=$REDIS_INFO|/bin/grep used_memory_peak_human|awk -F":" '{print $NF}'|awk -F'K' '{print $1}'
  51. echo $result
  52. ;;
  53. used_memory_lua)
  54. result=$REDIS_INFO|/bin/grep used_memory_lua|awk -F":" '{print $NF}'
  55. echo $result
  56. ;;
  57. mem_fragmentation_ratio)
  58. result=$REDIS_INFO|/bin/grep mem_fragmentation_ratio|awk -F":" '{print $NF}'
  59. echo $result
  60. ;;
  61. rdb

  62. rdb_changes_since_last_save)
  63. result=$REDIS_INFO|/bin/grep rdb_changes_since_last_save|awk -F":" '{print $NF}'
  64. echo $result
  65. ;;
  66. rdb_bgsave_in_progress)
  67. result=$REDIS_INFO|/bin/grep rdb_bgsave_in_progress|awk -F":" '{print $NF}'
  68. echo $result
  69. ;;
  70. rdb_last_save_time)
  71. result=$REDIS_INFO|/bin/grep rdb_last_save_time|awk -F":" '{print $NF}'
  72. echo $result
  73. ;;
  74. rdb_last_bgsave_status)
  75. result=$REDIS_INFO|/bin/grep -w "rdb_last_bgsave_status" | awk -F':' '{print $2}' | /bin/grep -c ok
  76. echo $result
  77. ;;
  78. rdb_current_bgsave_time_sec)
  79. result=$REDIS_INFO|/bin/grep -w "rdb_current_bgsave_time_sec" | awk -F':' '{print $2}'
  80. echo $result
  81. ;;
  82. rdbinfo

  83. aof_enabled)
  84. result=$REDIS_INFO|/bin/grep -w "aof_enabled" | awk -F':' '{print $2}'
  85. echo $result
  86. ;;
  87. aof_rewrite_scheduled)
  88. result=$REDIS_INFO|/bin/grep -w "aof_rewrite_scheduled" | awk -F':' '{print $2}'
  89. echo $result
  90. ;;
  91. aof_last_rewrite_time_sec)
  92. result=$REDIS_INFO|/bin/grep -w "aof_last_rewrite_time_sec" | awk -F':' '{print $2}'
  93. echo $result
  94. ;;
  95. aof_current_rewrite_time_sec)
  96. result=$REDIS_INFO|/bin/grep -w "aof_current_rewrite_time_sec" | awk -F':' '{print $2}'
  97. echo $result
  98. ;;
  99. aof_last_bgrewrite_status)
  100. result=$REDIS_INFO|/bin/grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | /bin/grep -c ok
  101. echo $result
  102. ;;
  103. aofinfo

  104. aof_current_size)
  105. result=$REDIS_INFO|/bin/grep -w "aof_current_size" | awk -F':' '{print $2}'
  106. echo $result
  107. ;;
  108. aof_base_size)
  109. result=$REDIS_INFO|/bin/grep -w "aof_base_size" | awk -F':' '{print $2}'
  110. echo $result
  111. ;;
  112. aof_pending_rewrite)
  113. result=$REDIS_INFO|/bin/grep -w "aof_pending_rewrite" | awk -F':' '{print $2}'
  114. echo $result
  115. ;;
  116. aof_buffer_length)
  117. result=$REDIS_INFO|/bin/grep -w "aof_buffer_length" | awk -F':' '{print $2}'
  118. echo $result
  119. ;;
  120. aof_rewrite_buffer_length)
  121. result=$REDIS_INFO|/bin/grep -w "aof_rewrite_buffer_length" | awk -F':' '{print $2}'
  122. echo $result
  123. ;;
  124. aof_pending_bio_fsync)
  125. result=$REDIS_INFO|/bin/grep -w "aof_pending_bio_fsync" | awk -F':' '{print $2}'
  126. echo $result
  127. ;;
  128. aof_delayed_fsync)
  129. result=$REDIS_INFO|/bin/grep -w "aof_delayed_fsync" | awk -F':' '{print $2}'
  130. echo $result
  131. ;;
  132. stats

  133. total_connections_received)
  134. result=$REDIS_INFO|/bin/grep -w "total_connections_received" | awk -F':' '{print $2}'
  135. echo $result
  136. ;;
  137. total_commands_processed)
  138. result=$REDIS_INFO|/bin/grep -w "total_commands_processed" | awk -F':' '{print $2}'
  139. echo $result
  140. ;;
  141. instantaneous_ops_per_sec)
  142. result=$REDIS_INFO|/bin/grep -w "instantaneous_ops_per_sec" | awk -F':' '{print $2}'
  143. echo $result
  144. ;;
  145. rejected_connections)
  146. result=$REDIS_INFO|/bin/grep -w "rejected_connections" | awk -F':' '{print $2}'
  147. echo $result
  148. ;;
  149. expired_keys)
  150. result=$REDIS_INFO|/bin/grep -w "expired_keys" | awk -F':' '{print $2}'
  151. echo $result
  152. ;;
  153. evicted_keys)
  154. result=$REDIS_INFO|/bin/grep -w "evicted_keys" | awk -F':' '{print $2}'
  155. echo $result
  156. ;;
  157. keyspace_hits)
  158. result=$REDIS_INFO|/bin/grep -w "keyspace_hits" | awk -F':' '{print $2}'
  159. echo $result
  160. ;;
  161. keyspace_misses)
  162. result=$REDIS_INFO|/bin/grep -w "keyspace_misses" | awk -F':' '{print $2}'
  163. echo $result
  164. ;;
  165. pubsub_channels)
  166. result=$REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}'
  167. echo $result
  168. ;;
  169. pubsub_channels)
  170. result=$REDIS_INFO|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}'
  171. echo $result
  172. ;;
  173. pubsub_patterns)
  174. result=$REDIS_INFO|/bin/grep -w "pubsub_patterns" | awk -F':' '{print $2}'
  175. echo $result
  176. ;;
  177. latest_fork_usec)
  178. result=$REDIS_INFO|/bin/grep -w "latest_fork_usec" | awk -F':' '{print $2}'
  179. echo $result
  180. ;;
  181. connected_slaves)
  182. result=$REDIS_INFO|/bin/grep -w "connected_slaves" | awk -F':' '{print $2}'
  183. echo $result
  184. ;;
  185. master_link_status)
  186. result=$REDIS_INFO|/bin/grep -w "master_link_status"|awk -F':' '{print $2}'|/bin/grep -c up
  187. echo $result
  188. ;;
  189. master_last_io_seconds_ago)
  190. result=$REDIS_INFO|/bin/grep -w "master_last_io_seconds_ago"|awk -F':' '{print $2}'
  191. echo $result
  192. ;;
  193. master_sync_in_progress)
  194. result=$REDIS_INFO|/bin/grep -w "master_sync_in_progress"|awk -F':' '{print $2}'
  195. echo $result
  196. ;;
  197. slave_priority)
  198. result=$REDIS_INFO|/bin/grep -w "slave_priority"|awk -F':' '{print $2}'
  199. echo $result
  200. ;;
  201. cpu

  202. used_cpu_sys)
  203. result=$REDIS_INFO|/bin/grep -w "used_cpu_sys"|awk -F':' '{print $2}'
  204. echo $result
  205. ;;
  206. used_cpu_user)
  207. result=$REDIS_INFO|/bin/grep -w "used_cpu_user"|awk -F':' '{print $2}'
  208. echo $result
  209. ;;
  210. used_cpu_sys_children)
  211. result=$REDIS_INFO|/bin/grep -w "used_cpu_sys_children"|awk -F':' '{print $2}'
  212. echo $result
  213. ;;
  214. used_cpu_user_children)
  215. result=$REDIS_INFO|/bin/grep -w "used_cpu_user_children"|awk -F':' '{print $2}'
  216. echo $result
  217. ;;
  218. *)
  219. echo "argu error"
  220. ;;
  221. esac
  222. db0:key

  223. elif [[ $# == 2 ]];then
  224. case $2 in
  225. keys)
  226. result=$REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "keys" | awk -F'=|,' '{print $2}'
  227. echo $result
  228. ;;
  229. expires)
  230. result=$REDIS_INFO| /bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "expires" | awk -F'=|,' '{print $4}'
  231. echo $result
  232. ;;
  233. avg_ttl)
  234. result=$REDIS_INFO|/bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "avg_ttl" | awk -F'=|,' '{print $6}'
  235. echo $result
  236. ;;
  237. *)
  238. echo "argu error" ;;
  239. esac
  240. fi

赋予权限:chmod +x redis_zbx.sh

3,编辑agentd配置文件

  1. 监控redis状态,我们可以根据这个参数对应的监控项创建redis状态触发器。

  2. redis monitor

  3. UserParameter=redis.status,/usr/bin/redis-cli -h 127.0.0.1 -p 6379 ping |grep -c PONG
  4. UserParameter=redis_info[*],/home/yunwei/redis_zbx.sh 2

重启agentd服务,使之生效。

好了,我们到administraton-general-other刷新下被监控主机不支持的监控项,使之生效后测试看下效果(太多数据了,这里只举例几个):
内存使用情况:

e

redis status状态信息:

1

说明:
1,这个模板redis监控的参数比较多,具体根据自己的实际情况启用redis里边的应用集或者监控项,也可以自己再添加,。
2,默认aof未开启 以及slave这里都有监控,用不到的就停掉,这个模板。当前模板四个触发器,其中关于aof和主从的关了,只保留了redis存活状态和redis磁盘回写失败与否两个触发器。

你可能感兴趣的:(zabbix redis模板)