当前位置:网站首页>Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
Redis notes (16) - info instructions and command line tools (view memory, status, number of client connections, monitoring server, scan large keys, sampling server, execute batch commands, etc.)
2022-06-26 09:46:00 【wohu1104】
Info Command return about Redis All kinds of information and statistics of the server . By giving optional parameters section , You can make the command return only a certain part of the information .
1. Display module
server: commonlyRedisserver information , Contains the following fields :redis_versionredis_git_sha1redis_git_dirtyosarch_bits: framework (32 or 64 position )multiplexing_api: Redis The event handling mechanism usedgcc_version: compile Redis Used in GCC editionprocess_id: Server process PIDrun_id: Redis Random identifier of the server ( be used for Sentinel And clusters )tcp_port:uptime_in_seconds: since Redis Since the server started , The number of seconds passeduptime_in_days: since Redis Since the server started , Days passedlru_clock: A clock that increases in minutes , be used for LRU management
clients: Connected client information , Contains the following fields :connected_clients: Number of connected clients ( Does not include clients connected through a secondary server )client_longest_output_list: Among the currently connected clients , The longest output listclient_longest_input_buf: Among the currently connected clients , Maximum input cacheblocked_clients: Waiting for blocking command (BLPOP、BRPOP、BRPOPLPUSH) Number of clients
memory: Memory informationused_memory: from Redis Total memory allocated by allocator , In bytes (byte) In units ofused_memory_human: Return... In a human readable format Redis The total amount of memory allocatedused_memory_rss: From an operating system perspective , return Redis Total allocated memory ( Commonly known as resident set size ). The value and top 、 ps Wait for the output of the command to be consistent .used_memory_peak: Redis Peak memory consumption ( In bytes )used_memory_peak_human: Return... In a human readable format Redis Peak memory consumptionused_memory_lua: Lua The amount of memory used by the engine ( In bytes )mem_fragmentation_ratio: used_memory_rss and used_memory The ratio betweenmem_allocator: Specified at compile time , Redis Memory allocator used . It can be libc 、 jemalloc perhaps tcmalloc .
persistence: RDB and AOF Information aboutstats: General Statisticsreplication: Lord / Copy information fromcpu: CPU Calculation Statisticscommandstats: Redis Command Statisticscluster: Redis Cluster informationkeyspace: Database related statistics
2. Examples of use
info The basic syntax of the command is as follows :
redis 127.0.0.1:6379> INFO [section]
info You can get all the information at once , You can also get information by block .
# Get all the information
> info
# Get memory information
> info memory
# Get information about replication
> info replication
2.1 Get all the information
127.0.0.1:6379> info
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:b61f37314a089f19
redis_mode:standalone
os:Linux 4.4.0-117-generic x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:10.2.1
process_id:1
process_supervised:no
run_id:931c8be0f80eb6ed2e3d787d3e8c324bb536adba
tcp_port:6379
server_time_usec:1640706998540791
uptime_in_seconds:400892
uptime_in_days:4
hz:10
configured_hz:10
lru_clock:13317046
executable:/data/redis-server
config_file:
io_threads_active:0
# Clients
connected_clients:2 # This is the number of clients that are connecting
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:24
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
# Memory
used_memory:895312
used_memory_human:874.33K
used_memory_rss:8028160
used_memory_rss_human:7.66M
used_memory_peak:953480
used_memory_peak_human:931.13K
used_memory_peak_perc:93.90%
used_memory_overhead:851480
used_memory_startup:809880
used_memory_dataset:43832
used_memory_dataset_perc:51.31%
allocator_allocated:938320
allocator_active:1196032
allocator_resident:3428352
total_system_memory:2097278976
total_system_memory_human:1.95G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.27
allocator_frag_bytes:257712
allocator_rss_ratio:2.87
allocator_rss_bytes:2232320
rss_overhead_ratio:2.34
rss_overhead_bytes:4599808
mem_fragmentation_ratio:9.42
mem_fragmentation_bytes:7175616
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:41000
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0
# Persistence
loading:0
current_cow_size:0
current_cow_size_age:0
current_fork_perc:0.00
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1640505723
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:192512
aof_enabled:0
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
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0
# Stats
total_connections_received:8
total_commands_processed:84
instantaneous_ops_per_sec:0
total_net_input_bytes:2508
total_net_output_bytes:124338
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:1
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:8174
evicted_keys:0
keyspace_hits:14
keyspace_misses:6
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:315
total_forks:7
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_error_replies:14
dump_payload_sanitizations:0
total_reads_processed:123
total_writes_processed:105
io_threaded_reads_processed:0
io_threaded_writes_processed:0
# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:9361c697e9805a63571591ac1e01eb07d8fec1d1
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
# CPU
used_cpu_sys:344.796000
used_cpu_user:310.832000
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
used_cpu_sys_main_thread:344.788000
used_cpu_user_main_thread:310.832000
# Modules
# Errorstats
errorstat_ERR:count=14
# Cluster
cluster_enabled:0
# Keyspace
db0:keys=9,expires=0,avg_ttl=0
db5:keys=2,expires=0,avg_ttl=0
127.0.0.1:6379>
2.2 Get memory information
127.0.0.1:6379> info memory
# Memory
used_memory:893568
used_memory_human:872.62K
used_memory_rss:8024064
used_memory_rss_human:7.65M
used_memory_peak:953480
used_memory_peak_human:931.13K
used_memory_peak_perc:93.72%
used_memory_overhead:851480
used_memory_startup:809880
used_memory_dataset:42088
used_memory_dataset_perc:50.29%
allocator_allocated:1089360
allocator_active:1355776
allocator_resident:3588096
total_system_memory:2097278976
total_system_memory_human:1.95G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
allocator_frag_ratio:1.24
allocator_frag_bytes:266416
allocator_rss_ratio:2.65
allocator_rss_bytes:2232320
rss_overhead_ratio:2.24
rss_overhead_bytes:4435968
mem_fragmentation_ratio:9.41
mem_fragmentation_bytes:7171520
mem_not_counted_for_evict:0
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:41000
mem_aof_buffer:0
mem_allocator:jemalloc-5.1.0
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0
127.0.0.1:6379>
2.3 Query the number of instructions executed per second
> ./redis-cli info stats |grep ops
instantaneous_ops_per_sec:234
ops_per_sec: operations per second, That is, the number of operations per second .
In other words, all clients will send 234 Instructions to the server for execution .
2.4 Number of client connections
The message is Clients Block inside , Can pass info clients notice .
connected_clients:124 # This is the number of clients that are connecting
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0
This information is also useful , By looking at this number, you can determine whether there are unexpected connections . If you find something wrong with this number , Then you can use client list The command lists all the client link addresses to determine the source .
There is another important parameter to observe about the number of clients , That's it rejected_connections, It represents the number of client connections that were rejected because the maximum number of connections limit was exceeded , If that's a big number , It means that the server's maximum number of connections is set too low and needs to be adjusted maxclients Parameters .
redis-cli info stats |grep reject
rejected_connections:0
3. Command line tools
3.1 Execute a single command
By passing command parameters directly to redis-cli To execute the command and get the output .
$ redis-cli incrby a 1
(integer) 1
$ redis-cli incrby a 1
(integer) 2
If the output is large , You can also redirect output to an external file
$ redis-cli info > info.txt
$ wc -l info.txt
120 info.txt
The server that the above command points to is the default server address , If you want to point to a specific server, you can
// -n 2 Indicates using the 2 Databases , amount to select 2
$ redis-cli -h localhost -p 6379 -n 2 ping
PONG
3.2 Execute batch command
Use it directly redis-cli To execute a series of instructions in batches .
$ cat cmds.txt
set foo1 bar1
set foo2 bar2
set foo3 bar3
......
$ cat cmds.txt | redis-cli
OK
OK
OK
...
The above command is used Unix Pipeline will cat The standard output of the command is connected to the redis-cli Standard input for . In fact, you can directly use input reset to execute instructions in batches .
$ redis-cli < cmds.txt
OK
OK
OK
...
3.3 Repeat instruction
redis-cli Multiple execution of instructions is also supported , Set an interval between the execution of each instruction , This allows you to observe the output of an instruction over time .
// interval 1s, perform 5 Time , Observe qps The change of
$ redis-cli -r 5 -i 1 info | grep ops
instantaneous_ops_per_sec:43469
instantaneous_ops_per_sec:47460
instantaneous_ops_per_sec:47699
instantaneous_ops_per_sec:46434
instantaneous_ops_per_sec:47216
If the number of times is set to -1 It's repeated countless times, forever . If not provided -i Parameters , Then there is no interval , Continuous and repeated execution . Instructions can also be executed repeatedly in interactive mode , It's weird in form , Increase the number of times before the instruction
127.0.0.1:6379> 5 ping
PONG
PONG
PONG
PONG
PONG
3.4 Monitor server status
We can use --stat Parameters to monitor the status of the server in real time , interval 1s Real time output once .
$ redis-cli --stat
------- data ------ --------------------- load -------------------- - child -
keys mem clients blocked requests connections
2 6.66M 100 0 11591628 (+0) 335
2 6.66M 100 0 11653169 (+61541) 335
2 6.66M 100 0 11706550 (+53381) 335
2 6.54M 100 0 11758831 (+52281) 335
2 6.66M 100 0 11803132 (+44301) 335
2 6.66M 100 0 11854183 (+51051) 335
If the interval is too long or too short , have access to -i Parameter adjust output interval .
3.5 Scanning large KEY
Every encounter Redis Accidental carton problem , The first thing to think about is whether there is a large KEY, Big KEY The memory expansion and release of will cause the main program to jam . If you know if it's big KEY, You can write your own program scan , But it's too much .redis-cli Provides --bigkeys Parameters can be quickly swept out of memory KEY, Use -i Parameter control scan interval , Avoid the server's ops Sharp alarm .
$ ./redis-cli --bigkeys -i 0.01
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest zset found so far 'hist:aht:main:async_finish:20180425:17' with 1440 members
[00.00%] Biggest zset found so far 'hist:qps:async:authorize:20170311:27' with 2465 members
[00.00%] Biggest hash found so far 'job:counters:6ya9ypu6ckcl' with 3 fields
[00.01%] Biggest string found so far 'rt:aht:main:device_online:68:{-4}' with 4 bytes
[00.01%] Biggest zset found so far 'machine:load:20180709' with 2879 members
[00.02%] Biggest string found so far '6y6fze8kj7cy:{-7}' with 90 bytes
redis-cli The maximum length of KEY, For each object type , Refresh the highest record once and output it once immediately . It can guarantee that the output length is Top1 Of KEY, however Top2、Top3 etc. KEY There's no guarantee that it can be scanned out . The general processing method is to scan several times , Or eliminated Top1 Of KEY And then scan to see if there's another big one KEY.
3.6 Sampling server instructions
on-line Redis Server's OPS Too high , There are many business modules using this Redis, How to judge which business caused it OPS Abnormal height . In this case, the instructions of the online server can be sampled , Observe the instruction of sampling and it can be roughly analyzed OPS High proportion of business points . Use it now monitor Instructions , It will display all the instructions executed by the server in an instant . But when you use it, you should pay attention to even if you use it ctrl+c interrupt , Otherwise, too many commands on your monitor will dazzle you instantly .
$ redis-cli --host 192.168.x.x --port 6379 monitor
1539853410.458483 [0 10.100.90.62:34365] "GET" "6yax3eb6etq8:{-7}"
1539853410.459212 [0 10.100.90.61:56659] "PFADD" "growth:dau:20181018" "2klxkimass8w"
1539853410.462938 [0 10.100.90.62:20681] "GET" "6yax3eb6etq8:{-7}"
1539853410.467231 [0 10.100.90.61:40277] "PFADD" "growth:dau:20181018" "2kei0to86ps1"
1539853410.470319 [0 10.100.90.62:34365] "GET" "6yax3eb6etq8:{-7}"
1539853410.473927 [0 10.100.90.61:58128] "GET" "6yax3eb6etq8:{-7}"
1539853410.475712 [0 10.100.90.61:40277] "PFADD" "growth:dau:20181018" "2km8sqhlefpc"
1539853410.477053 [0 10.100.90.62:61292] "GET" "6yax3eb6etq8:{-7}"
3.7 Diagnosis server delay
Usually, we diagnose the delay of two machines by using Unix Of ping Instructions .Redis Delay diagnosis instructions are also provided , But the principle is not the same , It is used to diagnose the current machine and Redis Instructions between servers (PING Instructions ) Time delay , It's not just the delay of the physical network , And the current Redis Whether the main thread is busy . If you find that Unix Of ping Instruction delay is very small , and Redis The delay is very large , That means Redis The server has a weak jam when executing instructions .
$ redis-cli --host 192.168.x.x --port 6379 --latency
min: 0, max: 5, avg: 0.08 (305 samples)
Delay unit is ms.
3.8 long-range rdb Backup
Execute the following command to remote Redis Instance backup to local machine , Remote server will execute once bgsave operation , And then rdb File transfer to client .
$ ./redis-cli --host 192.168.x.x --port 6379 --rdb ./user.rdb
SYNC sent to master, writing 2501265095 bytes to './user.rdb'
Transfer finished with success.
Reference resources :
https://juejin.cn/book/6844733724618129422/section/6844733724739764231
边栏推荐
- PHP extracts TXT text to store the domain name in JSON data
- 点击遮罩层关闭弹窗
- Origin of QPM
- online trajectory generation
- halcon 光度立体
- jz2440---使用uboot烧录程序
- 3 big questions! Redis cache exceptions and handling scheme summary
- Comparison of similar PMS in QPM
- kubernetes集群部署(v1.23.5)
- [open5gs] open5gs installation configuration
猜你喜欢

The shutter tabbar listener is called twice

How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card

c语言语法基础之——指针(字符、一维数组) 学习
QPM suspended window setting information

VI summary of common commands

力扣------从数组中移除最大值和最小值

How does flutter transfer parameters to the next page when switching pages?

mysql 数据库字段查询区分大小写设置

"One week's data collection" -- combinational logic circuit

Jz2440 - - - utiliser le programme de gravure uboot
随机推荐
How to solve the problem that NVIDIA model cannot be viewed by inputting NVIDIA SMI and quickly view NVIDIA model information of computer graphics card
爬虫相关文章收藏:pyppeteer 、Burpsuite
計算領域高質量科技期刊分級目錄
节流,防抖,new函数,柯里化
测试须知——常见接口协议解析
Learning to Generalize Unseen Domains via Memory-based Multi-Source Meta-Learning for Person Re-ID
c语言语法基础之——局部变量及存储类别、全局变量及存储类别、宏定义 学习
Halcon photometric stereoscopic
集合对象复制
QPM performance monitoring components - General
Throttling, anti chattering, new function, coriolism
install opencv-contrib-dev to use aruco code
同花顺炒股软件安全性怎样?在同花顺怎么开户
异常记录-23
PHP does not allow images to be uploaded together with data (no longer uploading images before uploading data)
使用递归或while循环获取父/子层级结构的名称
Mysql database field query case sensitive setting
Teach you to use shell script to check whether the server program is running
力扣------从数组中移除最大值和最小值
"One week's data collection" -- combinational logic circuit