Monitoring from the Linux Command LineBy Blane Warrene
System administration can be a time consuming and difficult job, and many web developers specifically assign these duties to a staff or contract sysadmin to insure servers are running optimally.
However, not every web business is economically ready to hire adminstrative staff and handle these tasks on their own. Second, not every web designer or developer has a sysadmin background and often learn on the fly.
The command line can be intimidating, but also very convenient when duties require monitoring the performance of and controlling running processes on a server. For those who access their servers via telnet or secure shell (SSH), two command line functions are listed below which may assist you in your day to day oversight of web servers.
The top and ps commands offer valuable insight into what is running on your server, and what resources are being used.
The top tool (lots of info by typing man top on the command line) lists the top processes running and the resources they are using (CPU, RAM, space). The command has options for sorting results and is interactive, updating constantly.
The ps command provides a list of running processes along with which user initiated the process or service, resource usage and how long the process has been running.
I tend to use ps -aux, which lists all running processes by all users including those without terminals (daemons that start with the server boot for example).
The list includes a process ID (PID) that is helpful if you need to stop a runaway process or identify a service running that is not authorized.
The kill command uses the PID to stop (or kill) a process. Take note that the kill aborts a running process ungracefully, so be sure you want to halt the process or application prior to using it. Traditionally you need superuser rights to issue a kill command (or be the root user).
I have included a screen shot of the top command run on my OS X system as an example of the statistics provided. I often leave a terminal open with top running when manually monitoring a server for any extended period of time.