Nagios: мониторинг памяти Linux

Автор: | 21/07/2015
 

nagios_logoНастройка клиента

Страница плагина https://exchange.nagios.org/directory/Addons/Active-Checks/Linux-Memory-Check/details

Недостаток – его придётся использовать через NRPE.

Примущества – он использует /proc/meminfo вместо утилиты free.

На сервере, который будет мониториться, качаем файл плагина:

# cd /tmp
# wget https://raw.github.com/hugme/Nag_checks/master/check_linux_memory
# chmod +x check_linux_memory

Опции:

# ./check_linux_memory  -h
Linux Memory Plugin for Nagios
Copyright (c) hugme ([email protected])
Version: 1.2.0
Last Modified: 10-07-2014
License: This software can be used for free unless I meet you, then you owe me lunch.

Usage: check_linux_memory -w [warning %] -c [critical %]

Options:
 -w [0-99]              = Your warning %. 20 means 20% of your memory can remain before a warning alarm. Do not use the % sign.
 -c [0-99]              = Your critical %. 10 means 10% of your memory can remain before a critical alarm. Do not use the % sign.
 -d [K,M,G,T]   = divider K=kilobytes, M=megabytes, G=gigabytes, T=terabytes
 -f             = Include cached memory as free memory when calculating your percentage free

Проверяем:

# ./check_linux_memory -w 20 -c 10
MEMORY WARNING - 11.0827% Free - Total:996.273M Active:411.777M Inactive:366.434M Buffers:134.633M Cached:583.078M |Free=11.0827;20;10;0 Active=421660;0;0;0 Inactive=375228;0;0;0 Buffers=137864;0;0;0 Cached=597072;0;0;0
# ./check_linux_memory -w 20 -c 10 -f
MEMORY OK - 83.1693% Free - Total:996.273M Active:411.508M Inactive:366.434M Buffers:134.633M Cached:583.078M |Free=83.1693;20;10;0 Active=421384;0;0;0 Inactive=375228;0;0;0 Buffers=137864;0;0;0 Cached=597072;0;0;0

Устанавливаем NRPE. РПроцесс описан в посте Nagios: мониторинг Apache Cassandra.

Копируем:

# cp check_linux_memory /usr/local/nagios/libexec/

В файл /usr/local/nagios/etc/nrpe.cfg добавляем проверку:

command[check_linux_memory]=/usr/local/nagios/libexec/check_linux_memory $ARG1$

Перезапускаем:

# service xinetd restart
Stopping xinetd:                                           [  OK  ]
Starting xinetd:                                           [  OK  ]

Настройка Nagios сервера

Устанавливаем NRPE плагин:

# yum install nagios-plugins-nrpe

Проверяем:

# /usr/local/nagios/libexec/check_nrpe -H 54.173.35.136 -c check_linux_memory
MEMORY OK - 50.666% Free - Total:7517.18M Active:2367.56M Inactive:1023.9M Buffers:226.812M Cached:2225.65M |Free=50.666;20;10;0 Active=2424380;0;0;0 Inactive=1048472;0;0;0 Buffers=232256;0;0;0 Cached=2279064;0;0;0

В файл /usr/local/nagios/etc/objects/commands.cfg добавляем новую проверку:

define command{
        command_name    check_linux_memory
        command_line    $USER1$/check_nrpe -H $HOSTNAME$ -c check_linux_memory -a '-f -w $ARG1$ -c $ARG2$'
        }

В файл /usr/local/nagios/etc/objects/services.cfg добавляем:

define service{
        use                             local-service
        hostgroup_name                  rdss-web-server
        service_description             Memory usage
        check_command                   check_linux_memory!80!50
        notifications_enabled           1
        }

Примечание: тут используется hostgroup_name, вместо обычного host_name. Группировка описана в посте Nagios: пример использования hostgroup.

Перезапускаем Nagios:

# service nagios restart
Running configuration check...
Stopping nagios:. done.
Starting nagios: done.

Готово:

nagios_install_centos_7_19