• 使用w查看系统负载 vmstat命令 top命令 sar命令 nload命令


    • w/uptime 查看系统负载

     

    w查看系统负载,uptime跟w一样。

     

    [root@centos7 ~]# w

     22:34:10 up 6 days, 23:10,  4 users,  load average: 0.00, 0.01, 0.05

    USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT

    root     tty1     :0               151月18  6days  3:52   0.61s mate-session

    root     pts/0    113.224.66.86    20:23    2:09m  0.00s  0.00s -bash

    root     pts/1    113.224.66.86    22:19    2.00s  0.00s  0.00s w

    root     pts/2    113.224.66.86    22:21   12:26   0.00s  0.00s -bash

     

    都是什么意思?

     

     

    系统时间,系统启动多长时间: 22:34:10 up 6 days, 23:10,

    date命令查看当前系统时间

    [root@centos7 ~]# date

    2018年 01月 22日 星期一 22:34:32 CST

     

    4个登录用户 4 users

    TTY用户登录方式:本地登录TTY1~TTY6;远程网络登录PTS/0,PTS/1

    tty1-tty6   本地登录6个终端

    远程网络登录时 pts/0,pts/1等。

      FROM    表示从哪里来的,从哪里登录的IP

     

     

    load average: 0.00, 0.01, 0.05

    系统负载:1分钟,5分钟,15分钟时间段内系统负载多少。

    数值含义:单位时间段内使用CPU活动的进程有多少个。

     

    0.00: 平均1分钟内使用CPU活动进程多少个。

    数值为1的时候是最理想的。

    如果是8核CPU,负载低于8不超载,大于8的话CPU就不够用了。

    0.01:平均5分钟内使用CPU活动进程多少个。

    0.05:平均5分钟内使用CPU活动进程多少个。

     

    cat/proc/cpuinfo 查看cpu核数  processor 0 表示 1核CPU

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

    processor : 0

    vendor_id : GenuineIntel

    cpu family : 6

    model : 79

    model name : Intel(R) Xeon(R) CPU E5-2682 v4 @ 2.50GHz

    stepping : 1

    microcode : 0x1

    cpu MHz : 2499.996

    cache size : 40960 KB

     

     

     

     

    • vmstat监控系统状态

    包括内存,虚拟磁盘,磁盘,系统进程,cpu等。

    用法 vmstat 1

    表示每一秒钟动态显示

    [root@centos7 ~]# vmstat 1

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

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

     3  0      0 105720  35080 1208312    0    0     2     2   26   63  0  0 99  0  0

     

    vmstat 1 5 表示每1秒钟显示一次,只需要显示5次

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

    r:run的缩写,表示有多少个进程处于run的状态。

    b: block (阻塞状态)有多少个进程在等待。

    swpd:交换分区。当内存不够的时候,将一部分内存资源放到swap分区里去。

    si: swap input 进入到内存里去

    so:swap output 从内存里出去

    io

    bi: 写入到磁盘里去

    bo: 从磁盘里读

    us: 表示用户占用资源的百分比,user service

    sy: 表示系统本身占用资源的百分比

    id:idle 空闲

    us + sy + id =100%

     

     

    wa: 表示waite 等待cpu的百分比

     

    • top查看进程使用资源情况

    每3秒更新一次,动态显示

     

    第一段跟w一样,第二段 总共多少进程,多少个正在运行进程,多少个休眠进程,多少个停止进程,多少个僵尸进程。

    第三段cpu百分比: us + sy +id =100%(用户资源占用百分比+系统资源占用百分比+空闲资源百分比=100%)

    wa :waite等待进程

    st:表示被偷走的进程cpu百分比。如果服务器做了虚拟化,子虚拟机可能会偷走部分cpu

    KiB Mem 物理内存。

    KiB Swap 虚拟机内存。

    [root@centos7 ~]# top

    top - 23:31:32 up 7 days, 7 min,  4 users,  load average: 0.00, 0.01, 0.05

    Tasks: 112 total,   1 running, 111 sleeping,   0 stopped,   0 zombie

    %Cpu(s):  2.0 us,  0.3 sy,  0.0 ni, 97.7 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st

    KiB Mem :  1883496 total,   101972 free,   537584 used,  1243940 buff/cache

    KiB Swap:        0 total,        0 free,        0 used.  1160012 avail Mem 

      PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                     

     1705 root      20   0 2142076 273816  69260 S  2.3 14.5  12:01.28 firefox                     

     1574 root      20   0  999584  14456  10936 S  0.7  0.8   9:25.85 mate-volume-con             

        1 root      20   0   43388   3824   2516 S  0.0  0.2   0:03.60 systemd                     

        2 root      20   0       0      0      0 S  0.0  0.0   0:00.05 kthreadd                    

        3 root      20   0       0      0      0 S  0.0  0.0   0:09.79 ksoftirqd/0                 

        5 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kworker/0:0H                

        6 root      20   0       0      0      0 S  0.0  0.0   0:01.05 kworker/u2:0                

        7 root      rt   0       0      0      0 S  0.0  0.0   0:00.00 migration/0                 

        8 root      20   0       0      0      0 S  0.0  0.0   0:00.00 rcu_bh                      

        9 root      20   0       0      0      0 S  0.0  0.0   0:22.85 rcu_sched                   

       10 root      rt   0       0      0      0 S  0.0  0.0   0:01.97 watchdog/0                  

       12 root      20   0       0      0      0 S  0.0  0.0   0:00.00 kdevtmpfs                   

       13 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 netns                       

       14 root      20   0       0      0      0 S  0.0  0.0   0:00.17 khungtaskd                  

       15 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 writeback                   

       16 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 kintegrityd                 

       17 root       0 -20       0      0      0 S  0.0  0.0   0:00.00 bioset                      

     

    %CPU,%MEM 会按照占用多少资源百分比排序,占用多的排到最前面。

    RES 表示物理内存大小,单位k字节

     

     

    top  -c 显示详细的进程信息,可以看到具体的命令。

     

    top  -bn1  静态显示所有进程。

     

    q退出,数字1显示所有核cpu,大写字母M按内存使用排序

    大写字母p按cpu使用排序

     

    杀死进程:kill  pid号

    • sar命令

    系统监控

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

    sar  每10分钟会把系统的状态抓一遍保存日志文件到目录/var/log/sa下

    saxx 是以日期结尾。保留数据1个月。

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

    sa01  sa06  sa11  sa16  sa21  sa27  sar01  sar06  sar11  sar16  sar21  sar27

    sa02  sa07  sa12  sa17  sa22  sa28  sar02  sar07  sar12  sar17  sar22  sar28

    sa03  sa08  sa13  sa18  sa23  sa29  sar03  sar08  sar13  sar18  sar24  sar29

    sa04  sa09  sa14  sa19  sa25  sa30  sar04  sar09  sar14  sar19  sar25  sar30

    sa05  sa10  sa15  sa20  sa26  sa31  sar05  sar10  sar15  sar20  sar26  sar31

    查看22号的使用网卡流量的情况:

    [root@centos7 ~]# sar -n DEV -f /var/log/sa/sa22

    sar -n DEV  查看网卡流量

     

    sar -n DEV 1 2  每1秒显示一次,显示2次

    [root@centos7 ~]# sar -n DEV 1 2

    Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

    00时09分15秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

    00时09分16秒      eth0      2.00      1.00      0.13      0.10      0.00      0.00      0.00

    00时09分16秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

    00时09分16秒     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

    00时09分17秒      eth0      1.00      1.00      0.06      0.18      0.00      0.00      0.00

    00时09分17秒        lo      0.00      0.00      0.00      0.00      0.00      0.00      0.00

    平均时间:     IFACE   rxpck/s   txpck/s    rxkB/s    txkB/s   rxcmp/s   txcmp/s  rxmcst/s

    平均时间:      eth0      1.50      1.00      0.10      0.14      0.00      0.00      0.00

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

    IFACE 两个网卡 eth0 和lo

     

    rxpck/s (received package)表示接收到的数据包量的多少

    txpck/s  表示发送的数据包量的多少

    接收到的数据包几千KB/S 算是正常,上万KB/S 可能被攻击了。

    rxkB/s  接收的数据量KB

    txkB/s 发送的数据量KB

     

     

    sar -q 1 10 查看系统负载,每1秒显示,显示10次

     

    [root@centos7 ~]# sar -q 1 10

    Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

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

    00时40分41秒         0       299      0.00      0.01      0.05         0

    00时40分42秒         0       299      0.00      0.01      0.05         0

    00时40分43秒         0       299      0.00      0.01      0.05         0

    00时40分44秒         0       299      0.00      0.01      0.05         0

    00时40分45秒         0       299      0.00      0.01      0.05         0

    00时40分46秒         0       299      0.00      0.01      0.05         0

    00时40分47秒         0       299      0.00      0.01      0.05         0

    00时40分48秒         0       299      0.00      0.01      0.05         0

    00时40分49秒         0       299      0.00      0.01      0.05         0

    00时40分50秒         0       299      0.00      0.01      0.05         0

    平均时间:         0       299      0.00      0.01      0.05         0

     

     

     

    指定日期查看系统负载情况:

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

    Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

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

    00时10分01秒         2       299      0.00      0.05      0.07         0

    00时20分01秒         2       299      0.01      0.02      0.05         0

    00时30分01秒         2       301      0.00      0.01      0.05         0

    00时40分01秒         2       299      0.00      0.01      0.05         0

    平均时间:         2       300      0.00      0.02      0.06         0

     

     

     

     

    查看磁盘使用情况

    sar -b  1  5   每秒显示1次,显示5次

    [root@centos7 ~]# sar -b 1 5

    Linux 3.10.0-693.2.2.el7.x86_64 (centos7.4) 2018年01月23日 _x86_64_ (1 CPU)

    00时44分03秒       tps      rtps      wtps   bread/s   bwrtn/s

    00时44分04秒      0.00      0.00      0.00      0.00      0.00

    00时44分05秒      0.00      0.00      0.00      0.00      0.00

    00时44分06秒      0.00      0.00      0.00      0.00      0.00

    00时44分07秒      0.00      0.00      0.00      0.00      0.00

    00时44分08秒      0.00      0.00      0.00      0.00      0.00

    平均时间:      0.00      0.00      0.00      0.00      0.00

     

     

    sa17&&sar17区别:

    ls /var/log/sa/sa17

    Sa17是一个二进制文件,不能cat,只能用sar -n DEV -f /var/log/sa/sa17查看

    ls /var/log/sa/sar17,sar17可以cat

    •  nload命令

    安装epel-release

    [root@centos7 ~]# yum install -y epel-release

     

    安装noload

     

    [root@centos7 ~]# yum install -y nload

    [root@centos7 ~]# nload

    Device eth0 [192.168.1.81] (1/2):

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

    Incoming:

                                                                      Curr: 1.02 kBit/s

                                                                      Avg: 2.45 kBit/s

                                                                      Min: 1.02 kBit/s

                                                                      Max: 7.89 kBit/s

                                                                      Ttl: 31.20 MByte

    Outgoing:

                                                                      Curr: 8.08 kBit/s

                                                                      Avg: 8.61 kBit/s

                                                                      Min: 4.46 kBit/s

                                                                      Max: 13.66 kBit/s

                                                                      Ttl: 17.06 MByte

    两个网卡,按上下键切换网卡

  • 相关阅读:
    湘志恒善.NET 企业实训新学员必读手册
    周末电脑城有感硬件和软件价格的升降(实物图9.22更新)
    企业I期做项目之前的小例子
    商学院企业I班暑期作业 【2008年8月12日更新】
    项目公司机房升级
    android小应用帮美女更衣系列一(附源码)
    android小应用帮美女更衣系列二(附源码)
    @synthesize 和 @property
    VS2008下载地址和版本破解
    Android腾讯微薄客户端开发十三:提及篇(与我有关的微博)
  • 原文地址:https://www.cnblogs.com/zhaocundang/p/8331865.html
Copyright © 2020-2023  润新知