Swiftorial Logo
Home
Swift Lessons
Matchups
CodeSnaps
Tutorials
Career
Resources

Built-in Metrics in Redis

Introduction

Redis is an in-memory data structure store that is widely used as a database, cache, and message broker. Monitoring Redis is crucial for ensuring its performance and reliability. Redis provides a variety of built-in metrics that can be used to monitor its behavior and performance. This tutorial will guide you through understanding and using these built-in metrics.

Accessing Redis Metrics

Redis provides an INFO command that returns information and statistics about the server. This command is the primary method for accessing Redis metrics.

To access the metrics, you can use the following command:

INFO

The INFO command returns a variety of metrics categorized into sections such as server, clients, memory, persistence, stats, replication, CPU, and cluster. We will explore some of these sections in detail.

Server Metrics

The server section provides general information about the Redis server. It includes metrics such as server version, uptime, and configuration settings.

Example output from the server section:

# Server
redis_version:6.2.5
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:6c3a3c49b8f3f945
redis_mode:standalone
os:Linux 4.15.0-142-generic x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:7.5.0
process_id:1
run_id:8fc5807b1cca3f6e6a5f4b8131b1547e8c0d1ff0
tcp_port:6379
uptime_in_seconds:123456
uptime_in_days:1
                    

Memory Metrics

The memory section provides information about Redis memory usage. It includes metrics such as total memory used, memory fragmentation ratio, and peak memory usage.

Example output from the memory section:

# Memory
used_memory:1024000
used_memory_human:1000K
used_memory_rss:2048000
used_memory_rss_human:2M
used_memory_peak:2048000
used_memory_peak_human:2M
used_memory_peak_perc:50.00%
used_memory_overhead:512000
used_memory_startup:512000
used_memory_dataset:512000
used_memory_dataset_perc:50.00%
total_system_memory:8192000
total_system_memory_human:8M
used_memory_lua:4096
used_memory_lua_human:4K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:2.00
mem_allocator:jemalloc-5.1.0
                    

Persistence Metrics

The persistence section provides information about the RDB and AOF persistence mechanisms. It includes metrics such as the last save time, save changes since the last save, and current AOF status.

Example output from the persistence section:

# Persistence
loading:0
rdb_changes_since_last_save:100
rdb_bgsave_in_progress:0
rdb_last_save_time:1627074078
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:1
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 Metrics

The stats section provides general statistics about Redis operations. It includes metrics such as total connections received, total commands processed, and number of key hits and misses.

Example output from the stats section:

# Stats
total_connections_received:1000
total_commands_processed:5000
instantaneous_ops_per_sec:10
total_net_input_bytes:2048000
total_net_output_bytes:2048000
instantaneous_input_kbps:1.00
instantaneous_output_kbps:1.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:100
evicted_keys:0
keyspace_hits:500
keyspace_misses:100
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:1000
migrate_cached_sockets:0
                    

Client Metrics

The clients section provides information about the connected clients. It includes metrics such as the number of connected clients, blocked clients, and client buffer usage.

Example output from the clients section:

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

Conclusion

Understanding and using Redis built-in metrics is essential for monitoring and optimizing the performance of your Redis server. By utilizing the INFO command, you can access a wealth of information about different aspects of your Redis instance, including server status, memory usage, persistence, and client connections. Regular monitoring of these metrics can help you identify and address potential issues before they impact your application's performance.