Reputation:
Using the Redis info
command, I am able to get all the stats of the redis server.
I am also able to get the used memory metric.
How do I get the total memory allocated to the Redis instance, so I can get the percent of memory used?
Upvotes: 5
Views: 7915
Reputation: 1179
You could do something like:
$ ps aux -m | grep redis-server | head -n1 | awk '{printf "VSZ: %dMB, RSS: %dMB\n", $5/1024, $6/1024}'
This will display the rounded Virtual and Real memory sizes of the redis-server process in MB (to see actual numbers remove the /1024
from both parameters).
Upvotes: 8
Reputation: 17470
Redis by default gets all available memory (as much as it needs and up to all available physical memory). You can limit the amount of memory allocated to Redis though, using maxmemory
parameter in redis.conf
file.
This is an excerpt from the file:
# Don't use more memory than the specified amount of bytes.
# When the memory limit is reached Redis will try to remove keys with an
# EXPIRE set. It will try to start freeing keys that are going to expire
# in little time and preserve keys with a longer time to live.
# Redis will also try to remove objects from free lists if possible.
#
# If all this fails, Redis will start to reply with errors to commands
# that will use more memory, like SET, LPUSH, and so on, and will continue
# to reply to most read-only commands like GET.
#
# WARNING: maxmemory can be a good idea mainly if you want to use Redis as a
# 'state' server or cache, not as a real DB. When Redis is used as a real
# database the memory usage will grow over the weeks, it will be obvious if
# it is going to use too much memory in the long run, and you'll have the time
# to upgrade. With maxmemory after the limit is reached you'll start to get
# errors for write operations, and this may even lead to DB inconsistency.
#
# maxmemory <bytes>
Upvotes: 4