Linux--每天学习一个命令(一)

Linux 系统监控

Top命令

Processes: 355 total, 3 running, 352 sleeping, 1540 threads            22:53:50
Load Avg: 2.23, 1.85, 1.79  CPU usage: 2.91% user, 3.4% sys, 94.3% idle
SharedLibs: 203M resident, 47M data, 29M linkedit.
MemRegions: 67938 total, 2480M resident, 96M private, 956M shared.
PhysMem: 9029M used (3177M wired), 7345M unused.
VM: 995G vsize, 627M framework vsize, 66673141(0) swapins, 67456042(0) swapouts.
Networks: packets: 10075546/9110M in, 7870367/1935M out.
Disks: 5209393/349G read, 3216109/340G written.

PID    COMMAND      %CPU TIME     #TH    #WQ  #PORT MEM    PURG   CMPRS  PGRP
36055  git          0.0  00:00.06 1      0    10    928K   0B     0B     35626
36054  git          0.0  00:01.33 2      0    11    7628K  0B     0B     35626
36052  mdworker     0.0  00:00.06 4      1    48    5224K  0B     0B     36052
36051  mdworker     0.0  00:00.03 3      1    46    2932K  0B     0B     36051
36050  mdworker     0.0  00:00.06 4      1    48    8084K  0B     0B     36050
36049  top          2.8  00:06.87 1/1    0    25    3400K  0B     0B     36049
35964  bash         0.0  00:00.07 1      0    16    2668K  0B     0B     35964
35963  login        0.0  00:00.02 2      1    29    1132K  0B     0B     35963
35961  Google Chrom 0.0  00:05.98 18     2    156   77M    0B     0B     4804
35955  git-remote-h 0.1  00:00.29 2      1    37    10M    0B     0B     35626
35954  git          0.0  00:00.02 1      0    10    6932K  0B     0B     35626
35949  git-remote-h 0.1  00:00.26 2      1    37    4672K+ 0B     0B     35626
35948  git          0.0  00:00.01 1      0    10    968K   0B     0B     35626
35940  bash         0.0  00:00.00 1      0    8     460K   0B     0B     35626

然而还有个好用的工具那就是 glances(惊鸿一瞥)

mac下载方法:

brew install -y glances

Linux Ubuntu:

apt install -y glances

Linux Centos:

yum install -y glances

Pip:

pip install glances

glances使用方法:

在终端直接敲glances:

CPU  [  9.3%]   CPU /     9.3%  nice:     0.0%  ctx_sw:   441     MEM -   61.2%     SWAP -   52.6%     LOAD    8-core

MEM  [ 61.3%]   user:     6.7%  inter:  -2515                     total:  16.0G     total:   2.00G     1 min:    1.69

SWAP [ 52.6%]   system:   2.7%  sw_int:   446                     used:   9.80G     used:    1.05G     5 min:    1.72

                idle:    90.7%  syscal:     0                     free:   6.20G     free:     970M     15 min:   1.73


NETWORK     Rx/s   Tx/s   TASKS 195 (939 thr), 195 run, 0 slp, 0 oth sorted automatically by cpu_percent, flat view

awdl0         0b     0b

bridge0       0b     0b     CPU%  MEM%  VIRT   RES   PID USER        NI S     TIME+ Command 

en0          2Kb   864b     39.3   0.7 3.45G  121M   293 yuqibing     0 R  11:12.56 /Applications/Utilities/Terminal.

en1           0b     0b      4.9   0.9 4.21G  155M 18921 yuqibing     0 R  47:40.92 /Applications/Google Chrome.app/C

en2           0b     0b      2.9   0.1 2.44G 13.1M  4811 yuqibing     0 R  22:06.99 /System/Library/Frameworks/VideoT

lo0         280b   280b      2.7   0.3 2.41G 43.9M 38637 yuqibing     0 R   0:03.34 /Library/Frameworks/Python.framew

p2p0          0b     0b      2.4   1.2 9.44G  190M  4809 yuqibing     0 R   1h10:32 /Applications/Google Chrome.app/C

utun0         0b     0b      1.4   1.7 5.19G  276M  4804 yuqibing     0 R   2h05:54 /Applications/Google Chrome.app/C

utun1         0b     0b      1.2   0.7 2.96G  115M   370 yuqibing     0 R   7:49.55 /System/Library/Input Methods/SCI

                             0.5   2.3 4.04G  383M 19198 yuqibing     0 R   3:53.39 /Applications/Google Chrome.app/C

DISK I/O     R/s    W/s      0.3   0.6 3.63G  103M 35137 yuqibing     0 R   0:42.80 /Applications/Google Chrome.app/C

disk0       494K      0      0.1   0.2 3.55G 34.1M 18920 yuqibing     0 R   1:15.87 /Applications/Google Chrome.app/C

disk2          0      0      0.1   0.5 3.70G 83.3M 18944 yuqibing     0 R   3:57.14 /Applications/Google Chrome.app/C

disk3          0      0      0.1   0.5 3.67G 90.0M 19058 yuqibing     0 R   1:23.48 /Applications/Google Chrome.app/C

                             0.1   0.1 4.48G 10.1M 19543 yuqibing     0 R   0:54.79 /Library/Java/JavaVirtualMachines

FILE SYS    Used  Total      0.1   0.2 3.57G 25.7M 19560 yuqibing     0 R   0:52.25 /Applications/Google Chrome.app/C

/ (disk1)   115G   233G      0.1   0.6 3.39G  106M 35625 yuqibing     0 R   0:01.54 /Applications/Google Chrome.app/C

_sX-NG-R8  18.0M  22.4M      0.0   0.4 2.67G 72.3M   111 root         0 R   2:18.93 /System/Library/CoreServices/logi

_CCB6B9D7   118G   233G      0.0   0.1 2.41G 13.4M   278 yuqibing     0 R   0:54.79 /usr/sbin/cfprefsd agent

                             0.0   0.1 2.43G 20.3M   279 yuqibing     0 R   1:11.77 /usr/libexec/UserEventAgent (Aqua

SENSORS                      0.0   0.1 2.40G 11.8M   281 yuqibing     0 R   2:58.90 /usr/sbin/distnoted agent

Battery             46%      0.0   0.2 2.45G 25.4M   283 yuqibing     0 R   0:49.88 /System/Library/Frameworks/CoreTe

                             0.0   0.1 2.43G 16.4M   284 yuqibing     0 R   0:12.73 /usr/libexec/lsd

                             0.0   0.1 3.46G 18.3M   285 yuqibing     0 R   1:55.30 /usr/libexec/trustd --agent

                             0.0   0.1 2.42G 13.4M   289 yuqibing     0 R   0:06.44 /System/Library/CoreServices/shar


Glances 会用一下几种颜色来代表状态:

  • 绿色:OK(一切正常)
  • 蓝色:CAREFUL(需要注意)
  • 紫色:WARNING(警告)
  • 红色:CRITICAL(严重)
Glances 的选项:
  • a – 对进程自动排序
  • c – 按 CPU 百分比对进程排序
  • m – 按内存百分比对进程排序
  • p – 按进程名字母顺序对进程排序
  • i – 按读写频率(I/O)对进程排序
  • d – 显示/隐藏磁盘 I/O 统计信息
  • f – 显示/隐藏文件系统统计信息
  • n – 显示/隐藏网络接口统计信息
  • s – 显示/隐藏传感器统计信息
  • y – 显示/隐藏硬盘温度统计信息
  • l – 显示/隐藏日志(log)
  • b – 切换网络 I/O 单位(Bytes/bits)
  • w – 删除警告日志
  • x – 删除警告和严重日志
  • 1 – 切换全局 CPU 使用情况和每个 CPU 的使用情况
  • h – 显示/隐藏这个帮助画面
  • t – 以组合形式浏览网络 I/O
  • u – 以累计形式浏览网络 I/O
  • q – 退出(‘ESC‘ 和 ‘Ctrl&C‘ 也可以)

更多glances的选项,可以用

man glances来参看。
远程使用 Glances
glances -s

Define the password for the Glances server
Password: 
Password (confirm): 
Glances server is running on 0.0.0.0:61209

当你执行了glances -s命令后,会让你为 Glances 服务器设置密码。当你设置完毕,你将看到 “Glances server is running on 0.0.0.0:61209” (Glances 服务器正在 0.0.0.0 的 61209 端口运行)的消息。当 Glances 服务器启动后,到本地执行下面的命令来指定服务器IP地址或主机名以链接。

注:这里的172.16.27.56是我 Glances 服务器的 IP 地址。glances -c -P 172.16.27.56

下面是一些在使用服务器/客户端模式时必须知道的事情:

  • 在服务器模式,你可以通过 -B 地址 来设置绑定地址,也可以通过 -p 端口 来绑定监听的 TCP 端口
  • 在客户端模式,你可以通过同样的 -p 端口 来指定服务器端口
  • 默认的绑定地址是 0.0.0.0,但这么做会监听所有网络接口的指定端口
  • 在服务器/客户端模式下,限制的阀值将由服务器的设置决定
  • 你也可以在命令行下用过 -P 密码 的方式来为服务器端设置一个密码

pmap

可以根据进程查看进程相关信息占用的内存情况,(进程号可以通过ps查看)如下所示:

  $ pmap -d 5647

Linux中使用free来查看内存

  $ free

             total       used       free     shared    buffers     cached
Mem:       8193564    7868388     325176          0     198848    2645932
-/+ buffers/cache:    5023608    3169956
Swap:            0          0          0


如何看额定值:

cat /proc/meminfo

proc:

/proc是Linux的一个伪文件系统,存储的是当前内核运行状态的一系列特殊文件,用户可以通过这些文件查看有关系统硬件及当前正在运行进程的信息,甚至可以通过更改其中某些文件来改变内核的运行状态。 

/proc/cpuinfo   cpu的相关信息

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值