【问题标题】:Nagios - check if a process is listening to a portNagios - 检查进程是否正在侦听端口
【发布时间】:2026-02-20 16:25:02
【问题描述】:

是否有任何命令可以检查某个进程是否正在侦听端口。 我试过 check_tcp 但它不输出哪个进程正在监听端口 它的输出是:

TCP OK - 0.000 second response time on port 8443|time=0.000421s;;;0.000000;10.000000

【问题讨论】:

  • 不会从端口号推断出你正在检查哪个进程正在监听它吗?
  • 我想断言我的预期进程正在监听端口
  • 检查端口上的进程是否确实响应请求是更好的检查。在您的示例中,您正在检查端口 8443,因此假定它是https。在这种情况下,似乎check_http 是正确的选择。

标签: tcp port monitoring nagios


【解决方案1】:

我在 Nagios Plugins Exchange 上没有看到任何东西可以满足您的需求,所以我写了一个与 NRPE 一起使用。

https://github.com/jlyoung/nagios_check_listening_port_linux

输出如下所示:

[root@joeyoung.io ~]# python /usr/lib/nagios/plugins/nagios_check_listening_port_linux.py -n nginx -p 80
OK. nginx found listening on port 80 for the following address(es): [0.0.0.0] | 'listening_on_expected_port'=1;;;;

[root@joeyoung.io ~]# python /usr/lib/nagios/plugins/nagios_check_listening_port_linux.py -n nginx -p 9999
CRITICAL - No process named nginx could be found listening on port 9999 | 'listening_on_expected_port'=0;;;;

【讨论】: