top

Sunday 21 May 2006

One of the things I’ve had to learn how to do at Tabblo is to monitor the state of our servers. I’m not the front-line guy for this, but I need to be knowledgable about it. We have a number of Linux servers running the site, so the top command is very helpful for seeing what’s going on in real-time.

top is the an info-junkie’s dream: it provides a compact dynamic presentation of a thousand factoids about what a Linux box is doing:

top - 10:14:05 up 116 days, 11:55,  2 users,  load average: 0.14, 0.16, 0.22
Tasks: 199 total,   2 running, 197 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.7% us,  0.2% sy,  0.0% ni, 98.2% id,  0.7% wa,  0.2% hi,  0.2% si
Mem:   2054140k total,  2045456k used,     8684k free,     3056k buffers
Swap:  4000144k total,  1995484k used,  2004660k free,    23052k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
15229 root      16   0  8880  864 8680 S    0  0.0   0:20.31 syslogd
14987 ned       16   0 10676 1380  10m R    0  0.1   0:00.13 top
    1 root      16   0  6012  432 5792 S    0  0.0   0:09.19 init
    2 root      RT   0     0    0    0 S    0  0.0   0:00.66 migration/0
    3 root      34  19     0    0    0 S    0  0.0   0:00.11 ksoftirqd/0
    4 root      RT   0     0    0    0 S    0  0.0   0:00.17 migration/1
    5 root      34  19     0    0    0 S    0  0.0   0:00.01 ksoftirqd/1
    6 root       5 -10     0    0    0 S    0  0.0   0:00.27 events/0
    7 root       5 -10     0    0    0 S    0  0.0   0:00.18 events/1
    8 root       6 -10     0    0    0 S    0  0.0   0:00.00 khelper
    9 root       5 -10     0    0    0 S    0  0.0   0:00.00 kacpid
   39 root       5 -10     0    0    0 S    0  0.0   0:14.50 kblockd/0
   40 root       5 -10     0    0    0 S    0  0.0   0:00.73 kblockd/1
   41 root      15   0     0    0    0 S    0  0.0   0:00.00 khubd
   54 root      15   0     0    0    0 S    0  0.0  17:09.55 kswapd1
   55 root      15   0     0    0    0 S    0  0.0  14:56.34 kswapd0
   56 root       7 -10     0    0    0 S    0  0.0   0:00.00 aio/0

Unfortunately, the help is about as compact:

$ man top
No manual entry for top
See 'man 7 undocumented' for help when manual pages are not available.
$ top --help
        top: procps version 3.2.6
usage:  top -hv | -bcisSH -d delay -n iterations [-u user | -U user] -p pid [,pid ...]

Luckily, the always-helpful O’Reilly devcenter has an actual man page: Linux command directory: top.

Comments

[gravatar]
Nathan 4:24 PM on 21 May 2006

If you like top, you should check out htop (http://htop.sourceforge.net). It's top, but more useful. You can scroll the list horizontally and vertically. Navigate with the arrow keys, and kill a process with a keystroke. It runs on all of my servers.

[gravatar]
Ben Finney 7:31 PM on 21 May 2006

I'll second the recommendation for 'htop'. Brings the navigation we expect, and a menu system that makes sense, and adds many features to the already-useful 'top'.

[gravatar]
Chris Siebenmann 8:36 PM on 21 May 2006

There's also procinfo; this doesn't show process information, but it does show a lot of system level statistics in a single display. If you're wondering why a system is slow, instead of what process is bogging it down in specific, procinfo can be a useful starting point.

[gravatar]
Chad Crabtree 12:16 PM on 22 May 2006

I was also going suggest HTOP, it's really helpful, sorting the fields amoung other things are much more understandable. TOP is good, HTOP is awesome.

[gravatar]
Chris Niekel 3:17 PM on 22 May 2006

That's weird, your top uses 10MB of shared memory? On my box the total size is only 1140, so about 10% of yours. I hope you edited your output, because that's way too much for top.

[gravatar]
James Antill 5:28 PM on 22 May 2006

What distribution are you using? Fedora certainly includes a man page, and I can _almost_ guarantee debian does too.

[gravatar]
Alan Green 6:54 PM on 22 May 2006

On Nathan and Ben's recommendation, I installed htop yesterday. Very neat - it addresses a whole bunch of UI issues, and adds little ASCII graphs. Thankyou both (and, anachronistically, Chad) for the recommendation.

[gravatar]
Mark Eichin 2:33 AM on 23 May 2006

Typing "h" into a running top gets the good stuff -- but dlocate top.1 gives me
procps: /usr/share/man/man1/top.1.gz

and also reminds me to point out slabtop - a little more subtle, but good for figuring out caching issues (although most of those are handled more directly by "upgrade to a 2.6 kernel", it's still useful to see where your memory is *really* going.
(procps top does have windowing, sorting by particular colums, almost-clever enough thread handling...)

[gravatar]
Jeremy Jones 8:50 AM on 23 May 2006

top is an OK tool. When I was doing performance analysis on Solaris a few years ago (16 CPU and 8 CPU servers, 16x running Weblogic and 8x running Oracle), I used mpstat, vmstat, and iostat quite a bit. Depending on exactly what your app does and how it does it, you may be more IO bound than CPU bound or may be running out of memory and swapping. top can give indicators of this, but iostat, mpstat, and vmstat may shed more light on things. I just discovered there are Linux implementations of these - and in the Ubuntu repository. If you want a really good book on performance stuff, the O'Reilly "marlin book" is a must have.

[gravatar]
Ned Batchelder 3:53 PM on 23 May 2006

Thanks for the pointers to all the alternatives out there. James: I probably just don't have man configured properly. I seem to be missing lots of man pages.

Add a comment:

Ignore this:
Leave this empty:
Name is required. Either email or web are required. Email won't be displayed and I won't spam you. Your web site won't be indexed by search engines.
Don't put anything here:
Leave this empty:
URLs auto-link and some tags are allowed: <a><b><i><p><br><pre>.