I would like to monitor specific processes via TOP on our application servers via TOP. Currently, I have been using the following in BASH to monitor just the processes that I am interested in:
top -p $(pgrep PSAPPSRV | tr "\\n" "," | sed 's/,$//')
I had thought that this was a great solution, but there are two caveats I was overlooking:
- A single process can recycle itself, creating a new PID
- When the existing processes are under load, the server can spawn new processes to cope with the load.
Both situations mean that I can't monitor the processes for an extended amount of time if I use a 'snapshot' of the PIDs at point-in-time that I run the command above.
These processes run as a dedicated user. However, this user runs all of the processes associated with the application server. And, an application server may actually consist of 30 processes, but I'm only interested in a specific process.
Is it possible to pass new PIDs into TOP output that is already running?
Or would the best strategy be to re-call TOP at certain intervals, passing in the PIDs at that current time?