Is there any way to check the usage of the ulimits for a given user? I know that you can change ulimits for a single process when you start it up or for a single shell when running but I want to be able to "monitor" how close a user is to hitting their limits. I am planning on writing a bash
script that will report back to statsd the current usage percentage. Specifically, I want to track:
- open files (
ulimit -n
) - max user processes (
ulimit -u
) - pending signals (
ulimit -i
)
What I want out is the percentage of usage (0-100).
Best Answer
Maybe this helps for the first question:
If you know the process IDs (PID) of the specific user you can get the limits for each process with:
You can get the number of opened files for each PID with:
And then just compare the value of
Max open files
with the number of open file descriptors from the second command to get a percentage.