1.客户端配置(被监控端)
①修改zabbix_agentd.conf文件新加2行标红部分需要确定路径-a为密码
UserParameter=Redis.Status,status=
1 | 1` |
/usr/local/bin/redis-cli -h 127.0.0.1 -a 'passwd' -p 6379 ping|grep -c PONG
1 | 1` |
&&echo $status
UserParameter=Redis.Info[*],
/etc/zabbix/scripts/redisStatus.sh $1 $2
配置好后重启客户端/etc/init.d/zabbix_agentd restart
②新建脚本
/etc/zabbix/scripts/redisStatus.sh 内容如下
vim /etc/zabbix/scripts/redisStatus.sh
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
91
92 1#!/bin/bash
2REDISCLI="/usr/local/bin/redis-cli"
3HOST="127.0.0.1"
4PORT=6379
5PASS=""
6
7if [[ $# == 1 ]];then
8 case $1 in
9 version)
10 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info server | grep -w "redis_version" | awk -F':' '{print $2}'`
11 echo $result
12 ;;
13 uptime)
14 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info server | grep -w "uptime_in_seconds" | awk -F':' '{print $2}'`
15 echo $result
16 ;;
17 connected_clients)
18 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info clients | grep -w "connected_clients" | awk -F':' '{print $2}'`
19 echo $result
20 ;;
21 blocked_clients)
22 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info clients | grep -w "blocked_clients" | awk -F':' '{print $2}'`
23 echo $result
24 ;;
25 used_memory)
26 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info memory | grep -w "used_memory" | awk -F':' '{print $2}'`
27 echo $result
28 ;;
29 used_memory_rss)
30 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info memory | grep -w "used_memory_rss" | awk -F':' '{print $2}'`
31 echo $result
32 ;;
33 used_memory_peak)
34 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info memory | grep -w "used_memory_peak" | awk -F':' '{print $2}'`
35 echo $result
36 ;;
37 used_memory_lua)
38 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info memory | grep -w "used_memory_lua" | awk -F':' '{print $2}'`
39 echo $result
40 ;;
41 used_cpu_sys)
42 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info cpu | grep -w "used_cpu_sys" | awk -F':' '{print $2}'`
43 echo $result
44 ;;
45 used_cpu_user)
46 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info cpu | grep -w "used_cpu_user" | awk -F':' '{print $2}'`
47 echo $result
48 ;;
49 used_cpu_sys_children)
50 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info cpu | grep -w "used_cpu_sys_children" | awk -F':' '{print $2}'`
51 echo $result
52 ;;
53 used_cpu_user_children)
54 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info cpu | grep -w "used_cpu_user_children" | awk -F':' '{print $2}'`
55 echo $result
56 ;;
57 rdb_last_bgsave_status)
58 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info Persistence | grep -w "rdb_last_bgsave_status" | awk -F':' '{print $2}' | grep -c ok`
59 echo $result
60 ;;
61 aof_last_bgrewrite_status)
62 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info Persistence | grep -w "aof_last_bgrewrite_status" | awk -F':' '{print $2}' | grep -c ok`
63 echo $result
64 ;;
65 aof_last_write_status)
66 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info Persistence | grep -w "aof_last_write_status" | awk -F':' '{print $2}' | grep -c ok`
67 echo $result
68 ;;
69 *)
70 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"
71 ;;
72 esac
73elif [[ $# == 2 ]];then
74 case $2 in
75 keys)
76 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $2}'`
77 echo $result
78 ;;
79 expires)
80 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "keys" | awk -F'=|,' '{print $4}'`
81 echo $result
82 ;;
83 avg_ttl)
84 result=`$REDISCLI -h $HOST -a $PASS -p $PORT info | grep -w "$1" | grep -w "avg_ttl" | awk -F'=|,' '{print $6}'`
85 echo $result
86 ;;
87 *)
88 echo -e "\033[33mUsage: $0 {db0 keys|db0 expires|db0 avg_ttl}\033[0m"
89 ;;
90 esac
91fi
92
赋予能够执行的权限chmod +x /etc/zabbix/scripts/redisStatus.sh
2.服务端用get方式进行测试,得到数据表示正常