Monitor Redis Service with Nagios Monitoring tool

Redis server monitoring
Redis server monitoring

Monitor Redis Service with Nagios

In this article, we are going to learn how to monitor the Redis service with the Nagios application.

I hope you already installed the Nagios server and NRPE Service. If not or you are new who just started working on Nagios then refer to the below links which help you to clear your doubts regarding Nagios Application.

With the default, Nagios installation will provide only some basics plugins which helps to monitor the general/standard services and application on the server.

In such a case, we need to install custom plugins that help us to monitor particular services and applications on Server.

What is Redis Server?

Redis is a very important part of the caching mechanism. It helps to improve the speed of your website as well as performance.

It is our duty to keep an eye on running services properly on the server or not?

Nagios will help us with the custom plugin that can monitor the Redis Server.

Below are the important parameters we are going to monitor about Redis,

  • Check_redis_procs
  • Check_redis_mem
  • check_redis_clients

 

Configuration Of Custom Redis Plugin

check_redis.pl is the Redis Server Check plugin. It gets stats variables and allows them to set thresholds on their value or their rate of change. It can measure response time, hit rate, memory utilization, check replication sync, and much more. You can also query specific key and set thresholds on its value or max/min/avg if it’s a range. All data is returned as performance variables for graphing and the pnp4nagios template is included here.

Step 1: Install Dependency Package

To run the custom plugin of Redis you need to first install the dependency package on the server which supports the Redis plugin.

Run below command to install package,

$ cpan install Redis

Step 2: Download the Custom Redis Plugin

Now download the Redis custom plugin which is used to fetch or monitor Redis service on the host server.

Download Plugin and paste it to below path,

$ cd /usr/local/nagios/libexec

$ wget https://www.linuxgrow.com/wp-content/uploads/check_redis.pl.zip 

Step 3: Give Permissions

Give executable permission to check_redis.pl plugin using the below commands,

$ chmod +x check_redis.pl

Step 4: Configure the Redis Plugin

Sytanx of Nagios Config Definitions:

define command {
command_name check_redis_new
command_line $USER1$/check_redis.pl -H $HOSTADDRESS$ -p $ARG1$ -T $ARG2$ -R -A -M $_HOSTSYSTEM_MEMORY$ -m $ARG3$ -a $ARG4$ -w $ARG5$ -c $ARG6$ -f -P "$SERVICEPERFDATA$"
}

# Arguments and thresholds are:
# $ARG1 : Port
# $ARG2 : response time thresholds
# $ARG3 : memory utilization thresholds
# $ARG4 : additional variables to be checked
# $ARG5 : warning thresholds for those variables
# $ARG6 : critical thresholds for those variables

Now open file “nrpe.cfg” which basically resides under “/etc/nagios” directory.

Add below Redis monitoring command which helps to fetch information from the host server and send it to the Nagios server.

vim /etc/nagios/nrpe.cfg

## Monitor Redis Service

command[check_redis_procs]=/usr/local/nagios/libexec/check_redis.pl -H localhost -p 6379 -t ping

command[check_redis_mem]=/usr/local/nagios/libexec/check_redis.pl -H localhost -a --used_memory_rss=WARN:700000000,CRIT:1000000000

command[check_redis_clients]=/usr/local/nagios/libexec/check_redis.pl -H localhost -a --connected_clients=WARN:1000,CRIT:1500

save and close the file.

Below is a short description of the Redis parameters which we are monitoring here,

Check_redis_procs: This is used to monitor Redis service running status means it is running or stop. This command will continuously ping the Redis port and check it’s working or not.

Check_redis_mem: The number of bytes that Redis allocated as seen by the operating system means how much memory or ram is allocated by Redis service and how much is remaining on the server. Here in warning and critical provide value as per your requirement.

Check_redis_clients: this command will check how many no. of clients connected to the Redis server. The threshold value for warning and critical I used here 1000 and 1500 clients you can use as per your requirement.

Below is the syntax to check other Redis parameters that you can use as per the requirement,

$ /usr/local/nagios/libexec/check_redis.pl --help

Step 5: Configuration On Nagios Server

Now come to Nagios server and go to the “/usr/local/nagios/etc/” directory. Create a file under the remote host directory which I already explained in the previous article.

For more understanding refer link,

Here i have created file in “/usr/local/nagios/etc/clients” directory with name of “redis-service-hosts.cfg”.

vim /usr/local/nagios/etc/clients/redis-service-hosts.cfg

## Add below Service’s

define service{
                      use   generic-service
                      host_name   nagios_host
                      service_description   Redis Processes
                      check_command       check_nrpe!check_redis_procs
}
define service{
                      use   generic-service
                      host_name nagios_host
                      service_description  Redis Memory Usage
                      check_command      check_nrpe!check_redis_mem
}
define service{
                       use generic-service
                       host_name nagios_host
                       service_description  Redis Connected Clients
                       check_command     check_nrpe!check_redis_clients
}

Save and close the file.

Step 6: Verify Configuration & Restart Nagios Service

Give permission to created files and restart the nrpe and Nagios service.

$ chown -R nagios.nagioscmd redis-service-hosts.cfg

$ /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

$ /etc/init.d/nagios-nrpe-server restart

$ /etc/init.d/nagios restart
Redis Server Monitoring

If you’re facing any difficulties while configuring Redis service monitoring. Please do comment on your queries or problem via the comment section, till then stay tuned to Linuxgrow.com for more such valuable articles.

Thank You 🙂

Prashant

Welcome to Linuxgrow. I'm Prashant, a tech-blogger from Mumbai, India. I started Linuxgrow as a passion and to share my knowledge about technologies. Here at Linuxgrow, I write about Linux technologies, Aws Cloud, Wordpress blogging and scripting knowledge. You can read more about me at About us page. Thank You :)

2 Responses

  1. Arun says:

    Please make more videos on scripting

Leave a Reply

Your email address will not be published. Required fields are marked *

Facebook