记录 cronjobs 的 cpu 时间、峰值内存等
我在网络服务器上有相当多的 cronjobs,它们的运行程度各不相同。
似乎其中一些在测试数据库上需要意外数量的 CPU 周期。当然,我可以看到 16:30 的作业有哪些,但由于 cron 的数量,如果我有这样的日志,我的任务会容易得多:
Dec 19 02:13:09 /var/crons/cron1 [user cpu time used] [system cpu time used] [peak mem] ..
是否有一个实用程序可以在 crontab 之前添加,例如so:
*/6 * * * * nice -n 18 getrusage?? /usr/bin/php /var/crons/cron1 > /var/log/something
也许与getrusage(2)
有关?
I have a rather large number of cronjobs on a webserver that are ran with varying levels of niceness.
It appears that some of them are requiring an unexpected number of CPU cycles on the test database. Of course, I can see what jobs rant at 16:30, but due to the number of crons, my task would be much easier if I had a log like this:
Dec 19 02:13:09 /var/crons/cron1 [user cpu time used] [system cpu time used] [peak mem] ..
Is there a utility that I could just add before the crontab, like so:
*/6 * * * * nice -n 18 getrusage?? /usr/bin/php /var/crons/cron1 > /var/log/something
Maybe something related to getrusage(2)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
实际上,您可以从 PHP 调用
getrusage
,所以也许这个想法是可行的:不是从 crontab 调用 /usr/bin/php,而是调用一个包装器,在调用实际的 PHP 脚本之前和之后调用 getrusage:它没有经过测试,只是一个想法。
time(1)
命令对于此目的也可能有用。You can actually call
getrusage
from PHP, so maybe this idea is workable: instead of calling /usr/bin/php from the crontab, invoke a wrapper that calls getrusage before and after calling the actual PHP script:It's not tested, just an idea.
The
time(1)
command might also be useful for this purpose.