About Redis
Redis is an advanced Key-value database. It is similar to memcached, but the data can be persisted and the supported data types are rich. There are 5 types of strings, linked lists, hashes, collections, and ordered collections. Support for compute and intersection and complement sets (difference) on the server side, as well as a variety of sorting functions. So Redis can also be viewed as a data structure server. All redis data is stored in memory and then periodically asynchronously saved to disk (this is called "semi-persistent mode"), and each data change can be written to a append only file (AOF) (this is called "Full persistence mode").
Redis Monitoring
First determine if the client and server connections are normal
?
1234567 |
# 客户端和服务器连接正常,返回PONG redis> PING PONG # 客户端和服务器连接不正常(网络不正常或服务器未能正常运行),返回连接异常 redis 127.0 . 0.1: 6379 > PING Could not connect to Redis at 127.0 . 0.1: 6379: Connection refused |
The most straightforward approach to redis monitoring is to use the Info command provided by the system to obtain status reports for the Redis system by executing one of the following commands.
?
The results are returned to Server, clients, Memory, persistence, Stats, Replication, CPU, keyspace 8 parts. The purpose of effective monitoring can be achieved by extracting relevant information from the large return results of info.
Explain the meaning of each parameter first
?
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 66676869707172737475767778798081828384 |
# Server
redis_version:
2.8
.
8 # Redis 的版本
redis_git_sha
1:
00000000
redis_git_dirty:
0
redis_build_id:bf
5
d
1747
be
5380
f
redis_mode:standalone
os:Linux
2.6
.
32
-220.7
.
1
.el
6
.x
86
_
64 x
86
_
64
arch_bits:
64
multiplexing_api:epoll
gcc_version:
4.4
.
7 #gcc版本
process_id:
49324
# 当前 Redis 服务器进程id
run_id:bbd
7
b
17
efcf
108
fdde
285
d
8987
e
50392
f
6
a
38
f
48
tcp_port:
6379
uptime_in_seconds:
1739082
# 运行时间(秒)
uptime_in_days:
20 # 运行时间(天)
hz:
10
lru_clock:
1734729
config_file:/home/s/apps/RedisMulti_video_so/conf/zzz.conf
# Clients
connected_clients:
1
#连接的客户端数量
client_longest_output_list:
0
client_biggest_input_buf:
0
blocked_clients:
0
# Memory
used_memory:
821848
#Redis分配的内存总量
used_memory_human:
802.59
K
used_memory_rss:
85532672 #Redis分配的内存总量(包括内存碎片)
used_memory_peak:
178987632
used_memory_peak_human:
170.70
M #Redis所用内存的高峰值
used_memory_lua:
33792
mem_fragmentation_ratio:
104.07
#内存碎片比率
mem_allocator:tcmalloc
-2.0
# Persistence
loading:
0
rdb_changes_since_last_save:
0
#上次保存数据库之后,执行命令的次数
rdb_bgsave_in_progress:
0
#后台进行中的 save 操作的数量
rdb_last_save_time:
1410848505
#最后一次成功保存的时间点,以 UNIX 时间戳格式显示
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:
0
rdb_current_bgsave_time_sec:
-1
aof_enabled:
0
#redis是否开启了aof
aof_rewrite_in_progress:
0
aof_rewrite_scheduled:
0
aof_last_rewrite_time_sec:
-1
aof_current_rewrite_time_sec:
-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
# Stats
total_connections_received:
5705
#运行以来连接过的客户端的总数量
total_commands_processed:
204013
# 运行以来执行过的命令的总数量
instantaneous_ops_per_sec:
0
rejected_connections:
0
sync_full:
0
sync_partial_ok:
0
sync_partial_err:
0
expired_keys:
34401
#运行以来过期的 key 的数量
evicted_keys:
0
#运行以来删除过的key的数量
keyspace_hits:
2129
#命中key 的次数
keyspace_misses:
3148
#没命中key 的次数
pubsub_channels:
0
#当前使用中的频道数量
pubsub_patterns:
0
#当前使用中的模式数量
latest_fork_usec:
4391
# Replication
role:master #当前实例的角色master还是slave
connected_slaves:
0
master_repl_offset:
0
repl_backlog_active:
0
repl_backlog_size:
1048576
repl_backlog_first_byte_offset:
0
repl_backlog_histlen:
0
# CPU
used_cpu_sys:
1551.61
used_cpu_user:
1083.37
used_cpu_sys_children:
2.52
used_cpu_user_children:
16.79
# Keyspace
db
0:
keys=
3
,expires=
0
,avg_ttl=
0
#各个数据库的 key 的数量,以及带有生存期的 key 的数量
|
Memory usage
If the memory used by Redis exceeds the available physical memory size, Redis is likely to be killed. For this, you can use the info command to monitor used_memory and Used_memory_peak, set thresholds for the amount of memory used, and set the appropriate alarm mechanism. Of course, the alarm is only a means, the important thing is that you have to plan ahead, when the memory usage is too large, you should do something to clean up some useless cold data, or to move Redis to a more powerful machine.
Persistence of
If Redis crashes because of problems with your machine or redis itself, your only lifeline might be the Rdb file that you dump, so it's important to monitor the Redis dump file. The rdb_last_save_time can be monitored to understand the time of the most recent dump data operation, and the rdb_changes_since_last_save can be monitored to get how much data is lost (that is, changed) if a failure occurs.
Keys
Get the number of keys in each database by getting the results in Keyspace
QPS
That is, the number of commands executed per minute, namely: (TOTAL_COMMANDS_PROCESSED2-TOTAL_COMMANDS_PROCESSED1)/span, in order to get QPS in real time, you can set the script to run in the background, recording the last few minutes of Total_ Commands_processed. When calculating a QPS, use past information and current information to derive a QPS estimate.
Reference
What each parameter means in the Redis info command
Redis Monitoring Solutions