博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
zabbix日常监控(监控缓存)
阅读量:5875 次
发布时间:2019-06-19

本文共 10852 字,大约阅读时间需要 36 分钟。

实现的方法大体类似:

 

多谢博主的文章,免了不少时间!

摘抄博文地址:

 

一、监控Redis

  1、创建采集脚本

vim /etc/zabbix/scripts/redis.sh

1 #!/bin/bash  2 REDISPATH="/usr/local/bin/redis-cli"  3 HOST="127.0.0.1"  4 PORT="6379"  5 REDIS_PA="$REDISPATH -h $HOST -p $PORT info"  6 if [[ $# == 1 ]];then  7     case $1 in  8  cluster)  9         result=`$REDIS_PA|/bin/grep cluster|awk -F":" '{print $NF}'` 10             echo $result  11             ;;  12  uptime_in_seconds) 13         result=`$REDIS_PA|/bin/grep uptime_in_seconds|awk -F":" '{print $NF}'` 14             echo $result  15             ;;  16  connected_clients) 17         result=`$REDIS_PA|/bin/grep connected_clients|awk -F":" '{print $NF}'` 18             echo $result  19             ;;  20  client_longest_output_list) 21         result=`$REDIS_PA|/bin/grep client_longest_output_list|awk -F":" '{print $NF}'` 22             echo $result  23             ;;  24  client_biggest_input_buf) 25         result=`$REDIS_PA|/bin/grep client_biggest_input_buf|awk -F":" '{print $NF}'` 26             echo $result  27             ;;  28  blocked_clients) 29         result=`$REDIS_PA|/bin/grep blocked_clients|awk -F":" '{print $NF}'` 30             echo $result  31             ;;  32 #内存 33  used_memory) 34         result=`$REDIS_PA|/bin/grep used_memory|awk -F":" '{print $NF}'|awk 'NR==1'` 35             echo $result  36             ;;  37  used_memory_human) 38         result=`$REDIS_PA|/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_PA|/bin/grep used_memory_rss|awk -F":" '{print $NF}'` 43             echo $result  44             ;;  45  used_memory_peak) 46         result=`$REDIS_PA|/bin/grep used_memory_peak|awk -F":" '{print $NF}'|awk 'NR==1'` 47             echo $result  48             ;;  49  used_memory_peak_human) 50         result=`$REDIS_PA|/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_PA|/bin/grep used_memory_lua|awk -F":" '{print $NF}'` 55             echo $result  56             ;;      57  mem_fragmentation_ratio) 58         result=`$REDIS_PA|/bin/grep mem_fragmentation_ratio|awk -F":" '{print $NF}'` 59             echo $result  60             ;;    61 #rdb 62  rdb_changes_since_last_save) 63         result=`$REDIS_PA|/bin/grep rdb_changes_since_last_save|awk -F":" '{print $NF}'` 64             echo $result  65             ;;    66  rdb_bgsave_in_progress) 67         result=`$REDIS_PA|/bin/grep rdb_bgsave_in_progress|awk -F":" '{print $NF}'` 68             echo $result  69             ;;    70  rdb_last_save_time) 71         result=`$REDIS_PA|/bin/grep rdb_last_save_time|awk -F":" '{print $NF}'` 72             echo $result  73             ;;    74  rdb_last_bgsave_status) 75         result=`$REDIS_PA|/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_PA|/bin/grep -w "rdb_current_bgsave_time_sec" | awk -F':' '{print $2}'` 80             echo $result  81             ;;  82 #rdbinfo 83  aof_enabled) 84         result=`$REDIS_PA|/bin/grep -w "aof_enabled" | awk -F':' '{print $2}'` 85             echo $result  86             ;;  87  aof_rewrite_scheduled) 88         result=`$REDIS_PA|/bin/grep -w "aof_rewrite_scheduled" | awk -F':' '{print $2}'` 89             echo $result  90             ;;  91  aof_last_rewrite_time_sec) 92         result=`$REDIS_PA|/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_PA|/bin/grep -w "aof_current_rewrite_time_sec" | awk -F':' '{print $2}'` 97             echo $result  98             ;;  99  aof_last_bgrewrite_status)100         result=`$REDIS_PA|/bin/grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | /bin/grep -c ok`101             echo $result 102             ;; 103 #aofinfo104  aof_current_size)105         result=`$REDIS_PA|/bin/grep -w "aof_current_size" | awk -F':' '{print $2}'`106             echo $result 107             ;; 108  aof_base_size)109         result=`$REDIS_PA|/bin/grep -w "aof_base_size" | awk -F':' '{print $2}'`110             echo $result 111             ;; 112  aof_pending_rewrite)113         result=`$REDIS_PA|/bin/grep -w "aof_pending_rewrite" | awk -F':' '{print $2}'`114             echo $result 115             ;; 116  aof_buffer_length)117         result=`$REDIS_PA|/bin/grep -w "aof_buffer_length" | awk -F':' '{print $2}'`118             echo $result 119             ;; 120  aof_rewrite_buffer_length)121         result=`$REDIS_PA|/bin/grep -w "aof_rewrite_buffer_length" | awk -F':' '{print $2}'`122             echo $result 123             ;;   124  aof_pending_bio_fsync)125         result=`$REDIS_PA|/bin/grep -w "aof_pending_bio_fsync" | awk -F':' '{print $2}'`126             echo $result 127             ;;128  aof_delayed_fsync)129         result=`$REDIS_PA|/bin/grep -w "aof_delayed_fsync" | awk -F':' '{print $2}'`130             echo $result 131             ;;                     132 #stats133  total_connections_received)134         result=`$REDIS_PA|/bin/grep -w "total_connections_received" | awk -F':' '{print $2}'`135             echo $result 136             ;; 137  total_commands_processed)138         result=`$REDIS_PA|/bin/grep -w "total_commands_processed" | awk -F':' '{print $2}'`139             echo $result 140             ;; 141  instantaneous_ops_per_sec)142         result=`$REDIS_PA|/bin/grep -w "instantaneous_ops_per_sec" | awk -F':' '{print $2}'`143             echo $result 144             ;; 145  rejected_connections)146         result=`$REDIS_PA|/bin/grep -w "rejected_connections" | awk -F':' '{print $2}'` 147             echo $result 148             ;; 149  expired_keys)150         result=`$REDIS_PA|/bin/grep -w "expired_keys" | awk -F':' '{print $2}'`151             echo $result 152             ;; 153  evicted_keys)154         result=`$REDIS_PA|/bin/grep -w "evicted_keys" | awk -F':' '{print $2}'` 155             echo $result 156             ;; 157  keyspace_hits)158         result=`$REDIS_PA|/bin/grep -w "keyspace_hits" | awk -F':' '{print $2}'` 159             echo $result 160             ;; 161  keyspace_misses)162         result=`$REDIS_PA|/bin/grep -w "keyspace_misses" | awk -F':' '{print $2}'`163             echo $result 164             ;;165  pubsub_channels)166         result=`$REDIS_PA|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}'`167             echo $result 168             ;;169  pubsub_channels)170         result=`$REDIS_PA|/bin/grep -w "pubsub_channels" | awk -F':' '{print $2}'`171             echo $result 172             ;;173  pubsub_patterns)174         result=`$REDIS_PA|/bin/grep -w "pubsub_patterns" | awk -F':' '{print $2}'`175             echo $result 176             ;;177  latest_fork_usec)178         result=`$REDIS_PA|/bin/grep -w "latest_fork_usec" | awk -F':' '{print $2}'`179             echo $result 180             ;;           181  connected_slaves)182         result=`$REDIS_PA|/bin/grep -w "connected_slaves" | awk -F':' '{print $2}'`183             echo $result 184             ;;185  master_link_status)186         result=`$REDIS_PA|/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_PA|/bin/grep -w "master_last_io_seconds_ago"|awk -F':' '{print $2}'`191             echo $result 192             ;;193  master_sync_in_progress)194         result=`$REDIS_PA|/bin/grep -w "master_sync_in_progress"|awk -F':' '{print $2}'`195             echo $result 196             ;;197  slave_priority)198         result=`$REDIS_PA|/bin/grep -w "slave_priority"|awk -F':' '{print $2}'`199             echo $result 200             ;;201 #cpu202  used_cpu_sys)203         result=`$REDIS_PA|/bin/grep -w "used_cpu_sys"|awk -F':' '{print $2}'`204             echo $result 205             ;;206  used_cpu_user)207         result=`$REDIS_PA|/bin/grep -w "used_cpu_user"|awk -F':' '{print $2}'`208             echo $result 209             ;;210  used_cpu_sys_children)211         result=`$REDIS_PA|/bin/grep -w "used_cpu_sys_children"|awk -F':' '{print $2}'`212             echo $result 213             ;;214  used_cpu_user_children)215         result=`$REDIS_PA|/bin/grep -w "used_cpu_user_children"|awk -F':' '{print $2}'`216             echo $result 217             ;;218         *)219         echo "Usage:$0{uptime_in_seconds|connected_clients|client_longest_output_list|client_biggest_input_buf|blocked_clients|used_memory|used_memory_human|used_memory_rss|used_memory_peak|used_memory_peak_human|used_memory_lua|mem_fragmentation_ratio|rdb_changes_since_last_save|rdb_bgsave_in_progress|rdb_last_save_time|rdb_last_bgsave_status|rdb_current_bgsave_time_sec|aof_enabled|aof_rewrite_scheduled|aof_last_rewrite_time_sec|aof_current_rewrite_time_sec|aof_last_bgrewrite_status|aof_current_size|aof_base_size|aof_pending_rewrite|aof_buffer_length|aof_rewrite_buffer_length|aof_pending_bio_fsync|aof_delayed_fsync|rejected_connections|instantaneous_ops_per_sec|total_connections_received|total_commands_processed|expired_keys|evicted_keys|keyspace_hits|keyspace_misses|pubsub_channels|pubsub_patterns|latest_fork_usec|connected_slaves|master_link_status|master_sync_in_progress|master_last_io_seconds_ago|connected_slaves|slave_priority|used_cpu_user|used_cpu_sys|used_cpu_sys_children|used_cpu_user_children}"220         ;;221 esac222 #db0:key223         elif [[ $# == 2 ]];then224 case $2 in225   keys)226         result=`$REDIS_PA| /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_PA| /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_PA|/bin/grep -w "db0"| /bin/grep -w "$1" | /bin/grep -w "avg_ttl" | awk -F'=|,' '{print $6}'`235             echo $result 236             ;;237           *)238      echo "Usage:$0{db0 keys|db0 expires|db0 avg_ttl}"239         ;;240 esac241 fi
redis.sh

  2、设置权限

chmod 550 redis.shchown root.zabbix redis.sh

  3、编辑agent的主配置文件

#redisUserParameter=redis.status,/usr/bin/redis-cli -h 127.0.0.1 -p 6379 ping |grep -c PONGUserParameter=redis_info[*],/etc/zabbix/scripts/redis.sh $1 $2

  4、重启服务

systemctl restart zabbix-agent.servicesystemctl enable zabbix-agent.service

 

  5、zabbix-service 导入模板

模板下载地址: 密码:msx5

  6、导入后套接到对应的主机即可!

  7、效果展示

 

转载于:https://www.cnblogs.com/huangyanqi/p/9225683.html

你可能感兴趣的文章
查询反模式 - GroupBy、HAVING的理解
查看>>
[转]动态加载javascript
查看>>
【协议】5、gossip 协议
查看>>
基于配置文件的redis的主从复制
查看>>
hasura graphql 角色访问控制
查看>>
springmvc中controller内方法跳转forward?redirect?
查看>>
C#委托,事件理解入门 (译稿)转载
查看>>
容器的end()方法
查看>>
[转] Agile Software Development 敏捷软件开发
查看>>
HDU 1007 Quoit Design (最小点对,模板题)
查看>>
Windows Phone 7 自定义事件
查看>>
Objective-c 网址中带中文解决方法
查看>>
向函数传递数组的问题
查看>>
上班族的坐姿
查看>>
ubuntu 12.04 下面安装vmware workstation 8.0.4
查看>>
[原创]FineUI秘密花园(二十三) — 树控件概述
查看>>
【Java学习笔记】如何写一个简单的Web Service
查看>>
Xcode 文档注释
查看>>
如何解决This system is not registered with RHN.
查看>>
Cocos2d-x学习笔记(两)Cocos2d-x总体框架
查看>>