Monitoring from the Linux Command Line

By Blane Warrene
We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now

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.

Monitoring Performance

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.

We teamed up with SiteGround
To bring you the latest from the web and tried-and-true hosting, recommended for designers and developers. SitePoint Readers Get Up To 65% OFF Now
  • sethtrain

    There are also many different command line apps for Linux that give you the ability to monitor logs and rotate logs which will come in very handy.

  • cholmon

    The ‘tail’ command is also extremely useful when you’re troubleshooting a running application. ‘tail -f /path/to/logfile’ shows you the last few lines of a log file as it is being written to. this is very handy for catching errors that get thrown out by apache, bind, qmail, or anything else that logs everything it does.

  • Anonymous

    Don’t forget the “grep”, “cat” and the pipe operator “|” for superglueing commands together.

  • goodgawd

    still running bind ?!? for djbdns and erase all worries

  • Lars

    Sorry, but isn’t this article a bit shallow, even for newbies? ;-)

    That said, here are few couple more hints for beginners:

    1. ps -aux is deprecated, use ps aux

    2. Use the uptime command to see how your box is loaded, as well as how long it’s been online. man uptime for more info.

    3. Use watch to run a command at set intervals (default is 2 seconds, see man top for other options):

    watch uptime
    watch tail -5 /var/log/messages

    Hit ctrl+C to exit

    4. Use ping and traceroute to check connections to a particular host (see man again), use the host command to lookup DNS (e.g. host

    5. Use netstat -n to investigate connections to the server you’re logged into. Use it now when everything’s hopefully ok; use it again when you suspect unusual network activity.

  • meni

    Good topic to an article, but i’m afraid lars is right, the article is shallow.

    BTW to watch the tail of a continuously growing file, use:

    tail -f FILENAME

    tail -f /var/log/httpd/access_log

  • cholmon

    fellas, it’s not an article, it’s a blog entry.

  • Isak

    lsof can be handy too, do a man lsof

  • ru

    wow, thanks for the tips guys

  • Anonymous

    Can be the output of tail copied to an out file to store

  • Yes – by piping it to a file – i.e. tail /var/log/maillog > mylogfile

    You can do this with numerous commands in the shell – i.e. ps -ax > myprocesses and so on…

  • MTO

    How do you exit the tail screen once you are in it? With the -f option it’s a never ending cycle.

  • I always leave tail with a ctrl-c (killing it) if I am running it dynamically.

  • MTO

    ctrl-c doesn’t seem to do anything for me…
    I have to close the telnet window and reconnect to quiet.
    The manual doesnt seem to say how to.

  • app_1


    How to know,whether particular process is running or not on linux
    using python programme…

    Help me regarding this….

  • bgavin

    As a newbie, the article was exactly what I wanted.

    My need was a command line tool that would let me see the difference in memory consumption between runlevel3 and runlevel5.

    I searched all through the MAN pages, Googled, etc, and came up empty. This blog had exactly what I needed.