Transferred from: http://www.cnblogs.com/itech/archive/2011/06/08/2075145.html
First, uptime
The uptime command is used to see how long the server has been running and how many users are logged in to quickly learn about the load on the server.
The output of the uptime contains a load of average, which shows the last 1, 5, and 15-minute loads. Its value represents the number of processes waiting to be processed by the CPU, and if the CPU does not have time to process these processes, the load average value will rise;
The best value for load average is 1, which means that each process can be processed immediately and no CPU cycles is lost. For a single-CPU machine, 1 or 2 is an acceptable value, and in a multi-CPU system This value should be divided by the number of physical CPUs, assuming that the number of CPUs is 4, and load average is 8 or 10, then the result is at 2多 points.
You can also use the Uptime command to determine network performance. For example, a network application performance is very low, by running uptime to see if the server load is very high, if not, then the problem should be caused by the network.
You can also view/proc/loadavg and/proc/uptime two files for relevant information.
The following is a running instance of uptime:
Second, Top (CPU)
The top command shows the actual CPU usage, which by default shows the CPU-intensive task information on the server and refreshes every 5 seconds. You can categorize them in a number of ways, including PID, time, and memory usage.
The following is an introduction to the output values:
PID: Process identification
User name of the process owner
PR: Priority of the process
Ni:nice level
RES: The amount of physical memory used by the process
SHR: The number of shared memory for this process and other processes
Code: Size of Codes
Data: Database + stack size
S: Status of the process: s= hibernation, r= running state, t= stop state, d= interrupt sleep state, z= zombie State
%CPU: Shared CPU usage
%MEM; shared physical memory
Time: How long the process consumes CPU
Command: To start a task (including parameters)
Process priority and nice level
The process priority is a parameter that determines the process is prioritized by the CPU, and the kernel adjusts the value as needed. The nice value is a restriction on priority. The value of the process priority cannot be less than the nice value. (The lower the Nice value the higher the priority)
Process priority cannot be changed manually, but only by changing the nice value to indirectly adjust the process priority level. If a process is running too slowly, you can allocate more CPU resources to it by specifying a lower nice value. Of course, this means that some other processes will be allocated less CPU resources and run slower. Linux supports a nice value with a range of 19 (low priority) to 20 (high priority), and the default value is 0. If you need to change the nice value of a process to a negative number (high priority), you must log on to the root user using the SU command. Here are some examples of commands to adjust nice values.
Start program xyz with nice value-5
#nice –n-5 XYZ
Change the nice value of a program that is already running
#renice level PID
Change the nice value of the process with PID 2500 to 10
#renice 10 2500
Zombie Process
When a process is finished, it usually takes some time to complete all tasks (such as closing open files) before it ends, and in a very short time, the status of this process is zombie state. After the process has completed all the shutdown tasks, it submits the information it closed to the parent process. In some cases, a zombie process cannot shut itself down, when the process state is Z (zombie). You cannot use the KILL command to kill a zombie process because it is already marked as "dead". If you can't get rid of a zombie process, you can kill its parent process, and the zombie process disappears. However, if the parent process is the INIT process, you cannot kill the init process because INIT is an important system process, in which case you can only get rid of the zombie process by restarting the server at once. You also have to analyze why applications can cause zombies.
Top Run Example:
Third, free (memory)
The free command displays all memory usage for the system, including idle memory, used memory, and swap memory space. The free command display also includes information about the caches and buffers used by the kernel. When using the free command, it is necessary to remember the memory structure of Linux and the management methods of virtual memory, such as the limit of the amount of idle memory, and the use of swap space does not mark the occurrence of a memory bottleneck.
You can also use Cat/proc/meminfo to see how memory is being used.
Free Run Example:
[[email protected]/tmp]# free
Total used free shared buffers Cached
mem:4149156 4130412 18744 0 13220 2720160
-/+ buffers/cache:1397032 2752124
swap:6289408 144 6289264 Line 1th
Total Memory: 4149156
Used number of memory used: 4130412
Free Memory Number: 18744
GKFX is currently obsolete. No, always 0.
Buffers Buffer Cache memory Number: 13220
Cached Page Cache Memory: 2720160
Relationship: total = used + Free
Line 2nd:
The meaning of-/+ Buffers/cache is equal to:
-buffers/cache Memory: 1397032 (equals 1th row of used-buffers-cached)
+buffers/cache Memory: 2752124 (equals 1th line of Free + buffers + cached)
The visible-buffers/cache reflects the memory that is actually eaten by the program, and +buffers/cache reflects the total amount of memory that can be appropriated.
The third line is separate for the swap partition, so you don't have to say it again.
In order to improve disk access efficiency, Linux has done some careful design, in addition to the Dentry cache (for VFS, speed up the file path name to Inode conversion), but also adopted two main cache mode: Buffer cache and Page cache. The former is for the disk block read and write, the latter for the file inode read and write. These caches effectively shorten the time for I/O system calls (such as read,write,getdents).
Four, PS and Pstree
The PS and Pstree commands are the most common basic commands for system analysis.
The PS command provides a list of the processes that are running, and the number of processes that are listed depends on the parameters attached to the command. Typically, we can use the following command to find out if a process is running: Ps-aux | grep XXX.
The Pstree command can display all the process information in a tree-like structure and can integrate the child process information. The Pstree command is useful for analyzing the source of a process.
Example:
Wu, VMStat
The Vmstat command provides monitoring of information such as processes, memory, page I/O blocks, and CPUs, Vmstat can display the average or sampled values of the test results, and the sampling mode can provide a monitoring result of different frequencies over a sampling period.
Note: In the sampling mode, you need to consider the possible errors in data collection, and set the sampling frequency to a lower value to minimize the effect of the error.
Here's a look at what each column means
process (procs)
R: Number of processes waiting for run time
B: Process in non-disruptive sleep state
W: Processes that are swapped out but can still be run, this value is calculated
Memory
SWPD: Number of virtual memory
Free: The number of idle memory
Buff: The amount of memory used as a buffer
Swap
Si: Quantity exchanged from hard disk
So: The number of swapped to the hard drive
· Io
BI: Number of blocks output to a single block device
Bo: Number of blocks accepted from a single block device
system
In: Number of interrupts per second, including clock
CS: Number of context switches that occur per second
CPU (percent of the total CPU run time)
US: Time for non-kernel code to run (user time, including nice time)
SY: Kernel code run time (System time)
ID: Idle time, in the kernel version prior to Linux 2.5.41, this value includes I/O wait time
WA: Time to wait for I/O operation, this value is 0 in the kernel version prior to Linux 2.5.41
Example:
Six SysStat
Http://sebastien.godard.pagesperso-orange.fr/index.html Iostat: Reports CPU statistics and statistics of devices, partitions, network file system io;
Mpstat: Statistics related to the reporting process;
Pidstat: Report The statistics of Linux io,cpu,memory and so on;
SAR: Collect, Report, save system activity information (CPU, memory, disks, interrupts, network interfaces, TTY, kernel tables,etc.) ;
Linux System performance Detection