2

我有一个 Ubuntu 服务器,它正在收集传入的 SNMP 陷阱。目前,这些陷阱是使用 PHP 脚本处理和记录的。

文件/etc/snmp/snmptrapd.conf

traphandle default /home/svr/00-VHOSTS/nagios/scripts/snmpTrap.php

这个脚本很长,它包含许多数据库操作。通常,服务器每天会收到数千个陷阱,因此该脚本占用了过多的 CPU 时间。我的理解是这是由于每次收到陷阱时 php 脚本的启动成本都很高。

我收到了重新编写此脚本的请求,我正在考虑将此脚本作为守护程序运行。我可以创建一个 Ubuntu 守护进程。我的问题是如何使用snmptrapd.conf文件将陷阱处理程序传递给这个守护进程?

先感谢您。

4

2 回答 2

1

One suggestion is to use mysql support thats built into 5.5 of snmptrapd. That way you can use mysql as a queue and process the traps in bulk.

details of this are on the snmptrapd page: http://www.net-snmp.org/wiki/index.php/Snmptrapd

If not using mysql another option is to use a named pipe.

Do mkfifo snmptrapd.log Now change snmptrapd to write to this log. Its not a file but it looks like one. You then write another daemon to watch the named pipe for new data.

于 2015-05-09T03:04:39.393 回答
1

您可能可以使用 php-fpm / php-fcgi 来最小化 PHP 脚本的启动成本。

虽然,您可能需要编写一些包装外壳脚本来将请求从 snmptrapd 转发到 fcgi 协议。

但起初我建议检查 PHP 脚本。PHP 的启动成本并没有那么高,以至于每分钟很少的请求应该会显着增加 CPU 使用率。

于 2015-05-10T13:19:58.830 回答