在 NAGIOS 上监控 Docker 服务 本地检查远程检查

问题描述

我使用 NAGIOS 作为我认为完美的监控工具。但是我想知道我们如何在 NAGIOS 的帮助下监控正在运行的服务,比如 DOCKER 或其他任何东西。

我主要是想监控在服务器的 Docker 服务中运行的容器。

例如,下面给出的是我主机服务器中的 .cfg 文件。我需要在此处进行哪些更改以监控 docker 容器?

另外,在 Nagios 的帮助下,我们还可以监控任何很酷的东西吗?

define host {
      use                          linux-server
      host_name                    testserver
      alias                        Remote Host
      address                      XXX.XXX.XXX
      register                     1
}

define service {
      host_name                       testserver
      service_description             PING
      check_command                   check_ping!100.0,20%!500.0,60%
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       testserver
      service_description             disk Usage
      check_command                   check_local_disk!20%!10%!/
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

define service {
      host_name                       testserver
      service_description             SSH Service
      check_command                   check_ssh
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

解决方法

您需要知道的第一件事是您是要在本地还是远程运行这些检查。也就是说,您运行 Nagios 的服务器是否也可以运行 Docker 检查?

本地检查

您只需要为此目的下载插件,创建一个新的命令对象(在 commands.cfg 中,请参阅文档)并将其设置为新服务对象的 check_command(示例):

define service {
      host_name                       testserver
      service_description             Docker Check
      check_command                   your_check_command!arg1!arg2 # args are optional
      max_check_attempts              2
      check_interval                  2
      retry_interval                  2
      check_period                    24x7
      check_freshness                 1
      contact_groups                  admins
      notification_interval           2
      notification_period             24x7
      notifications_enabled           1
      register                        1
}

这将在 testserver 主机下创建一个新服务,它将使用您配置的 your_check_command 命令,它接受两个可以在 命令中使用的参数 strong> 定义,如 $ARG1$$ARG2。这些参数的目的是使命令对象可重用(某些细节可能因服务而异)。

远程检查

如果检查需要在另一个节点上进行,可能是因为防火墙不允许您的 Nagios 服务器与您要检查的任何内容进行通信,那么通常使用 NRPE。它基本上是这样工作的:

┌────────────┬───────────┐    ┌─────┬─────┬──────────────┐
│            ├──────────┼│    ├─────┤     ├─────────────┼│
│testserver  │check_nrpe│┼───►│nrped│ bar │check_docker ││
│            ├──────────┼│    ├─────┤     ├─────────────┼│
└────────────┴───────────┘    └─────┴─────┴─────┼────────┘
                                                │
                                                ▼
                                          ┌─────────────┐
                                          │targeted node│
                                          └─────────────┘

所以你的 Nagios 服务器不再运行实际的插件,而是运行 check_nrpe,它调用另一个安装了 nrped(守护进程)的节点。当这个守护进程被调用时,你给它一个预配置的“命令”,它映射到 bar 上的插件。此插件运行,结果通过 NRPE 协议传回。

这只是一个总体概述,但希望它能为运行这些检查的两种主要方法提供一些想法。

是的,您可以使用 Nagios 进行很多检查。可能有一百万个插件,所以只需开始谷歌搜索或查看https://exchange.nagios.org/