Библиотека сайта rus-linux.net
7.1. System Resources
Being able to monitor the performance of your system is essential. If system resources become to low it can cause a lot of problems. System resources can be taken up by individual users, or by services your system may host such as email or web pages. The ability to know what is happening can help determine whether system upgrades are needed, or if some services need to be moved to another machine.
7.1.1. The top command.
|
The top portion of the report lists information such as the system time, uptime, CPU usage, physical ans swap memory usage, and number of processes. Below that is a list of the processes sorted by CPU utilization.
You can modify the output of top while
is is running. If you hit an i
, top will no longer
display idle processes. Hit i
again to see them
again. Hitting M
will sort by memory usage,
S
will sort by how long they processes have been
running, and P
will sort by CPU usage again.
In addition to viewing options, you can also modify processes
from within the top command. You can use
u
to view processes owned by a specific user,
k
to kill processes, and r
to
renice them.
For more in-depth information about processes you can look in
the /proc
filesystem. In the /proc
filesystem you will find a series of sub-directories with numeric names.
These directories are associated with the processes ids of currently
running processes. In each directory you will find a series of files
containing information about the process.
YOU MUST TAKE EXTREME CAUTION TO NOT MODIFY THESE FILES, DOING SO MAY CAUSE SYSTEM PROBLEMS!
7.1.2. The iostat command.
|
/dev/hda
. To have iostat print this
out for you, use the -x
.
|
The iostat man page contains a detailed explanation of what each of these columns mean.
7.1.3. The ps command
The ps will provide you a list of processes currently running. There is a wide variety of options that this command gives you.
UID PID PPID C STIME TTY TIME CMD root 1 0 0 Dec22 ? 00:00:03 init root 2 1 0 Dec22 ? 00:00:00 [keventd] root 3 1 0 Dec22 ? 00:00:00 [kapmd] root 4 1 0 Dec22 ? 00:00:00 [ksoftirqd_CPU0] root 9 1 0 Dec22 ? 00:00:00 [bdflush] root 5 1 0 Dec22 ? 00:00:00 [kswapd] root 6 1 0 Dec22 ? 00:00:00 [kscand/DMA] root 7 1 0 Dec22 ? 00:01:28 [kscand/Normal] root 8 1 0 Dec22 ? 00:00:00 [kscand/HighMem] root 10 1 0 Dec22 ? 00:00:00 [kupdated] root 11 1 0 Dec22 ? 00:00:00 [mdrecoveryd] root 15 1 0 Dec22 ? 00:00:01 [kjournald] root 81 1 0 Dec22 ? 00:00:00 [khubd] root 1188 1 0 Dec22 ? 00:00:00 [kjournald] root 1675 1 0 Dec22 ? 00:00:00 syslogd -m 0 root 1679 1 0 Dec22 ? 00:00:00 klogd -x rpc 1707 1 0 Dec22 ? 00:00:00 portmap root 1813 1 0 Dec22 ? 00:00:00 /usr/sbin/sshd ntp 1847 1 0 Dec22 ? 00:00:00 ntpd -U ntp root 1930 1 0 Dec22 ? 00:00:00 rpc.rquotad root 1934 1 0 Dec22 ? 00:00:00 [nfsd] root 1942 1 0 Dec22 ? 00:00:00 [lockd] root 1943 1 0 Dec22 ? 00:00:00 [rpciod] root 1949 1 0 Dec22 ? 00:00:00 rpc.mountd root 1961 1 0 Dec22 ? 00:00:00 /usr/sbin/vsftpd /etc/vsftpd/vsftpd.conf root 2057 1 0 Dec22 ? 00:00:00 /usr/bin/spamd -d -c -a root 2066 1 0 Dec22 ? 00:00:00 gpm -t ps/2 -m /dev/psaux bin 2076 1 0 Dec22 ? 00:00:00 /usr/sbin/cannaserver -syslog -u bin root 2087 1 0 Dec22 ? 00:00:00 crond daemon 2195 1 0 Dec22 ? 00:00:00 /usr/sbin/atd root 2215 1 0 Dec22 ? 00:00:11 /usr/sbin/rcd weeksa 3414 3413 0 Dec22 pts/1 00:00:00 /bin/bash weeksa 4342 3413 0 Dec22 pts/2 00:00:00 /bin/bash weeksa 19121 18668 0 12:58 pts/2 00:00:00 ps -ef |
The first column shows who owns the process. The second column is the process ID. The Third column is the parent process ID. This is the process that generated, or started, the process. The forth column is the CPU usage (in percent). The fifth column is the start time, of date if the process has been running long enough. The sixth column is the tty associated with the process, if applicable. The seventh column is the cumulitive CPU usage (total amount of CPU time is has used while running). The eighth column is the command itself.
With this information you can see exacly what is running on your system and kill run-away processes, or those that are causing problems.
7.1.4. The vmstat command
The vmstat command will provide a report showing statistics for system processes, memory, swap, I/O, and the CPU. These statistics are generated using data from the last time the command was run to the present. In the case of the command never being run, the data will be from the last reboot until the present.
|
The following was taken from the vmstat man page.
FIELD DESCRIPTIONS
Procs
r: The number of processes waiting for run time.
b: The number of processes in uninterruptable sleep.
w: The number of processes swapped out but otherwise runnable. This
field is calculated, but Linux never desperation swaps.
Memory
swpd: the amount of virtual memory used (kB).
free: the amount of idle memory (kB).
buff: the amount of memory used as buffers (kB).
Swap
si: Amount of memory swapped in from disk (kB/s).
so: Amount of memory swapped to disk (kB/s).
IO
bi: Blocks sent to a block device (blocks/s).
bo: Blocks received from a block device (blocks/s).
System
in: The number of interrupts per second, including the clock.
cs: The number of context switches per second.
CPU
These are percentages of total CPU time.
us: user time
sy: system time
id: idle time
7.1.5. The lsof command
The lsof command will print out a list of every file that is in use. Since Linux considers everythihng a file, this list can be very long. However, this command can be useful in diagnosing problems. An example of this is if you wish to unmount a filesystem, but you are being told that it is in use. You could use this command and grep for the name of the filesystem to see who is using it.
Or suppose you want to see all files in use by a particular process. To do this you would use lsof -p -processid-.
7.1.6. Finding More Utilities
To learn more about what command line tools are available, Chris Karakas has wrote a reference guide titled GNU/Linux Command-Line Tools Summary. It's a good resource for learning what tools are out there and how to do a number of tasks.