Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to remotely detect the memory usage in the Linux server

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the relevant knowledge of "how to remotely detect the memory footprint in the Linux server". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Prepare the remote server

In 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 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 free memory, issue a warning when the available memory is less than 20%, and generate a serious warning when the 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 need to define the command for NRPE to check memory usage. As mentioned above, the command checks the available memory, issues an alarm when the availability is less than 20%, and issues a serious warning when it is less than 10%.

The code is as follows:

# vim / etc/nagios/nrpe.cfg

For Debian/Ubuntu:

The code is as follows:

Commanded [check _ mem] = / usr/lib/nagios/plugins/check_mem-f-w 20-c 10

For RHEL/CentOS 32 bit:

The code is as follows:

Commanded [check _ mem] = / usr/lib/nagios/plugins/check_mem-f-w 20-c 10

For RHEL/CentOS 64 bit:

The code is as follows:

Commanded [check _ mem] = / usr/lib64/nagios/plugins/check_mem-f-w 20-c 10

Prepare the Nagios server

In the Nagios server, we define a custom command for NRPE. This command can be stored in any directory within Nagios. To make this tutorial simple, we will 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'$ARG1 $'

}

For RHEL/CentOS 32 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 $ARG1 $

}

For RHEL/CentOS 64 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 $ARG1 $

}

Now let's define the service check for Nagios

On 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 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 Debian/Ubuntu:

The code is as follows:

# service nagios3 restart

On RHEL/CentOS 6:

The code is as follows:

# service nagios restart

On RHEL/CentOS 7:

The code is as follows:

# systemctl restart nagios.service

Troubleshooting

Nagios should start checking memory usage on remote servers that use NRPE. If you have any questions, you can check the following.

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

You can try to check the NRPE operation manually by issuing the check_nrpe command: / usr/lib/nagios/plugins/check_nrpe-H remote-server.

You can also try running the check_mem command: / usr/lib/nagios/plugins/check_nrpe-H remote-server-c check_mem

On the remote server, set 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 permission errors, the log should contain relevant information. If nothing is reflected in the log, it is likely that the request did not reach the remote server because the request was filtered on some ports.

This is the end of the content of "how to remotely detect the memory footprint in the Linux server". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report