服务器性能用到的知识:

Load

系统负载指运行队列的平均长度,也就是等待CPU的平均进程数

可以通过cat /proc/loadavg w top等命令获取

推荐一篇文章[[http://blog.scoutapp.com/articles/2009/07/31/understanding-load-averages|Understanding Linux CPU Load]]

CPU

top atop htop
获取CPU信息cat /proc/cpuinfo

其中%wa指CPU等待磁盘写入完成的时间

vmstat sar iostat

Memory

free vmstat top cat /proc/meminfo

Swap

From Linux.com

Linux divides its physical RAM (random access memory) into chucks of memory called pages. Swapping is the process whereby a page of memory is copied to the preconfigured space on the hard disk, called swap space, to free up that page of memory. The combined sizes of the physical memory and the swap space is the amount of virtual memory available.

Swapping is necessary for two important reasons. First, when the system requires more memory than is physically available, the kernel swaps out less used pages and gives memory to the current application (process) that needs the memory immediately. Second, a significant number of the pages used by an application during its startup phase may only be used for initialization and then never used again. The system can swap out those pages and free the memory for other applications or even for the disk cache.

排查哪个进程占用swap过高:

1 读取/proc/*/status/proc/*/smaps文件, 具体可以man 5 proc. 脚本来源

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/bash
# Get current swap usage for all running processes
# Erik Ljungstrom 27/05/2011
# Modified by Mikko Rantalainen 2012-08-09
# Pipe the output to "sort -nk3" to get sorted output
# Modified by Marc Methot 2014-09-18
# removed the need for sudo

SUM=0
OVERALL=0
for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+"`
do
    PID=`echo $DIR | cut -d / -f 3`
    PROGNAME=`ps -p $PID -o comm --no-headers`
    for SWAP in `grep VmSwap $DIR/status 2>/dev/null | awk '{ print $2 }'`
    do
        let SUM=$SUM+$SWAP
    done
    if (( $SUM > 0 )); then
        echo "PID=$PID swapped $SUM KB ($PROGNAME)"
    fi
    let OVERALL=$OVERALL+$SUM
    SUM=0
done
echo "Overall swap used: $OVERALL KB"

简短的命令就如下, 不过wild match应该只匹配数字, 所以这里会把一些其它文件包含进来, 脚本来源:

for file in /proc/*/status ; do awk '/VmSwap|Name/{printf $2 " " $3}END{ print ""}' $file; done | sort -k 2 -n -r | less

2 top命令, 好像3.2的版本是Op, 3.3的版本是fp来调出swap并排序. 具体查看help.

3 smem命令, 要装的东西太多了, 所以还没装.

参考:

磁盘I/O

iostat

网络I/O

netstat

Read More