Thursday, 27 April 2017

redis info command - key metrics to monitor

While running redis, it is very essential to continuously monitor the health of the redis instance. This helps in identifying any problems that may come up in next some days and appropriate action can be taken to avoid it.

Redis INFO command is one of the most important commands to monitor the health of redis.

The INFO command also taken an optional "section" as parameter so that it will display redis stats about that section only.
Sections can be one of the following.

  • server
  • clients
  • memory
  • persistence 
  • stats
  • replication
  • cpu
  • commandstats
  • cluster
  • keyspace
so that redis-cli -p 6379 info memory will give the information about the memory consumed by redis, while redis-cli -p 6379 info keyspace will give the information about the keys in redis, ie their number, expiring keys, average TTL etc.

Note that there are other two other sections, default and all.
redis-cli -p 6379 info will give the default fields.
redis-cli -p 6379 info all will give all the fields of all the sections.

Below is the output of info all command on one of the servers.

redis-cli info all
# Server
redis_version:3.2.8
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:f45ba3990f1644ad
redis_mode:standalone
os:Linux 3.10.0-229.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.3
process_id:3379
run_id:70c7bdd361b8a65c68612092dc559cf5412e76dd
tcp_port:6379
uptime_in_seconds:3561216
uptime_in_days:41
hz:10
lru_clock:141552
executable:/opt/redis-3.2.8/src/redis-server
config_file:/opt/redis-3.2.8/redis.conf

# Clients
connected_clients:78
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:51602584992
used_memory_human:48.06G
used_memory_rss:70614675456
used_memory_rss_human:65.77G
used_memory_peak:68906025968
used_memory_peak_human:64.17G
total_system_memory:135059263488
total_system_memory_human:125.78G
used_memory_lua:99328
used_memory_lua_human:97.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.37
mem_allocator:jemalloc-4.0.3

# Persistence
loading:0
rdb_changes_since_last_save:53293
rdb_bgsave_in_progress:0
rdb_last_save_time:1493312911
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:200
rdb_current_bgsave_time_sec:-1
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

# Stats
total_connections_received:216566
total_commands_processed:6332830614
instantaneous_ops_per_sec:419
total_net_input_bytes:968574281425
total_net_output_bytes:12348467048288
instantaneous_input_kbps:26.09
instantaneous_output_kbps:97.82
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:122577760
evicted_keys:0
keyspace_hits:870705988
keyspace_misses:2491310815
pubsub_channels:25
pubsub_patterns:2
latest_fork_usec:1093910
migrate_cached_sockets:0

# Replication
role:master
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:60615.77
used_cpu_user:69274.88
used_cpu_sys_children:42067.91
used_cpu_user_children:642783.81

# Commandstats
cmdstat_get:calls=5225350,usec=30469704,usec_per_call=5.83
cmdstat_set:calls=20476309,usec=178583650,usec_per_call=8.72
cmdstat_setex:calls=61479312,usec=434391737,usec_per_call=7.07
cmdstat_del:calls=185544,usec=52523131,usec_per_call=283.08
cmdstat_exists:calls=7918,usec=50075,usec_per_call=6.32
cmdstat_incr:calls=61425211,usec=174208343,usec_per_call=2.84
cmdstat_mget:calls=749917,usec=154888129,usec_per_call=206.54
cmdstat_rpush:calls=5,usec=127,usec_per_call=25.40
cmdstat_lpush:calls=6,usec=159,usec_per_call=26.50
cmdstat_lrange:calls=12,usec=180,usec_per_call=15.00
cmdstat_ltrim:calls=2,usec=45,usec_per_call=22.50
cmdstat_sadd:calls=35711154,usec=482334843,usec_per_call=13.51
cmdstat_srem:calls=321972,usec=4654957,usec_per_call=14.46
cmdstat_sismember:calls=640,usec=2558,usec_per_call=4.00
cmdstat_scard:calls=29948693,usec=46578706,usec_per_call=1.56
cmdstat_spop:calls=29947974,usec=418436228,usec_per_call=13.97
cmdstat_sinter:calls=1,usec=67,usec_per_call=67.00
cmdstat_smembers:calls=197297,usec=1346705,usec_per_call=6.83
cmdstat_sscan:calls=3,usec=9,usec_per_call=3.00
cmdstat_zadd:calls=816683,usec=2615273,usec_per_call=3.20
cmdstat_hset:calls=9007518,usec=118520557,usec_per_call=13.16
cmdstat_hsetnx:calls=3,usec=53,usec_per_call=17.67
cmdstat_hget:calls=416016545,usec=681666715,usec_per_call=1.64
cmdstat_hmset:calls=111728508,usec=633862773,usec_per_call=5.67
cmdstat_hmget:calls=114510880,usec=1689683861,usec_per_call=14.76
cmdstat_hincrby:calls=1,usec=18,usec_per_call=18.00
cmdstat_hdel:calls=9219162,usec=40814849,usec_per_call=4.43
cmdstat_hlen:calls=3489,usec=22029,usec_per_call=6.31
cmdstat_hstrlen:calls=3,usec=40,usec_per_call=13.33
cmdstat_hkeys:calls=1987,usec=27508499,usec_per_call=13844.24
cmdstat_hvals:calls=2507470589,usec=3927244340,usec_per_call=1.57
cmdstat_hgetall:calls=165563433,usec=954226498,usec_per_call=5.76
cmdstat_hexists:calls=474570,usec=727412,usec_per_call=1.53
cmdstat_hscan:calls=13439743,usec=17244866871,usec_per_call=1283.12
cmdstat_incrby:calls=1042,usec=28983,usec_per_call=27.81
cmdstat_randomkey:calls=2,usec=9,usec_per_call=4.50
cmdstat_expire:calls=61430368,usec=217149820,usec_per_call=3.53
cmdstat_pexpire:calls=7906572,usec=77505182,usec_per_call=9.80
cmdstat_keys:calls=1008,usec=312829814,usec_per_call=310347.06
cmdstat_scan:calls=27145,usec=116950316,usec_per_call=4308.36
cmdstat_dbsize:calls=18,usec=21,usec_per_call=1.17
cmdstat_auth:calls=4,usec=10,usec_per_call=2.50
cmdstat_ping:calls=2520082001,usec=891648507,usec_per_call=0.35
cmdstat_type:calls=11,usec=43,usec_per_call=3.91
cmdstat_info:calls=1084582,usec=108458365,usec_per_call=100.00
cmdstat_monitor:calls=41,usec=43,usec_per_call=1.05
cmdstat_role:calls=1,usec=17,usec_per_call=17.00
cmdstat_debug:calls=1,usec=254,usec_per_call=254.00
cmdstat_config:calls=1,usec=20,usec_per_call=20.00
cmdstat_subscribe:calls=491335,usec=1366115,usec_per_call=2.78
cmdstat_unsubscribe:calls=71,usec=4243,usec_per_call=59.76
cmdstat_psubscribe:calls=896,usec=5074,usec_per_call=5.66
cmdstat_punsubscribe:calls=60,usec=1181,usec_per_call=19.68
cmdstat_publish:calls=14850264,usec=194492588,usec_per_call=13.10
cmdstat_client:calls=348,usec=114949,usec_per_call=330.31
cmdstat_eval:calls=15,usec=2353,usec_per_call=156.87
cmdstat_evalsha:calls=131774371,usec=9267334162,usec_per_call=70.33
cmdstat_script:calls=108337,usec=277045,usec_per_call=2.56
cmdstat_command:calls=379,usec=376033,usec_per_call=992.17
cmdstat_pfadd:calls=1141298,usec=6958117,usec_per_call=6.10
cmdstat_pfcount:calls=6,usec=186,usec_per_call=31.00
cmdstat_host::calls=3,usec=294,usec_per_call=98.00

# Cluster
cluster_enabled:0

# Keyspace
db0:keys=757200,expires=24896,avg_ttl=3036101



It is important to understand each and every one of the metrics.
Important metrics are


  • config_file  => location of config file, important when you forget its location. :)
  • connected_clients => no of connected clients.
  • used_memory_human => used memory
  • role   => master/slave
  • used_cpu_user   => time spent by CPU in seconds in user space, like processing and returning back the data.
  • used_cpu_sys    => time spent by CPU in seconds in system space because of user calls, like while allocating memory.
  • cmdstat_<command>_calls => calls made for command
  • cmdstat_<command>_usec  => time spent in microsecs for those calls.
  • cmdstat_<command>_usec_per_call  => time spent per call in microsecs for those calls.
  • cluster_enabled => whether the redis is running as part of a cluster.
  • db0:keys   => no of keys 
  • db0:expires  => no of keys on which expiry is set.
In case you wish to create a graph to see the variation of these params, it is advisable to query the redis instances every predefined interval(like 5 mins), and push the data to a location and create graphs. We push the data from all redis instances every 5 mins, push the data to graphite and create graphs using grafana. All sorts of graphs help us feel like we are in control(are we?, aren't the machines going to take over..)
:)




No comments:

Post a Comment