Monitoring Ram Usage: Nagios Setup Guide

how to monitor ram usage in nagios step by step

Nagios is a powerful monitoring tool that can be used to keep an eye on your system's performance, including CPU and memory usage. While Nagios itself doesn't include a memory plugin, there are several ways to monitor RAM usage. One popular method is to use the check_mem.pl plugin, which is compatible with Solaris, Linux, and other Unix systems. This plugin provides performance data and can be downloaded from the Nagios Exchange website or the creators' GitHub repository. Once downloaded, you can define the command to check RAM usage and set up alerts for specific thresholds, such as warning when free memory falls below 20% and critical when it drops below 10%. This can be achieved by configuring NRPE (Nagios Remote Plugin Executor) and defining custom commands in the Nagios configuration file.

Other methods for monitoring memory usage include using SNMP (Simple Network Management Protocol) to query memory statistics or employing other plugins like check_proc_mem.sh, which specifically monitors memory usage by individual processes.

shundigital

Check memory usage

To monitor RAM usage in Nagios, you can use a variety of methods and plugins, depending on your specific requirements and setup. Here is a step-by-step guide to help you get started:

Check Memory Usage with Nagios Plugins:

Nagios Plugins provide a range of options to monitor memory usage. Here are some examples:

  • Memory Free - Percentage: These checks are based on percentages and are useful when you want to be notified if the amount of free memory is running low. The linux-nrpe-agent includes a custom_check_mem plugin that triggers a warning if free memory falls below a specified threshold.
  • Memory Free - Specific Value: These checks notify you when the amount of free memory falls below a specific value. While Nagios Plugins don't include a memory plugin, you can use the custom_check_mem plugin from linux-nrpe-agent or the memory module in NPCA.
  • Memory Used - Percentage: These checks are based on memory usage percentages and alert you when the used memory exceeds a certain threshold. You can use the memory module in NSClient++ or the check_ncpa.py script in NPCA for these types of checks.
  • Memory Used - Specific Value: These checks alert you when the amount of used memory exceeds a specific value. While the check_disk plugin in Nagios Plugins doesn't support this, you can perform memory free checks or use the memory module in NSClient++.

Use External Plugins:

If you can't find a suitable plugin within Nagios, you may need to use external plugins. For example, the check_swap plugin is recommended for monitoring swap usage, and it's available by default on Debian. You can also find various plugins on the Nagios Exchange website, such as check_mem.pl, check_mem.py, and check_memcache.

Monitor Memory Usage on Linux Servers:

If you're using Nagios to monitor memory usage on Linux servers, you can follow these steps:

  • Download the Script: Start by downloading the check_mem.pl script from Nagios Exchange or the creators' GitHub repository. Save it in the appropriate directory, such as /usr/lib/nagios/plugins/ or /usr/lib64/nagios/plugins/.
  • Test the Script: Run the script manually on localhost to ensure it generates output correctly. For example, use the command ./check_mem -f -w 20 -c 10 to check free memory and set warning and critical thresholds.
  • Define the Command: Next, define the command to check RAM usage for NRPE in the nrpe.cfg file. This command will specify the path to the check_mem script and the warning and critical thresholds.
  • Configure Nagios Server: On the Nagios server, define a custom command for NRPE in a configuration file, such as nrpe_command.cfg. This command will specify the path to the check_nrpe plugin and the host address.
  • Define the Service Check: Create a service check configuration file, such as nrpe_service_check.cfg, to define the service details. Specify the host name, service description, and the check_command using the custom command defined earlier.
  • Restart Nagios: Finally, restart the Nagios service for the changes to take effect. You can do this using commands like service nagios3 restart or systemctl restart nagios.service, depending on your system.

Monitor Memory Usage on Windows Systems:

For Windows systems, you can use SNMP (Simple Network Management Protocol) to monitor memory usage. There are several plugins available for this purpose, such as check_winmem, check_win_snmp_storage.pl, and check_snmp_memory.pl. These plugins can provide detailed memory statistics, including used and free memory, cache, and swap memory usage.

Remember to refer to the official Nagios documentation and the specific plugin documentation for detailed instructions and options. The steps provided here should give you a good starting point for monitoring memory usage with Nagios.

shundigital

Check free memory

To monitor RAM usage in Nagios, you will need to download a plugin as Nagios does not include a memory plugin.

Check Memory Usage with check_mem.pl

One option is to use the check_mem.pl plugin, which is a Solaris, Linux, and other Unix-compatible Perl script. This script enables perfdata output and gathers statistics about the caches and buffers from /proc/meminfo.

To use check_mem.pl, follow these steps:

Download the script from the Nagios Exchange website or the creator's GitHub repository:

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

  • Test the script by running the following command on localhost:
  • /check_mem -f -w 20 -c 10

You should see output similar to the following:

> OK - 34.0% (2735744 kB) free.|TOTAL=8035340KB;;;; USED=5299596KB;6428272;7231806;; FREE=2735744KB;;;; CACHES=2703504KB;;;;

Define the command to check RAM usage for NRPE in the /etc/nagios/nrpe.cfg file:

Vim /etc/nagios/nrpe.cfg

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

Restart the NRPE service:

Service nrpe restart

Check Memory Usage with check_mem.py

Another option is to use the check_mem.py plugin, which is a Nagios plugin for checking available memory and swap with perfdata on a Unix machine.

To use check_mem.py:

Download the script from GitHub:

Cd /usr/lib/nagios/plugins

Wget https://github.com/rendicott/check_mem/blob/master/check_mem.py

Mv check_mem.py check_mem

Chmod +x check_mem

  • Test the script by running the following command:
  • /check_mem.py -w 20 -c 10
  • Define the command to check RAM usage for NRPE in the /etc/nagios/nrpe.cfg file:

Vim /etc/nagios/nrpe.cfg

Command[check_mem]=/usr/lib/nagios/plugins/check_mem.py -w 20 -c 10

Restart the NRPE service:

Service nrpe restart

Check Memory Usage with check_mem_ng.sh

The check_mem_ng.sh plugin is another option for checking memory usage. This plugin is compatible with Linux, including RHEL 7+, and checks buffer, cache, and used memory with performance data enabled.

To use check_mem_ng.sh:

Download the script from the Nagios Exchange website:

Cd /usr/lib/nagios/plugins

Wget https://exchange.nagios.org/directory/Plugins/System-Metrics/Memory/check_mem_ng.sh-3A-compatible-with-RHEL-7/details

Mv check_mem_ng.sh check_mem

Chmod +x check_mem

  • Test the script by running the following command:
  • /check_mem -w 20 -c 10
  • Define the command to check RAM usage for NRPE in the /etc/nagios/nrpe.cfg file:

Vim /etc/nagios/nrpe.cfg

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

Restart the NRPE service:

Service nrpe restart

shundigital

Check used memory

To monitor RAM usage in Nagios, you can use a variety of methods and plugins, depending on your specific requirements and setup. Here is a step-by-step guide to checking used memory:

Check Memory Usage with Core Plugins:

Firstly, ensure that you have Nagios installed on a central machine and NRPE on remote Linux machines. By default, core plugins should allow you to monitor CPU load, current users, processes, and more. However, memory usage monitoring may require external plugins.

Use External Plugins:

You can use external plugins like check_swap, which is available by default on Debian. Alternatively, you can use the check_memory plugin available from the Nagios Exchange website. This is a Perl script that you can copy to the same directory as your other check plugins.

Configure Permissions:

Ensure that you change the execute permissions for the check_memory plugin. The execute permission should be given to the Nagios user. For example, you can use chmod 755 or chmod 754, depending on your specific requirements.

Update NRPE Configuration:

Update the remote client's NRPE configuration file (nrpe.cfg) to include the check_memory command. For example:

Command[check_memory]=/usr/lib64/nagios/plugins/check_memory -u -w 8% -c 90%

Test the Plugin:

Before proceeding, it is essential to test the plugin to ensure it generates output properly. You can manually run the check_memory command with specific options to check free memory and set warning and critical thresholds. For example:

/check_memory -f -w 20 -c 10

If the command is working correctly, you should see output similar to the following:

OK - 34.0% (2735744 kB) free.|TOTAL=8035340KB;;;; USED=5299596KB;6428272;7231806;; FREE=2735744KB;;;; CACHES=2703504KB;;;;

Define NRPE Command:

In the NRPE configuration file (nrpe.cfg), define the command to check RAM usage. This command will include the path to the check_memory plugin and any options you want to use, such as warning and critical thresholds. For example:

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

The specific path and options may vary depending on your setup.

Configure Nagios Server:

On the Nagios server, define a custom command for NRPE. This can be done in the Nagios configuration file (nagios.cfg or nagios3.cfg). Here is an example of defining a custom command:

Define command{

Command_name check_nrpe

Command_line /usr/lib/nagios/plugins/check_nrpe -H '$HOSTADDRESS$' -c '$ARG1$'

}

Again, the specific path and options may vary depending on your setup.

Define Service Check in Nagios:

In the Nagios configuration file, define the service check for monitoring RAM usage. This will include the host_name, service_description, and the check_command. Here is an example:

Define service{

Use local-service

Host_name remote-server

Service_description Check RAM

Check_command check_nrpe!check_mem

}

Restart Nagios Service:

Finally, restart the Nagios service for the changes to take effect. You can do this using the appropriate command for your system, such as service nagios restart or systemctl restart nagios.service.

By following these steps, you should be able to effectively monitor used memory and receive alerts when certain thresholds are met.

shundigital

Check swap usage

To monitor RAM usage in Nagios, you can use various plugins and tools that are available for different operating systems. Here are the steps to monitor swap usage:

  • Check_swap plugin: This is a native Nagios plugin that checks the swap space on the local machine. It provides options to specify warning and critical thresholds in percentages or specific values. You can use this plugin by following the instructions on the Nagios website.
  • Check_snmp_memory plugin: This plugin is written in Bash and can be used to check memory and swap usage on both Windows and Linux servers using SNMP queries. It supports performance data output and allows you to set warning and critical levels for memory usage.
  • Check_mem.pl: This is a Perl script that works on Solaris, Linux, and other Unix systems. It provides statistics about memory usage, including buffers, caches, and swap memory. You can find this script on the Nagios Exchange website.
  • Check_mem.py: This is a Nagios plugin for checking available memory and swap space on Unix systems. It supports performance data output and has been tested on various Linux distributions and Unix flavors.
  • Check_memcache: This is a PHP-based plugin that requires the php-memcache extension. It returns performance data and can be integrated with your monitoring software.
  • Check_memcached: This plugin checks the statistics of a Memcached server, including object cache data.
  • Check_mem_ng.sh: This plugin is compatible with Linux distributions, including RHEL 7+. It checks buffer, cache, and used memory with performance data enabled.
  • Check_winmem: This plugin uses SNMP to check the memory usage of Windows hosts.
  • Check_win_snmp_storage.pl: This plugin checks the disk and memory usage of Windows systems using SNMP.
  • Check_solaris_swap_perf: This plugin is an update to check_solaris_swap and is used to analyse swap usage on Solaris systems. It returns performance data for tools like PNP.
  • Check_swap (by Markus Walther): This is a simple shell script that uses check_by_ssh to check free swap on a target system. It is designed for active checks and has been tested with Smoothwall firewalls.
  • Check used Swap on Linux: This is a shell script that checks the usage of swap space in a Linux system. It is intended to monitor systems that should not be swapping.
  • SNMP_remote_swap: This plugin checks the available swap space on a Linux host. It ensures that there is enough swap space available and can be used with Nagios to trigger alerts when swap usage reaches a certain threshold.

These are some of the tools and plugins available to monitor swap usage with Nagios. Depending on your specific requirements and operating system, you can choose the one that best suits your needs. Remember to refer to the official documentation and resources provided by the developers for detailed instructions on using these tools and plugins.

shundigital

Check memory over SNMP

Nagios does not include a memory plugin, but there are several options for monitoring RAM usage over SNMP.

Check_snmp_memory.pl

This plugin provides memory statistics data from NetSNMP and calculates the percentage of used data based on the amount of system/user memory. It also includes buffer/cache data, which is a problem for heavily used servers where disk cache would use all unused memory. The returned data includes:

  • Total_free - Total free memory in MB
  • Total_real - Total real memory on a system
  • Avail_real - Free real memory
  • Total_swap - Total swap
  • Avail_swap - Free swap memory
  • Shared - In use shared memory
  • Buffer - In use buffer memory
  • Cached - In use disk cache memory
  • Total - Total memory on the system, real + swap
  • Used_swap - Swap memory in use
  • %avail_real - Percent of available real memory
  • %used_real - Percent of real memory in use
  • %avail_swap - Percent of swap memory available
  • %used_swap - Percent of swap memory in use
  • User - Memory used by user (and system and kernel) processes
  • %user_real - Percent memory used for user processes in relation to total real memory
  • %cached_real - Percent of user disk cache in relation to total real memory
  • %buffer_real - Percent of buffer memory in relation to total real memory

Check_snmp_memory

This plugin checks the memory (physical and virtual) usage for Windows, Solaris, Linux servers, Cisco firewalls and MacAffee WebGateway. It provides the following features:

  • Windows: Physical and virtual memory is monitored. Threshold (and alarm) for virtual memory.
  • Linux: Physical memory, swap space and memory buffers are monitored. Threshold (and alarm) for swap space.
  • Solaris: The swapfs (virtual memory) uses a part of the physical memory and the swap space. With most memory plugins, only the swap space is monitored. This plugin monitors the virtual monitor physical memory, virtual memory and swap space.

Check_mem.pl

This is a Solaris, Linux, and other Unix-compatible Perl script that:

  • Enables perfdata output
  • On Solaris - gathers statistics about the ZFS ARC cache
  • On Linux - gathers statistics about the caches and buffers from /proc/meminfo
  • When run on HP-UX - gathers statistics about the page and swap files
  • When run on AIX - gathers statistics about the memory and swap usage

Check_mem.py

This Nagios plugin is for checking available memory and swap with perfadata on a Unix machine. It has been tested on several Unix flavors, including:

  • Linux-3.10.0-327.4.4.el7.x86_64-x86_64-with-centos-7.2.1511-Core
  • Linux-3.16.0-30-generic-x86_64-with-Ubuntu-14.04

Check_win_snmp_storage.pl

This plugin checks Windows SNMP storage for disk and memory.

Check_snmp_storage_wizard.pl

This plugin allows you to target physical memory using SNMP and regular expressions. The thresholds for the memory checks are triggered if the free memory is less than the supplied value.

Frequently asked questions

There are a variety of plugins available to monitor CPU and memory usage with Nagios. You can find a list of these on the Nagios Exchange website.

First, download the script from Nagios Exchange or GitHub. Then, define the command to check RAM usage for NRPE. This command will check free memory, warn when free memory is less than 20%, and generate a critical alarm when free memory is less than 10%. Finally, restart the Nagios service.

You can manually run the following command on localhost:

> ./check_mem -f -w 20 -c 10

If the script is working, you should see output like this:

> OK - 34.0% (2735744 kB) free.|TOTAL=8035340KB;;;; USED=5299596KB;6428272;7231806;; FREE=2735744KB;;;; CACHES=2703504KB;;;;

Written by
Reviewed by
Share this post
Print
Did this article help you?

Leave a comment