Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)

Monitoring System Usage

Staying aware of what's happening on your machine is a big part of system administration. The two most important things to watch on a day-to-day basis are (1) disk space and (2) load on the processor(s). Run out of disk space, and many processes stop working because they have no place to create temporary data. Let a runaway program consume too much processor time, and everything else slows down.

Monitoring disk space

Anticipating the need to add disk space before you run out is an important system-administration function.

You can view both available and used space for the entire system or for any directory in the file system.

To see a summary of disk usage for the entire system:

Tip

To see disk usage for a particular directory:

Compare with Aqua: Activity Monitor Application

Mac OS X comes with a nice GUI application called Activity Monitor, located in the /Applications/Utilities folder, which lets you monitor active processes, memory, network activity, and so on. Still, you may want to use the command-line tools for several reasons:

  • If you are logged in to the machine using ssh over the Internet and have access only to the command-line tools.

  • If you need information, such as disk usage by directory as supplied by the du command, that isn't available in Activity Monitor.

  • If you want to redirect activity or resource information to a file, send it in e-mail, or use the information in script.

  • If you are already working at the command line, in which case it may be faster to simply type top than to launch Activity Monitor.

  • If you are on another Unix system. The command-line tools for monitoring the system described in this chapter are available on virtually any Unix system you might use, while Activity Monitor is available only on Mac OS X.

To see disk usage for several directories:

Tip

Monitoring processes and load on your machine

If you have read Chapter 2, "Using the Command Line," then you already have seen two of the best tools for monitoring running processes: ps and top . (See "About Commands, Processes, and Jobs," in Chapter 2.)

Reading the man pages for ps and top yields a great deal of information about the kinds of things you can monitor on your system. Here are some highlights for the top command, which shows a wealth of information in real time. You might want to compare what we show here with the various views of system activity in the Activity Monitor application, which we mentioned earlier. For example, in Activity Monitor you may limit the display of active processes to ones associated with windows in the Aqua interface ("Windowed Processes").

More about top

Figure 11.24 is an annotated example of output from top , showing the most significant indicators of system use.

Figure 11.24. Annotated example of output from the top command.

Note how the ID of each process is displayed. If a process gets out of control, you can use the kill command (described in Chapter 2) to terminate it. You need to use sudo to kill processes you didn't start yourself. Be very careful, since you could crash the machine by killing a system process, such as the process 1 ( launchd ).

If you use top frequently, you will notice that your system spends a great deal of time doing very little. It is quite common for computers, especially desktop machines used by only a few people, to run at 90 percent idle. Most of the computing power in the world is wasted , just generating heat and performing no useful work. For ways to put those spare CPU cycles to work for a good cause, see Seti@home (http://setiathome.ssl.berkeley.edu), distributed.net (www.distributed.net), and Xgrid (www.apple.com/server/macosx/features/ xgrid .html).

Another noteworthy command is uptime , which shows the same thing as the first line of output from the w command. The top command also displays the information from uptime in its first few lines, as well as a great deal of other information.

To see system load and uptime:

vm_statTool for Monitoring Memory Usage

Another command worth knowing about is vm_stat ( virtual memory statistics ), often called vmstat on other Unix systems. vm_stat reports on several aspects of memory usage, in real time.

vm_stat is normally executed as

vm_stat 5

which gives a summary since startup and then a new line every 5 seconds. It keeps running until you press .

Interpreting the output of vm_stat takes some experience, but the pageout column is similar to the data shown by top that column should be zero most of the time. Otherwise, either your system is short of memory or something is using it up.

Категории