If your Linux system is being used as a multiuser computer, sharing the processing power of that computer can be a major issue. Likewise, any time you can stop a runaway process or reduce the overhead of an unnecessary program running, your Linux server can do a better job serving files, Web pages, or e-mail to the people that rely on it.
Utilities are included with Linux that can help you monitor the performance of your Linux system. The kinds of features you want to monitor in Linux include CPU usage, memory usage (RAM and swap space), and overall load on the system. The following sections describe tools for monitoring Linux.
If you like visual representations of your system use, the System Monitor provides a great way to see how much your system is being used. To open the System Monitor from the red hat menu, select System Tools ® System Monitor. Figure 10-5 shows the System Monitor window with the Resource Monitor tab selected.
Figure 10-5: System Monitor graphically displays your system’s CPU and memory usage.
On the Resource Monitor window, lines scroll from right to left, indicating the percentage of your CPU being used as it rises and falls. You can also see how much of your total memory (RAM) is being used at the moment (and over time), as well as the amount of swap space being used. Scroll the devices at the bottom of the window to see the space being consumed on each of your hard disk partitions.
Click the Process Listing tab to see a listing of processes that are running currently. Click the columns in that tab to sort processes by name, user (who launched the process), memory use, percentage of CPU being consumed by the process, and process ID.
The example in Figure 10-5 shows a computer that is running with only 128MB of RAM. The Memory Used is running near the maximum, indicating the likely occurrence of performance problems as RAM fills up and data has to be moved to swap space. The CPU used is only about 19 percent, which indicates that the CPU is keeping up with the demand.
Start the top utility in a Terminal window, and it displays the top CPU consuming processes on your computer. Every five seconds, top will determine which processes are consuming the most CPU time and display them in descending order on your screen.
By adding the -S option to top, you can have the display show you the cumulative CPU time that the process, as well as any child processes that may already have exited, has spent. If you want to change how often the screen is updated, you can add the -d secs option, where secs is replaced by the number of seconds between updates.
By default, processes are sorted by CPU usage. You can sort processes numerically by PID (press N), by age (press A), by resident memory usage (press M), by time (press T), or back to CPU usage (press P). Figure 10-6 shows an example of top running in a Terminal window.
Figure 10-6: Running processes appear in CPU usage order by default in the top window.
To effectively use a laptop computer, you need to be able to monitor and manage the laptop’s power usage. Using tools provided in Fedora, you can configure your laptop to:
Monitor the battery level.
Notify you when the battery is low.
Notify you when the battery is fully charged.
Show when the laptop is plugged in.
Suspend the current session.
Fedora offers two facilities that do power management: APM and ACPI.
Advanced Power Management (APM) — APM can be used to monitor the battery of your notebook and notify user-level programs to tell you when your battery is low. It can also be used to place your laptop into suspend mode.
Advanced Configuration and Power Interface (ACPI) — Besides monitoring power features on your laptop, ACPI can also do thermal control, motherboard configuration, and change power states.
Many older laptops do not include support for ACPI in the BIOS, so you must use APM to monitor and manage your batteries. For some newer laptops, ACPI may be required. In general, ACPI offers a more complete feature set for power management, but APM has more user-level support today.
To check whether ACPI or APM are supported on your Fedora system, you can use the dmesg command after a reboot. For example, type:
# dmesg | less
Page through the output looking for lines beginning with ACPI or amp. On a computer where APM wasn’t working, I saw the message "amp: BIOS not found." When ACPI wasn’t working, I saw the message "ACPI: System description tables not found."
The following procedure was performed on a laptop that used APM to manage power events. It describes how to use the Battery Charge Monitor applet on the desktop to monitor your battery and the apm command to place your laptop in suspend mode.
If it seems that ACPI is interfering with the proper operation of your laptop, you can turn off ACPI when you boot your computer. Add acpi=off to the end of the kernel line (from the GRUB boot screen or the /boot/grub/grub.conf file) to turn off ACPI.
If you are using the GNOME desktop, you can add a Battery Status Monitor to your panel to keep track of the power levels of your battery. The following procedure steps you through adding the monitor to your panel and configuring it to behave as you like:
Right-click the GNOME panel; then select Add to Panel ® Battery Charge Monitor. When the Battery Charge Monitor applet appears on the panel, you can stop here if you like. The applet will:
Include a battery icon that appears green (with the battery above a 40% charge), yellow (25%-40%), orange (15%-25%) or red (under 15%).
Show a power cord if the laptop is plugged in.
Notify you with at pop-up window when the battery charge is low.
Notify you with a pop-up window when the battery is fully charged.
Display the percent charged and whether the battery is currently charging when you move the mouse pointer over the applet icon.
Continue with the following steps if you want to change that behavior.
Right-click the Battery Charge monitor applet, then select Preferences. Figure 10-7 shows the Battery Charge Monitor Preferences window and the applet in the panel.
Figure 10-7: View battery status and change preferences with the Battery Charge Monitor.
Change any of the following values related to your battery monitor:
Battery color levels — You can change the levels at which the battery icon changes from green, yellow, orange, and red.
Warnings — Select whether or not you want to be notified (with a pop-up) when the battery charge is low or fully charged. You can also select to have the laptop beep if either case is true.
Suspend command — Add a command to put the laptop in suspend mode. (Try the apm -s command as described in the next section.) With a Suspend command set, you can right-click the icon and choose Suspend Computer to suspend your laptop.
Appearance — Select the Appearance tab. From there, you can choose which icons appear on the applet (battery, power cord, or percent charged). You can also change whether the progress bar on the battery moves up or down as power empties.
If, when you try to add the Battery Charge Monitor icon to the panel, a pop-up window tells you that the operation fails, it may be that the apmd daemon isn’t running. You can try starting the apmd service (as root user; type service apmd start). If, however, APM is shown as not supported in your dmesg file, you can try turning on APM support in your laptop's BIOS.
The apm command lets you view information about your computer’s power management and put the computer in suspend mode (if it is supported on your laptop). Here are some examples of using the apm command:
# apm -m
Using the -m option, the apm command displays the number of minutes of battery life remaining (if that information is available). It may also give you information about the status of how the battery is charging and whether or not the laptop is currently plugged in.
# apm -s
The -s option of apm causes the laptop to enter suspend mode. You can start up the laptop again, in most cases, by pressing a key on the keyboard.