查看Linux服务器的负载

服务器性能指标一般是指CPU、内存、磁盘IO、网络连接等相关信息,下面介绍几个命令用来查看CPU和内存的信息。

w命令

➔ w
 11:37:56 up 639 days, 12:46,  1 user,  load average: 0.33, 0.12, 0.07
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
root     pts/3    58.32.4.73       11:25    4.00s  0.18s  0.00s w

第一行:当前时间 启动时长(没有关机和重启),当前用户数量,过去1分钟、5分钟、15分钟前的负载,一般来说,负载的值小于cpu数量*2时,服务器可以流畅运行,当大于这个值时,服务器就有一定压力了。

然后下面列出所有登录状态的用户的一些信息。

uptime命令

➔ uptime
 11:41:23 up 639 days, 12:49,  1 user,  load average: 0.02, 0.07, 0.06

这个命令是w的简化版,只有第一行,没有用户信息。

top命令

top命令非常强大,可以实时展示当前服务器CPU、内存的状态。按q键退出实时监控。

➔ top
top - 11:37:55 up 639 days, 12:46,  1 user,  load average: 0.33, 0.12, 0.07
Tasks: 389 total,   2 running, 387 sleeping,   0 stopped,   0 zombie
%Cpu(s):  1.1 us,  2.2 sy,  0.0 ni, 96.6 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
KiB Mem :  3881692 total,   336376 free,   605588 used,  2939728 buff/cache
KiB Swap:  2097148 total,  2011344 free,    85804 used.  2884676 avail Mem

  PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND
 5204 root      20   0  157992   2584   1548 R   2.3  0.1   0:00.24 top
    1 root      20   0  191632   3996   1844 S   0.0  0.1  85:41.69 systemd

第一行和w命令一样,来看第二行(Tasks),分别是:

进程总数,云中中的进程数,休眠中的进程数,停止了的进程数,僵尸进程数

第三行(%Cpu(s))是CPU的汇总信息,分别是:

us: user cpu time (or) % CPU time spent in user space
sy: system cpu time (or) % CPU time spent in kernel space
ni: user nice cpu time (or) % CPU time spent on low priority processes
id: idle cpu time (or) % CPU time spent idle
wa: io wait cpu time (or) % CPU time spent in wait (on disk)
hi: hardware irq (or) % CPU time spent servicing/handling hardware interrupts
si: software irq (or) % CPU time spent servicing/handling software interrupts
st: steal time - - % CPU time in involuntary wait by virtual cpu while hypervisor is servicing another processor (or) % CPU time stolen from a virtual machine

如果你的服务器是多核的,可以按数字1显示其他CPU的信息。

然后是内存和交换分区的信息,我这里是一个4G内存+2G的交换分区:

KiB Mem :  3881692 total,   321924 free,   603428 used,  2956340 buff/cache
KiB Swap:  2097148 total,  2011344 free,    85804 used.  2886952 avail Mem

如果Swap占用很多,说明内存不足。

然后下面的table列出了所有的进程的信息,每一列的意思分别是:

PID:    进程ID
USER:   用户名称
PR:     Piority 权重
NI:     nice值
VIRT:   Virtual Memory Size (KiB) 虚拟内存大小
RES:    Resident Memory Size (KiB) 实际使用内存的大小
SHR:    Shared Memory Size (KiB) 共享内存大小
S:      Process Status 进程状态,状态可能值见下面
%CPU:   CPU Usage 自上一次top刷新起到目前时间,该进程占用CPU的时间占比,按 shift+p 可按此列排序
%MEM:   Memory Usage (RES) 进程使用的物理内存的占比,按 shift+m 可按此列排序
TIME+:  自进程启动起占用CPU的百分之一秒数(例如:0:00.06 表示占用CPU 6秒)
COMMAND 进程命令

Process Status的值

D = uninterruptible sleep
R = running
S = sleeping
T = stopped by job control signal
t = stopped by debugger during trace
Z = zombie

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注