10月23日任务

10.1 使用w查看系统负载

查看时间:

[root@test ~]# date

2018年 10月 23日 星期二 09:09:50 CST

 

 

查看系统状态

[root@test ~]# uptime

09:24:58 up 11 days, 20:48,  1 user,  load average: 0.00, 0.01, 0.05

 

[root@test ~]# w

09:06:56 (当前时间)up 11 days, 20:30,(系统启动的时间)  1 user(目前登陆几个用户),  load average: 0.00, 0.01, 0.05 (系统负载)

(登陆用户情况)

USER     TTY(登陆终端)      FROM             LOGIN@(登陆时间)   IDLE(空闲多久)   JCPU   PCPU WHAT

root     pts/0                          115.236.28.52    08:59    0.00s  0.07s  0.00s w

注:网络登陆: pts/0   pts/1 ...

     终端登陆:tty1 至tty6

 

系统负载(与CPU关联)数值是平均值:load average: 0.00(一分钟使用CPU的活动进程有多少个,最关注数值), 0.01(五分钟使用CPU的活动进程有多少个), 0.05(十五分钟使用CPU的活动进程有多少个

注:数值为0时表示系统在空跑浪费资源,数值最理想的状态首先查看有几颗逻辑CPU,不高于或者等于逻辑CPU数量一致是最理想状态

 

查看逻辑CPU

[root@test ~]# cat /proc/cpuinfo

processor    : 0

vendor_id    : GenuineIntel

cpu family    : 6

model        : 47

model name    : Intel(R) Xeon(R) CPU E7- 4807  @ 1.87GHz

stepping    : 2

microcode    : 0x37

cpu MHz        : 1862.014

cache size    : 18432 KB

physical id    : 0

siblings    : 2

core id        : 0

cpu cores    : 2

apicid        : 0

initial apicid    : 0

fpu        : yes

fpu_exception    : yes

cpuid level    : 11

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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm dtherm arat

bogomips    : 3724.02

clflush size    : 64

cache_alignment    : 64

address sizes    : 40 bits physical, 48 bits virtual

power management:

 

processor    : 1

vendor_id    : GenuineIntel

cpu family    : 6

model        : 47

model name    : Intel(R) Xeon(R) CPU E7- 4807  @ 1.87GHz

stepping    : 2

microcode    : 0x37

cpu MHz        : 1862.014

cache size    : 18432 KB

physical id    : 0

siblings    : 2

core id        : 1

cpu cores    : 2

apicid        : 1

initial apicid    : 1

fpu        : yes

fpu_exception    : yes

cpuid level    : 11

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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm dtherm arat

bogomips    : 3724.02

clflush size    : 64

cache_alignment    : 64

address sizes    : 40 bits physical, 48 bits virtual

power management:

 

processor    : 2

vendor_id    : GenuineIntel

cpu family    : 6

model        : 47

model name    : Intel(R) Xeon(R) CPU E7- 4807  @ 1.87GHz

stepping    : 2

microcode    : 0x37

cpu MHz        : 1862.014

cache size    : 18432 KB

physical id    : 1

siblings    : 2

core id        : 0

cpu cores    : 2

apicid        : 2

initial apicid    : 2

fpu        : yes

fpu_exception    : yes

cpuid level    : 11

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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm dtherm arat

bogomips    : 3724.02

clflush size    : 64

cache_alignment    : 64

address sizes    : 40 bits physical, 48 bits virtual

power management:

 

processor    : 3

vendor_id    : GenuineIntel

cpu family    : 6

model        : 47

model name    : Intel(R) Xeon(R) CPU E7- 4807  @ 1.87GHz

stepping    : 2

microcode    : 0x37

cpu MHz        : 1862.014

cache size    : 18432 KB

physical id    : 1

siblings    : 2

core id        : 1

cpu cores    : 2

apicid        : 3

initial apicid    : 3

fpu        : yes

fpu_exception    : yes

cpuid level    : 11

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 ht syscall nx rdtscp lm constant_tsc arch_perfmon pebs bts nopl xtopology tsc_reliable nonstop_tsc aperfmperf eagerfpu pni pclmulqdq ssse3 cx16 sse4_1 sse4_2 popcnt aes hypervisor lahf_lm dtherm arat

bogomips    : 3724.02

clflush size    : 64

cache_alignment    : 64

address sizes    : 40 bits physical, 48 bits virtual

power management:

10.2 vmstat命令(查看系统瓶颈)

用vmstat命令监控系统的状态

命令w查看的是系统整体上的负载,通过看那个数值可以知道当前系统有没有压力。当它无法判断具体是哪里(CPU,内存,虚拟磁盘、交换分区、io磁盘、系统进程等)有压力,所以这就用到了vmstat 。

 

命令vmstat用法

 

- 静态显示内存状态一次。

 

[root@test ~]# vmstat

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

1  0      0 3257704   2116 440592    0    0     0     0    9    4  0  0 100  0  0

 

- vmstat [n] 在此n代表数字,意思是每隔n秒输出一次状态(按Ctrl+c结束命令)。

 

[root@test ~]# vmstat 1    //如果不Ctrl+c    每1秒钟会显示一次,动态显示。

 

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

1  0      0 3257828   2116 440588    0    0     0     0    9    4  0  0 100  0  0

0  0      0 3257828   2116 440588    0    0     0     0   80   63  0  0 100  0  0

0  0      0 3257836   2116 440588    0    0     0     0   94   71  0  0 100  0  0

0  0      0 3257836   2116 440588    0    0     0     0   63   52  0  0 100  0  0

0  0      0 3257836   2116 440588    0    0     0     0   97   80  0  0 100  0  0

0  0      0 3257836   2116 440588    0    0     0     0   70   51  0  0 100  0  0

0  0      0 3257836   2116 440588    0    0     0     0   79   64  0  0 100  0  0

 

- vmstat [n] [m] 这里的n表示每隔n秒输出一次状态,m表示动态显示的次数;

 

[root@test ~]# vmstat 1 5

procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----

r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st

1  0      0 3257704   2116 440580    0    0     0     0    9    4  0  0 100  0  0

0  0      0 3257712   2116 440580    0    0     0     0   96   63  0  0 100  0  0

0  0      0 3257712   2116 440580    0    0     0     0   72   58  0  0 100  0  0

0  0      0 3257712   2116 440580    0    0     0     0   70   55  0  0 100  0  0

0  0      0 3257712   2116 440580    0    0     0     0   83   70  0  0 100  0  0

 

 

注:关注列:r,b,swpd,si,so,bi,bo,us,wa

 

说明:

 

proc 显示进程相关信息

 

r:=run,表示运行中或等待cpu运行的进程数,如果该数长期大于服务器CPU个数,则说明CPU不够用了。多少个进程处于run状态,进程sleep状态也属于run,当进程比cpu多时,一个时刻只可能有一个进程在使用一个cpu,此时进程处于排队状态,循环使用每个进程都会使用一会,排队就是r状态

 

b: =block ,表示等待资源的进程数,如,等待I/O,内存等,这列的值如果长时间大于1,则需要关注一下。  进程被内存、网络阻断,处于堵死、卡死,只能等待

 

memory 内存相关信息

 

swpd:表示切换到交换分区的内存量(当该数据不断变化时说明内存不足) 内存不够时临时放到swpd空间中,数据不断变化说明交换分区和内存频繁的在交换数据,需要关注内存不够了

 

free:表示当前空闲的内存量

 

buff:缓冲大小

 

cache:缓存大小

 

swap 内存交换情况

 

si:=storage in,表示有多少块(kb单位)数据交换区写入到内存的数据量  (swpd有关联,swpd频繁改变,此列数据会发生改变)有多少块(kb单位)

 

so:=storage out,表示由内存写入到交换区的数据量  (swpd有关联,swpd频繁改变,此列数据会发生改变)

 

io 磁盘使用情况

 

bi:=block in,表示从块设备(磁盘)读取数据(写入内存)的量(即:读磁盘),单位为KB;(磁盘关联)

 

bo:=block out,表示(从内存读取)写入到块设备(磁盘)的数据(即:写磁盘),单位为KB;(磁盘关联)

注: 此处数据会直接关系到proc出的b的值。

 

system 显示采集间隔内发生的中断次数

 

in:表示在某一时间间隔中观测到的每秒设备中断数

 

cs:表示每秒产生的上下文切换次数

 

CPU 显示CPU的使用状态(us+sy+id=100%)

 

us:表示用户资源( 用户级别)所花费CPU的百分比(当该值长时间>50时说明CPU数量不足  不会超过100%) 

 

sy:表示系统资源所花费CPU的百分比(系统本身)

 

id:表示CPU处于空闲状态的百分比

 

wa:=wait,表示等待使用CPU的百分比有多少个进程(该数值大说明CPU不足)与b类似  

 

st:表示被偷走的CPU所占百分比(该值一般为0,不用关注)

 

us + sy + id + wa =100% 

 

注意:需要关注的是r,b和wa这3列,io部分和bi和bo也是要经常参考的对象,如果磁盘io压力很大,这两列的数值会比较高(大于5千算高)。另外,当si和so两列的数值比较高并且不断变化时,说明内存不够了,内存中的数据频繁交换分区中,这往往对系统性能影响极大。

10.3 top命令(具体查看瓶颈的进程)

3秒钟动态显示进程

[root@test ~]# top

d641327606c4cf54dec3b8575d66f07039c.jpg

 

第一行与w显示的系统负载一致

第二行total有多少个任务(总数进程)  running有多少个运行的任务(运行,r状态vmstat r列)  sleeping有多少个运行的任务(休眠)   0 stopped有多少个运行的任务(停止)  0 zombie有多少个运行的任务 (僵尸进程)

僵尸进程:主进程意外停止,子进程没人管理,自生自灭

第三列cpu百分比 vmstat含有此列  st被偷走的CPU所占百分比 (服务器做了虚拟机,虚拟机会偷走部分cpu)  (超过60%的cpu会使服务器寿命减少) 关注us (占用cpu不一定是r状态也许是sleep状态,但是排队会使cpu跑高)

第四五列表示:物理内存和交换分区  

KiB Mem :  3881028 total(总共内存大小),  3256860 free(剩余多少内存),   181316 used(使用多少内存),   442852 buff/cache

 

默认情况按照%CPU  cpu百分比排序(从高至底)  %MEM内存大小百分比  RES物理内存大小(单位kb)   

PID杀死进程 kill  pid         kill -9  pid 一定可以杀死。 误杀了 就恢复不了了。

按照内存排序 按M  换回CPU 按P   

所有CPU的百分比  按数字1

d641327606c4cf54dec3b8575d66f07039c.jpg

[root@test ~]# top -c查看具体进程命令(全局路径)

5596bbe637115c0faec997f419858f26e2a.jpg

[root@test ~]# top -bn1静态显示 一次性打印出来(写脚本时使用)

0d2c01611a14422d16dd9d417196bbb56f2.jpg

10.4 sar命令(分析系统状态命令,网卡流量   linux系统瑞士军刀)

yum install -y sysstat 

sar -n DEV  网卡流量 

sar -q  系统负载 

sar -b  磁盘读写 

sar -f /var/log/sa/saxx  历史文件

 

安装命令

[root@test ~]# yum install -y sysstat

 

使用前(不加参数会去调用保留的历史文件)

[root@test ~]# sar

无法打开 /var/log/sa/sa23: 没有那个文件或目录

 

[root@test ~]# sar

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

10时50分02秒     all      0.03      0.00      0.03      0.00      0.00     99.94

11时00分01秒     all      0.03      0.00      0.03      0.00      0.00     99.93

平均时间:     all      0.03      0.00      0.03      0.00      0.00     99.93

 

sar生成的历史文件所在目录(每十分钟把系统状态过滤一遍)

[root@test ~]# ls /var/log/sa

sa23

查看网卡流量

[root@test ~]# sar -n DEV 1 3  (每隔一秒显示一次 显示十次)

0d2c01611a14422d16dd9d417196bbb56f2.jpg

 

rxpck接收到的数据包(个数)   (被攻击时接收的数据包会很大,使网络堵塞,正常值:数据量不能上万,上万至几十万就是被攻击并且借用抓包工具)

txpck发送出去的数据包  (个数)

 

rxkB接收数据量(kb) (被攻击时接收的数据量也会很大)

txkB发送出去数据量(kb)  (查看网卡流量多大,网站下载速率是否跑满,因为用户体验下载速率慢)

 

查看网卡流量并且指定文件(按照日期生成,可以查历史数据,但是只保留一个月)

[root@test ~]# sar -n DEV -f /var/log/sa/sa23

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

10时50分02秒     ens32      6.19      0.09      0.38      0.01      0.00      0.00      0.00

10时50分02秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

10时50分02秒 virbr0-nic      0.00      0.00      0.00      0.00      0.00      0.00      0.00

10时50分02秒    virbr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

11时00分01秒     ens32      6.14      0.23      0.38      0.05      0.00      0.00      0.00

11时00分01秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

11时00分01秒 virbr0-nic      0.00      0.00      0.00      0.00      0.00      0.00      0.00

11时00分01秒    virbr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

平均时间:     ens32      6.16      0.16      0.38      0.03      0.00      0.00      0.00

平均时间:        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

平均时间: virbr0-nic      0.00      0.00      0.00      0.00      0.00      0.00      0.00

平均时间:    virbr0      0.00      0.00      0.00      0.00      0.00      0.00      0.00

 

查看系统负载

[root@test ~]# sar -q 1 3  (当前数据)

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

11时06分34秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked

11时06分35秒         0       173      0.00      0.01      0.05         0

11时06分36秒         0       173      0.00      0.01      0.05         0

11时06分37秒         0       173      0.00      0.01      0.05         0

平均时间:         0       173      0.00      0.01      0.05         0

 

[root@test ~]# sar -q

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked

10时50分02秒         0       172      0.00      0.01      0.05         0

11时00分01秒         0       173      0.00      0.01      0.05         0

平均时间:         0       172      0.00      0.01      0.05         0

 

[root@test ~]# sar -q -f /var/log/sa/sa23  (查看历史数据)

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒   runq-sz  plist-sz   ldavg-1   ldavg-5  ldavg-15   blocked

10时50分02秒         0       172      0.00      0.01      0.05         0

11时00分01秒         0       173      0.00      0.01      0.05         0

平均时间:         0       172      0.00      0.01      0.05         0

 

查看磁盘

[root@test ~]# sar -b 1 3  (查看当前)

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

11时08分59秒       tps      rtps      wtps   bread/s   bwrtn/s

11时09分00秒      0.00      0.00      0.00      0.00      0.00

11时09分01秒      0.00      0.00      0.00      0.00      0.00

11时09分02秒      0.00      0.00      0.00      0.00      0.00

平均时间:      0.00      0.00      0.00      0.00      0.00

 

 

[root@test ~]# sar -b

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒       tps      rtps      wtps   bread/s   bwrtn/s

10时50分02秒      0.08      0.00      0.08      0.00      1.07

11时00分01秒      0.06      0.00      0.06      0.05      0.85

平均时间:      0.07      0.00      0.07      0.03      0.96

 

[root@test ~]# sar -b -f /var/log/sa/sa23  (查看历史)

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒       tps      rtps      wtps   bread/s   bwrtn/s

10时50分02秒      0.08      0.00      0.08      0.00      1.07

11时00分01秒      0.06      0.00      0.06      0.05      0.85

平均时间:      0.07      0.00      0.07      0.03      0.96

 

区别:

[root@test ~]# ls /var/log/sa/sa23  (二进制文件)

[root@test ~]# ls /var/log/sa/sar23  (查看cat)

 

[root@test ~]# sar -f /var/log/sa/sa23

Linux 3.10.0-862.14.4.el7.x86_64 (test)     2018年10月23日     _x86_64_    (4 CPU)

 

10时40分01秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

10时50分02秒     all      0.03      0.00      0.03      0.00      0.00     99.94

11时00分01秒     all      0.03      0.00      0.03      0.00      0.00     99.93

11时10分01秒     all      0.04      0.00      0.04      0.00      0.00     99.92

平均时间:     all      0.03      0.00      0.04      0.00      0.00     99.93

 

10.5 nload命令(监控网卡流量)

nload命令 

yum install -y epel-release 

yum install -y nload

安装命令[root@test ~]# yum install -y nload

按向右键可以查看其它网卡  q退出

[root@test ~]# nload

7f42051b4774813d1e55e83d153266bca80.jpg

查看进来和出去的带宽

curr 当前值  (进来的值)

avg平均值

min最小值

max最大值

转载于:https://my.oschina.net/u/3803396/blog/2251087

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值