Monitoring from the Linux Command Line

By | | Open Source

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.

Written By:

Blane Warrene

Blane is a writer and researcher focusing on Apple and Open Source technologies. Prior to this, he helped found a commercial software and consulting venture, and worked in the financial services sector as a director of technology and in varying technical roles. Blane maintains Open Sourcery: SitePoint's Open Source Blog.

Website
>> More Posts By Blane Warrene

 

{ 16 comments }

bgavin August 7, 2007 at 8:12 am

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.

app_1 May 21, 2007 at 3:27 pm

Hi,

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

Help me regarding this….

MTO November 12, 2004 at 11:02 am

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.

bwarrene November 11, 2004 at 11:42 am

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

MTO November 10, 2004 at 2:40 pm

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

bwarrene September 29, 2004 at 11:41 pm

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…

Anonymous September 29, 2004 at 8:16 am

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

ru August 6, 2004 at 2:39 am

wow, thanks for the tips guys

Isak June 22, 2004 at 4:44 am

lsof can be handy too, do a man lsof

cholmon June 21, 2004 at 6:52 pm

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

meni June 21, 2004 at 11:38 am

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

e.g.
tail -f /var/log/httpd/access_log

Lars June 21, 2004 at 2:44 am

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 http://www.google.com).

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.

goodgawd June 21, 2004 at 1:08 am

still running bind ?!? cr.yp.to for djbdns and erase all worries

Anonymous June 20, 2004 at 9:06 pm

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

cholmon June 18, 2004 at 4:12 pm

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.

sethtrain June 18, 2004 at 1:38 pm

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.

Comments on this entry are closed.