Get Rewarded! We will reward you with up to €50 credit on your account for every tutorial that you write and we publish!

Настройка мониторинга на управляемом сервере

profile picture
Author
Alexander Knerlein
Published
2019-03-29
Time to read
4 minutes reading time

Введение

В этом руководстве мы настроим простой мониторинг на управляемом сервере основанном на Monitoring Plugins (также известными как Nagios Plugins).

Требования

  • Управляемый сервер с включенным SSH доступом
  • Hetzner Development Package (hos-dev) -> необходимо запросить в поддержке
  • Установленный локально Nagios или Icinga сервер

Шаг 1 - Установка Monitoring Plugins

Войдите в оболочку на управляемом сервере и выполните указанные ниже команды в своей домашней директории.

wget https://www.monitoring-plugins.org/download/monitoring-plugins-2.4.0.tar.gz
tar xzvf monitoring-plugins-2.4.0.tar.gz
cd monitoring-plugins-2.4.0
./configure --prefix=/usr/home/holu/monitoring-plugins
make -j $(($(grep ^cpu\ cores /proc/cpuinfo | uniq | sed s/[^0-9]//g)+1))
make install

(Опционально) Выполнив команды ниже вы можете установить удобный сторонний плагин check-linux-memory.

cd ../monitoring-plugins/libexec
wget https://raw.githubusercontent.com/hugme/Nag_checks/master/check_linux_memory
chmod 755 check_linux_memory

Шаг 2 - Подготовка локального сервера мониторинга для check-by-ssh

Войдите в локальный Nagios или Icinga сервер.

Нижеуказанные шаги должны работать для большинства версий Nagios и Icinga.

sudo su - nagios -s /bin/bash
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
ssh-copy-id -i ~/.ssh/id_ed25519.pub holu@dediX.your-server.de -p222

Шаг 3 - Настройка проверки на локальном сервере мониторинга

Для корректной настройки сервера мониторинга, пожалуйста обратитесь к соответствующей документации разработчика.

Пример проверки нагрузки:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_load -w 10,8,6 -c 20,15,10"
OK - load average: 0.03, 0.08, 0.08|load1=0.030;10.000;20.000;0; load5=0.080;8.000;15.000;0; load15=0.080;6.000;10.000;0;

Пример проверки файла подкачки:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_swap -w 60% -c 20%"
SWAP OK - 99% free (4019 MB out of 4095 MB) |swap=4019MB;2457;819;0;4095

Пример проверки диска:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_disk -w 10% -c 5% -p /usr"
DISK OK - free space: /usr 284513 MB (90% inode=95%);| /usr=28210MB;296519;312992;0;329466

Пример проверки датчиков:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_sensors -v"
SENSORS OK
acpitz-virtual-0 Adapter: Virtual device temp1: +27.8 C (crit = +105.0 C) temp2: +29.8 C (crit = +105.0 C) coretemp-isa-0000 Adapter: ISA adapter Physical id 0: +33.0 C (high = +80.0 C, crit = +100.0 C) Core 0: +33.0 C (high = +80.0 C, crit = +100.0 C) Core 1: +32.0 C (high = +80.0 C, crit = +100.0 C) Core 2: +31.0 C (high = +80.0 C, crit = +100.0 C) Core 3: +28.0 C (high = +80.0 C, crit = +100.0 C)

Пример проверки процессов:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_procs -a \"/usr/sbin/apache2 -k start\" -c 1:"
PROCS OK: 5 processes with args '/usr/sbin/apache2 -k start' | procs=5;;1:;0;

Обратите внимание: Если вы хотите видеть все процессы с помощью with check_procs, запросите это в поддержке.

Пример проверки памяти:

./check_by_ssh -H dediX.your-server.de -p 222 -l holu -C "/usr/home/holu/monitoring-plugins/libexec/check_linux_memory -w 20 -c 10"
MEMORY OK - 57.55% Free - Total:5846.2M Active:3192.04M Inactive:974.828M Buffers:828.434M Cached:1898.42M |Free=57.55;20;10;0 Active=3268648;0;0;0 Inactive=998224;0;0;0 Buffers=848316;0;0;0 Cached=1943984;0;0;0

Заключение

Теперь вы можете мониторить различные аспекты вашего управляемого сервера.

License: MIT
Want to contribute?

Get Rewarded: Get up to €50 in credit! Be a part of the community and contribute. Do it for the money. Do it for the bragging rights. And do it to teach others!

Report Issue
Try Hetzner Cloud

Get €20/$20 free credit!

Valid until: 31 December 2025 Valid for: 3 months and only for new customers
Get started
Want to contribute?

Get Rewarded: Get up to €50 credit on your account for every tutorial you write and we publish!

Find out more