Ways to remotely detect memory usage in a Linux server

Source: Internet
Author: User
Tags chmod memory usage centos

The scripts we use to monitor memory are found in the Nagios market, in the GitHub warehouse of the creator.

Assuming we have Nrpe installed, we first download the script on the server we want to monitor.

Preparing a remote server

In the Debain/ubuntu:

The code is as follows:

# cd/usr/lib/nagios/plugins/

# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl

# MV Check_mem.pl Check_mem

# chmod +x Check_mem

In the Rhel/centos:

The code is as follows:

# cd/usr/lib64/nagios/plugins/(or/usr/lib/nagios/plugins/for 32-bit)

# wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl

# MV Check_mem.pl Check_mem

# chmod +x Check_mem

You can check that the output of the script is normal by manually running the following command locally. When using Nrpe, this command should detect idle memory, warn when available memory is less than 20%, and generate a severe warning when available memory is less than 10%.

The code is as follows:

#/check_mem-f-W 20-c 10

ok-34.0% (2735744 KB) free.| total=8035340kb;;;; used=5299596kb;6428272;7231806;; free=2735744kb;;;; caches=2703504kb;;;;

If you see output like the one above, it means that the command is working properly.

Now that the script is ready, we want to define the Nrpe check the Memory usage command. As described above, the command checks for available memory, alerts when the availability rate is less than 20%, and emits a severe warning when less than 10%.

The code is as follows:

# vim/etc/nagios/nrpe.cfg

For Debian/ubuntu:

The code is as follows:

Command[check_mem]=/usr/lib/nagios/plugins/check_mem-f-W 20-c 10

For Rhel/centos bit:

The code is as follows:

Command[check_mem]=/usr/lib/nagios/plugins/check_mem-f-W 20-c 10

For Rhel/centos bit:

The code is as follows:

Command[check_mem]=/usr/lib64/nagios/plugins/check_mem-f-W 20-c 10

Prepare Nagios Server

In the Nagios server, we defined a custom command for Nrpe. This command can be stored in any directory within the Nagios. To make this tutorial simple, we'll put the command definition in the/etc/nagios directory.

For Debian/ubuntu:

The code is as follows:

# vim/etc/nagios3/conf.d/nrpe_command.cfg

Define Command{

Command_name Check_nrpe

Command_line/usr/lib/nagios/plugins/check_nrpe-h ' $HOSTADDRESS $ '-C ' $ARG 1$ '

}

For Rhel/centos bit:

The code is as follows:

# vim/etc/nagios/objects/nrpe_command.cfg

Define Command{

Command_name Check_nrpe

Command_line/usr/lib/nagios/plugins/check_nrpe-h $HOSTADDRESS $-C $ARG 1$

}

For Rhel/centos bit:

The code is as follows:

# vim/etc/nagios/objects/nrpe_command.cfg

Define Command{

Command_name Check_nrpe

Command_line/usr/lib64/nagios/plugins/check_nrpe-h $HOSTADDRESS $-C $ARG 1$

}

Now we define the Nagios service check

On the Debian/ubuntu:

The code is as follows:

# vim/etc/nagios3/conf.d/nrpe_service_check.cfg

Define Service{

Use Local-service

HOST_NAME Remote-server

Service_description Check RAM

Check_command Check_nrpe!check_mem

}

On the Rhel/centos:

The code is as follows:

# vim/etc/nagios/objects/nrpe_service_check.cfg

Define Service{

Use Local-service

HOST_NAME Remote-server

Service_description Check RAM

Check_command Check_nrpe!check_mem

}

Finally, we restart the Nagios service.

On the Debian/ubuntu:

The code is as follows:

# Service NAGIOS3 Restart

On the Rhel/centos 6:

The code is as follows:

# Service Nagios Restart

On the Rhel/centos 7:

The code is as follows:

# systemctl Restart Nagios.service

Troubleshooting

Nagios should start checking memory usage on a remote server that uses Nrpe. If you have any questions, you can check the following.

Ensure that the Nrpe port is always allowed on the remote host. The default Nrpe port is TCP 5666.

You can try to manually check Nrpe operations by executing the Check_nrpe command:/usr/lib/nagios/plugins/check_nrpe-h remote-server.

You can also try to run the CHECK_MEM command:/usr/lib/nagios/plugins/check_nrpe-h remote-server–c check_mem

On the remote server, set the debug=1 in/etc/nagios/nrpe.cfg. Restart the Nrpe service and check the log files,/var/log/messages (Rhel/centos) or/var/log/syslog (Debain/ubuntu). If there are any configuration or permissions errors, the log should contain the relevant information. If nothing is reflected in the log, it is likely that the request was filtered on some ports and did not reach the remote server.

To sum up, this tutorial describes how we can debug Nrpe to monitor the memory usage of a remote server. The process simply needs to download the script, define the command, and restart the service. I hope this will be of help to you.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.