ArticleDirectory
- Memory usage
- Persistence
- Master-slave Replication
- Fork Performance
- Consistent Configuration
- Slow log
- Monitoring Service
- Data Distribution
This article is a series of articles by Simon Maynard, co-founder of bugsng.RedisUsage experience of apsaradb for redisMonitoringThe method has been systematically summarized, and there are a lot of dry goods, it is worth looking.
Original article: redis masterclass-Part 2, Monitoring
The most direct method for redis monitoring is to use the info Command provided by the system. You only need to execute the following command to obtain the status report of the redis system.
Redis-cli info
Memory usage
If the memory used by redis exceeds the available physical memory size, redis may be killed by OOM killer. To solve this problem, you can use the info commandUsed_memoryAndUsed_memory_peakMonitor, set the threshold for memory usage, and set the corresponding alarm mechanism. Of course, alarm is only a means. What is important is that you have to plan in advance. When the memory usage is too large, what should you do to clear useless cold data, or migrate redis to a more powerful machine.
Persistence
If your machine or redis itself causes redis to crash, your only life-saving straw may be the RDB file dumped by dump. Therefore, it is also important to monitor redis dump files. You canRdb_last_save_timeTo learn about the last dump data operation time, you can alsoRdb_changes_since_last_savePerform monitoring to learn how much data will be lost if a fault occurs at this time.
Master-slave Replication
If you have set the master-slave replication mode, you 'd better monitor the replication status, mainly for the info outputMaster_link_statusMonitoring. If the value is up, the synchronization is normal. If the value is down, pay attention to some other diagnostic information. For example:
Role: slavemaster_host: 192.168.1.128master _ port: 6379master_link_status: downmaster_last_io_seconds_ago:-1master_sync_in_progress: 0master_link_down_since_seconds: 1356900595
Fork Performance
When redis persistently transmits data to the disk, it performs a fork operation and uses the fork copy on write mechanism to implement the memory image at the lowest cost. However, although the memory is copy on write, the virtual memory table needs to be allocated at the moment of fork, So fork will cause the master thread to get stuck for a short time (stop all read/write operations ), this lagging time is related to the memory usage of the current redis instance. Generally, the fork operation time of redis in GB is within milliseconds. You can outputLatest_fork_usecPerform monitoring to learn how long the last fork operation has caused a lag.
Consistent Configuration
Redis supports using the config set operation to modify the configuration of the running instance, which is convenient, but it also causes a problem. The configuration that is dynamically modified using this command will not be synchronized to your configuration file. So when you restart redis for some reason, the configuration changes you made using config set will be lost, so we 'd better ensure that every time you use config set to modify the configuration, you can also change the configuration file. To prevent human errors, we recommend that you monitor the configuration and use the config GET command to obtain the current configuration at runtime. the configuration values in conf are compared. If the two sides are not correct, an alarm is triggered.
Slow log
Redis provides the slowlog command to obtain the latest slow logs. redis slow logs exist directly in the memory, so its slow log overhead is not large. In actual applications, we use the crontab task to execute the slowlog command to obtain the slow log, store the slow log to the file, and use kibana to generate a real-time performance chart for performance monitoring.
It is worth mentioning that the time for redis slow log recording only includes the time for redis to execute a command, not the time for Io, for example, the time for receiving client data and sending client data. In addition, the slow log of apsaradb for redis is slightly different from that of other databases. The occasional slow log of 100 ms in other databases may be normal, because generally, the database is executed in multiple threads concurrently, the performance of executing a command in a thread may not represent the overall performance, but for redis, it is single-threaded. Once a slow log appears, it may need to be paid attention to immediately, it is best to check the specific reason.
Monitoring Service-Sentinel
Sentinel is a tool provided by redis. It can monitor redis master-slave replication and implement automatic failover after the master node fails. During the transfer process, it can also be configured to execute a user-defined script, in which we can implement alarm notification and other functions.
-Redis live
Redis live is a more general redis monitoring solution. Its principle is to regularly execute the monitor command on redis to obtain the commands currently being executed by redis and perform statistical analysis, generate a visual analysis report on the web page.
-Redis Faina
Redis Faina is a redis Monitoring Service developed by the famous image sharing application Instagram. Its principle is similar to that of redis live.Monitor.
Data Distribution
It is difficult to find out the Data Storage Distribution in redis. For example, you want to know which type of key value occupies the most memory. The following are some tools that can help you analyze redis data sets.
-Redis-Sampler
Redis-sampler is a tool developed by the author of redis. It allows you to understand the general type, data, and distribution of data in redis.
-Redis-Audit
Redis-audit is a script through which we can know the memory usage of each type of key. It provides data such as the Access frequency of a type of key value, the expiration time, and the memory size of a type of key value, this makes it easy for us to find out which keys are not commonly used or are not used at all.
-Redis-RDB-Tools
Redis-RDB-tools and redis-audit functions are similar. The difference is that they obtain statistical data through analysis of RDB files.
From: http://blog.nosqlfan.com/html/4166.html