|
Monitoring Debian System Resources
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. top commandThe most common of these commands is top. The top will display a continually updating report of system resource usage.
test:~#top
12:10:49 up 8 day, 3:47, 4 users, load average: 0.34, 0.19, 0.10
75 processes: 20sleeping, 2 running, 8 zombie, 0 stopped CPU states: 5.1% user 1.1% system 0.0% nice 0.0% iowait 93.6% idle
Mem: 512216k av, 506176k used, 6540k free, 0k shrd, 21888k buff
Swap: 1044216k av, 161672k used, 882544k free 199388k cached
PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME CPU COMMAND
2330 root 15 0 161M 70 M 2132 S 4.9 14.0 1000m 0 X
2605 weeksa 15 0 8240 6340 3804 S 0.3 1.2 1:12 0 kdeinit
3413 weeksa 15 0 6668 5324 3216 R 0.3 1.0 0:20 0 kdeinit
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 it 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.
If you want to know see the more performance details of your system you need to install a package called ‘sysstat’ .This package contains the the sar, mpstat and iostat commands for Linux
Installing sysstat package in debian
#apt-get install sysstat
We will see one by one command now
sar command
The sar command collects and reports system activity information. The statistics reported by sar concern I/O transfer rates, paging activity, process-related activities, interrupts, network activity, memory and swap space utilization, CPU utilization, kernel activities and TTY statistics, among others. Both UP and SMP machines are fully supported.
test:~#sar 17:58:15 %usr %sys %wio %idle
17:58:17 43 9 1 46
17:58:19 35 17 3 45
17:58:21 36 22 20 23
17:58:23 21 17 0 63
17:58:25 85 12 3 0
Average 44 15 5 35
For more details about each field and other options check man pages for sar.Click here for manpage.
mpstat command The mpstat command reports global and per-processor statistics test:~# mpstat Linux 2.4.27-1-686-smp (test) 16/11/05 09:05:11 CPU %user %nice %system %iowait %irq %soft %idle intr/s 09:05:11 all 0.01 0.00 0.03 0.00 0.00 0.00 99.96 106.03 For more details about each fields and other options check the man pages for mpstat.Click here for manpage iostat commandThe iostat will display the current CPU load average and disk I/O information. This is a great command to monitor your disk I/O usage. test:~# iostat Linux 2.4.27-1-686-smp (test) 16/11/05 avg-cpu: %user %nice %sys %iowait %idle 0.01 0.00 0.03 0.00 99.96 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn scsi/host3/bus0/target0/lun0/disc 0.36 0.08 5.08 370598 24543512 scsi/host3/bus0/target0/lun0/part2 0.36 0.08 5.08 370572 24543512 scsi/host3/bus0/target0/lun0/part5 0.00 0.00 0.00 8 0
For 2.4 kernels the devices is names using the device's major and minor number. In this case the device listed is SCSI. To have iostat print this out for you, use the -x.
tice:~# iostat -x Linux 2.4.27-1-686-smp (test) 16/11/05 avg-cpu: %user %nice %sys %iowait %idle 0.01 0.00 0.03 0.00 99.96
Device: rrqm/s wrqm/s r/s w/s rsec/s wsec/s rkB/s wkB/s avgrq-sz avgqu-sz await svctm %util scsi/host3/bus0/target0/lun0/disc 0.01 0.28 0.00 0.35 0.08 5.08 0.04 2.54 14.37 0.00 6.49 8.85 0.32 scsi/host3/bus0/target0/lun0/part2 0.01 0.28 0.00 0.35 0.08 5.08 0.04 2.54 14.37 0.00 6.49 8.85 0.32 scsi/host3/bus0/target0/lun0/part5 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 8.00 0.00 20.00 20.00 0.00
iostat man page contains a detailed explanation of what each of these columns mean.Click here for manpage
ps commandThe ps will provide you a list of processes currently running. There is a wide variety of options that this command gives you.
A common use would be to list all processes currently running. To do this you would use the ps -ef command. (Screen output from this command is too large to include, the following is only a partial output.)
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
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.
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. # vmstat procs memory swap io system cpu
r b w swpd free buff cache si so bi bo in cs us sy id
0 0 0 181604 17000 26296 201120 0 2 8 24 149 9 61 3 36
For more details about each field and other options see vmstat man page.Click here for manpage 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.Click here for lsof manpage
Or suppose you want to see all files in use by a particular process. To do this you would use lsof -p -processid
|
|