监控打开文件限制等

moi*_*din 6 linux monitoring limits

我们最近在一些服务上达到了最大打开文件限制。还有很多其他限制。有没有办法监控进程与这些限制的接近程度,以便我们可以在需要提高限制或修复根本原因时收到警报?同样,是否可以查看这些事件的日志,以便我们知道何时发生崩溃是因为达到了这些限制之一?

小智 7

假设一个linux服务器。

查看全局最大打开文件:

cat /proc/sys/fs/file-max
Run Code Online (Sandbox Code Playgroud)

查看全局当前打开的文件:

cat /proc/sys/fs/file-nr
Run Code Online (Sandbox Code Playgroud)

更改全局最大打开文件:

sysctl -w fs.file-max=1000000 or edit sysctl.conf
Run Code Online (Sandbox Code Playgroud)

查看当前用户的限制:

ulimit -Hn   (hard limit)
ulimit -Sn   (soft limit)
Run Code Online (Sandbox Code Playgroud)

更改用户限制:例如,编辑/etc/security/limit.conf以设置网络服务器的限制

apache2 soft nofile 4096
apache2 hard nofile 10000
Run Code Online (Sandbox Code Playgroud)

您可以通过脚本/proc并为您提供一些统计信息:

for pid in $(pgrep apache2); do ls /proc/$pid/fd | wc -l; done
Run Code Online (Sandbox Code Playgroud)


Den*_*ker 5

是的你可以。/proc/<pid>/fd列出所有打开的文件描述符。内存使用情况可以在/proc/<pid>/{maps,smaps}. 只需浏览/proc/<pid>一下您不理解的谷歌文件:)