In today’s article, we’ll show you how to use Elastic to monitor Redis.
Redis is a very fast NoSQL data store. Although it is primarily used as a cache, it can be applied in a variety of forms, such as graphical representation and search. The client library is available in all major programming languages and is offered as a managed service by all top cloud service providers. For the past few years, Redis has been rated the most highly rated database by Stack Overflow developers. If you want to know more about Redis, please see the link tutorialspoint.
While the popularity of Redis may be related to its ease of use, managing Redis servers or clusters often presents many challenges. As with all other systems, problems with Redis itself or other dependencies Redis involves (for example, disk failure or low memory) can cause failure. Analyzing Redis logs can provide a variety of information about Redis server operations, including its operating life (for example, start or stop), warnings (for example, non-optimized OS configuration), persistence (for example, loading or saving a Redis database from a Redis database to disk) and errors.
Install the Redis server
MacOS
For MasOS installation, simply put:
brew update
brew install redis
Copy the code
To start Start Redis immediately, and then restart redis at login, type the following command:
sudo brew services start redis
Copy the code
We can restart the Redis service (after you have modified the configuration file) by saying
sudo brew services restart redis
Copy the code
Or, if you don’t want/need a background service, you can run:
sudo redis-server /usr/local/etc/redis.conf
Copy the code
Test whether the Redis server is running.
redis-cli ping
Copy the code
It would have been nice to say “PONG!”
The location of the Redis configuration file in/usr/local/etc/Redis. Conf,
Uninstall Redis and its files.
brew uninstall redis
rm ~/Library/LaunchAgents/homebrew.mxcl.redis.plist
Copy the code
Ubunut OS
You can type the following command ina terminal:
sudo apt-get install redis-server
Copy the code
We can start Redis Server with the following command
sudo service redis-server start
Copy the code
We can check whether the Redis service is running by using the following command:
sudo systemctl status redis
Copy the code
If I make any changes to /etc/redis/redis.conf, we can restart redis-server using the following command:
sudo systemctl restart redis.service
Copy the code
Alternatively, you can compile Redis from source code. This procedure is recommended as it ensures that you are using the latest version. However, if you are just testing Redis, this step is not required. Follow the instructions in the Redis Quick Start documentation to compile Redis from source code.
Collect redis logs
To enable Redis to collect the required log information, we need to modify the redis.conf file and configure the logfile. See the link for details. To install Elasticsearch, we need to set logfile to redis-server.log.
After we have modified redis. Conf, we need to restart Redis. Then, we find the corresponding log information under the following address (MacOS) :
liuxg-2:redis liuxg$ pwd
/usr/local/var/db/redis
liuxg-2:redis liuxg$ ls
dump.rdb redis-server.log redis.log
Copy the code
You can see redis-server.log and redis.log above
Test redis
You can use the Redis – CLI client tool to send some basic commands to the Redis server. The tool should already be installed with redis-server. To run redis-cli and execute basic commands to verify that Redis is working properly, use the following command:
$redis-cli 127.0.0.1:6379> SET x 1 OK 127.0.0.1:6379> GET x "1" 127.0.0.1:6379> DEL x (integer) 1Copy the code
The above example shows how to set the value of a key named X to 1, retrieve the value, and then remove it. When finished, press Ctrl + C to exit Redis – CLI.
Install the Elastic Stack
Install the Elasticsearch
You can install Elasticsearch by following instructions in the article “How to Install Elasticsearch on Linux, MacOS, and Windows”.
Install Kibana
You can install Kibana by following the article “How to Install Kibana in An Elastic Stack on Linux, MacOS, and Windows”.
Install Filebeat
Filebeat’s Redis module makes it very easy to transport Redis logs to Elasticsearch and visualize them in Kibana. It sets default configurations for Filebeat (including log file paths and Redis server endpoints), sets up ingesting pipes to automatically resolve Redis log structures into Elasticsearch fields, and deploys visualizations and dashboards to facilitate log analysis of data in Kibana.
We opened the Kibana interface and clicked on the Kibana icon in the upper left corner of the interface:
We click “Add Log Data” button, we can see the following interface:
Next, select our operating system and follow the instructions above to install and configure:
When we have finished executing the following command:
./filebeat modules enable redis
Copy the code
Redis configuration files can be found in the following directory:
Monitoring redis can be done without any configuration, but you can update the redis.yml file if you want to customize the Settings.
Depending on the platform, we follow the instructions above to start FileBeat.
We can view Redis logs in Kibana’s Dashboard:
Redis overview:
Install Metricbeat
We can use Metricbeat’s Redis module to periodically collect data from the Redis server.
Metricbeat consists of modules and indicator sets. The Metricbeat module defines the basic logic for collecting data from specific services such as Redis, MySQL, and so on. This module specifies details about the service, including how to connect, how often to collect metrics, and which metrics to collect.
Each module has one or more metric sets. A metric set is a part of a module that is used to capture and build data. Rather than collecting each metric standard as a separate event, the metric standard set retrieves a list of multiple related metric standards in a single request to a remote system. So, for example, the Redis module provides an information indicator set that collects information and statistics from Redis by running the INFO command and parsing the returned results.
Next, let’s install Metricbeat. Let’s open Kibana first:
Let’s click “Add Metric Data” :
Click on “Redis Metrics” :
Depending on our platform, select the appropriate installation steps. In general, we don’t need to do any special configuration. The configuration file for redis can be found in the redis. Yml file in modules.d:
Finally, we run metricBeat:
./metricbeat setup
./metricbeat -e
Copy the code
We opened Kibana:
We can see the redis indicator information:
conclusion
Redis is an important part of many enterprise architectures, and ensuring that DevOps engineers make it a priority to keep it running smoothly. The insights gained from Redis logs can improve performance (for example, by configuring to resolve warnings), but more importantly, they can help employees address critical issues that affect application stability.
When there are critical issues affecting the stability of your application, sending logs to a centralized Elastic Stack is critical to finding relevant logs quickly and getting your system back up and running with minimal disruption.