当系统文件句柄使用数达到上限时,系统会无法创建进程,因此,系统文件句柄使用率是系统监控中的一项比较重要的指标。要监控系统文件句柄,可读取系统文件/proc/sys/fs/file-nr。先看一下man 中对/proc/sys/fs/file-nr的说明:
This (read-only) file gives the number of files presently opened. It contains three numbers: the number of allocated file handles; the number of free file handles; and the maximum number of file handles. The kernel allocates file handles dynamically, but it doesn't free them again. If the number of allocated files is close to the max-imum, you should consider increasing the maximum. When the number of free file handles is large, you've encountered a peak in your usage of file handles and you probably don't need to increase the maximum.
从这段说明中可以知道,文件中包含3个数据,第一个表示当前系统已经分配的文件句柄数,第二个表示未被使用的文件句柄数,第三个表示系统的最大文件句柄数。因此,文件句柄使用率可通过当前已经分配的除以最大文件句柄数获得。