17.1.0: 系统管理-系统负载



1. cpu负载和cpu使用率

1) 基础概念

2) cpu load详解

system load averages(单位时间段内活动的进程数)是如何计算出来的(翻译整理自网络) 我们以一个单核cpu为例,这个单核cpu在1分钟内的处理状态相当于一条车道,每个cpu时间片相当于这条车道上的一段,如果执行了任务,则为有车,那么在此基础上,我们可以想象:

单位时间段内负载为0即为

==================================

==================================

单位时间段内负载为1即为

==================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
==================================

单位时间段内负载为1.2即为

    ===================================
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    ===================================

若cpu为双核,那么车道应该如下所示,为双车道

==================================

----------------------------------

==================================

以此类推,则n个核的cpu刚好满负载是n*1.0

3) cpu的个数和核数

cpu信息文件:
/proc/cpuinfo,此文件记录的是cpu的详细信息,以逻辑核为单位分段落,假设你有2个4核cpu,那么此文档就会分为8段,每一段落以processor的编号开头我们有8个核,第一段为0,以此类推到7,其中具体片段内容如下(虚拟机上内容与真机有差异)

文件内容示例:

processor       : 0
vendor_id       : GenuineIntel
cpu family      : 6
model           : 42
model name      : Intel(R) Core(TM) i3-2120 CPU @ 3.30GHz
stepping        : 7
cpu MHz         : 3292.570
cache size      : 3072 KB
fdiv_bug        : no
hlt_bug         : no
f00f_bug        : no
coma_bug        : no
fpu             : yes
fpu_exception   : yes
cpuid level     : 13
wp              : yes
flags           : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts mmx fxsr sse sse2 ss nx rdtscp constant_tsc up arch_perfmon pebs bts xtopology tsc_reliable nonstop_tsc aperfmperf unfair_spinlock pni pclmulqdq ssse3 pcid sse4_1 sse4_2 x2apic popcnt xsave avx hypervisor arat epb xsaveopt pln pts dts
bogomips        : 6585.14
clflush size    : 64
cache_alignment : 64
address sizes   : 40 bits physical, 48 bits virtual
power management:

4) 用法示例:

# 获取cpu逻辑核个数
# 我用虚拟机只分配了一个cpu
cat /proc/cpuinfo | grep 'processor'     
processor       : 0
cat /proc/cpuinfo | grep 'processor'|wc -l
1

# 获取物理cpu的个数
physical id是每一个物理cpu的唯一标识,虚拟机上无此字段
cat /proc/cpuinfo | grep 'physical id'|sort|uniq|wc -l
0


# 获取cpu内核个数
cat /proc/cpuinfo |grep 'core id'|sort|uniq|wc -l
0
core id是每一个内核的唯一标识符,虚拟机上无此字段

2. 系统负载查看

1) 命令:w

作用: 显示登录到系统的用户及它们在做什么

man page description
w - Show who is logged on and what they are doing.

语法:w [参数] [username]

man page description w - [husfV] [user]

参数:

输出结果含义:

用法举例:

# -u参数忽略进程的用户名称
# 登录使用的是essence,然后su切换到了root
w -u
 23:19:48 up 2 days, 4 min,  1 user,  load average: 0.00, 0.00, 0.00
USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT
essence  pts/0    unknown_c8-3a-35 23:19    0.00s  0.10s  0.00s w -u   
# 最终显示登录用户-essence


# -h参数不显示header
w -h
root     pts/0    essence-pc.gatew 11:05    0.00s  0.05s  0.00s w -h

2) 命令:uptime

作用:Tell how long the system has been running.
语法:

参数:

输出内容含义: