Skip to content

Performance monitor and tracing command on Linux

ifconfig

网卡数目、ip地址、Mac地址、MTU大小

eth0      Link encap:Ethernet  HWaddr 00:0d:3a:50:12:e9
          inet addr:10.0.0.4  Bcast:10.0.0.255  Mask:255.255.255.0
          inet6 addr: fe80::20d:3aff:fe50:12e9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:129949 errors:0 dropped:0 overruns:0 frame:0
          TX packets:104544 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:93502262 (93.5 MB)  TX bytes:17135376 (17.1 MB)

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:113017627 errors:0 dropped:0 overruns:0 frame:0
          TX packets:113017627 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:15337780680 (15.3 GB)  TX bytes:15337780680 (15.3 GB)

w

当前用户及其运行程序,1分钟、5分钟、10分钟平均负载

 10:19:04 up  3:34,  2 users,  load average: 0.00, 0.02, 0.05
USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHAT
ubuntu   pts/0    104.210.36.135   10:14    0.00s  0.08s  0.02s sshd: ubuntu [priv]
ubuntu   pts/1    104.210.36.135   07:25    2:53m  1:49   0.02s sshd: ubuntu [priv]

df

磁盘用量,挂载目录、总容量、使用量等

df -h
Filesystem      Size  Used Avail Use% Mounted on
udev             14G   12K   14G   1% /dev
tmpfs           2.8G  404K  2.8G   1% /run
/dev/sda1        29G  1.8G   26G   7% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none             14G     0   14G   0% /run/shm
none            100M     0  100M   0% /run/user
none             64K     0   64K   0% /etc/network/interfaces.dynamic.d
/dev/sdb1        55G   52M   53G   1% /mnt

查看i节点使用量

df -Ti
Filesystem     Type      Inodes IUsed   IFree IUse% Mounted on
udev           devtmpfs 3600253   435 3599818    1% /dev
tmpfs          tmpfs    3601470   372 3601098    1% /run
/dev/sda1      ext4     1925120 89929 1835191    5% /
none           tmpfs    3601470     2 3601468    1% /sys/fs/cgroup
none           tmpfs    3601470     1 3601469    1% /run/lock
none           tmpfs    3601470     1 3601469    1% /run/shm
none           tmpfs    3601470     2 3601468    1% /run/user
none           tmpfs    3601470     1 3601469    1% /etc/network/interfaces.dynamic.d
/dev/sdb1      ext4     3670016    12 3670004    1% /mnt

ps

查看进程

ps auxfww

pmap

查看某进程调用各种库占用的内存

pmap -d PID

内存占用查看

free -h
             total       used       free     shared    buffers     cached
Mem:           27G       1.6G        25G       448K        39M       1.1G
-/+ buffers/cache:       508M        26G
Swap:           0B         0B         0B

查看swap的I/O

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
 1  0      0 27127940  40624 1122280    0    0     2    29  171  369  1  2 97  0  0
 0  0      0 27127644  40624 1122280    0    0     0     0   27   92  0  0 100  0  0
 0  0      0 27127768  40624 1122312    0    0     0     0   22  109  0  0 100  0  0
 0  0      0 27127768  40624 1122312    0    0     0     0   18   49  0  0 100  0  0
 0  0      0 27127800  40624 1122312    0    0     0     0   21  103  0  0 100  0  0

网络相关数据查看

查看TCP、UDP端口及其相关程序

netstat -tunlp
netstat -tan

磁盘I/O查看

iostat -x
avg-cpu:  %user   %nice %system %iowait  %steal   %idle
           1.05    0.00    1.91    0.06    0.00   96.98

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
scd0              0.00     0.00    0.01    0.00     0.02     0.00     7.82     0.00    0.86    0.86    0.00   0.86   0.00
sda               0.00     2.51    0.57    3.85    14.26   223.74   107.62     0.04   10.13    2.82   11.21   1.17   0.52
sdb               0.00     2.36    0.06    0.15     0.40  4196.06 39096.28     0.00   16.67    0.16   23.59   0.21   0.00

dstat

CPU、磁盘、网络、系统性能实时监控采集

You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw
  1   1  97   0   0   0|  14k 4206k|   0     0 |   0     0 |1248  2698
  0   0 100   0   0   0|   0     0 | 264B 1284B|   0     0 |  20   125
  0   0 100   0   0   0|   0     0 |  66B  370B|   0     0 |  24    75
  0   0 100   0   0   0|   0     0 | 198B  934B|   0     0 |  20    86
  0   0 100   0   0   0|   0     0 | 198B  758B|   0     0 |  22    81
  0   0 100   0   0   0|   0    12k| 132B  500B|   0     0 |  20    69

mtr

集成ping和traceroute的工具,查看请求、丢包情况等。

mtr -r -c 10 -i 2 www.google.com
Start: Sat Feb  6 10:59:50 2016
HOST: UBUNTU                      Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- ???                       100.0    10    0.0   0.0   0.0   0.0   0.0
  2.|-- ???                       100.0    10    0.0   0.0   0.0   0.0   0.0
  3.|-- ???                       100.0    10    0.0   0.0   0.0   0.0   0.0
  4.|-- ???                       100.0    10    0.0   0.0   0.0   0.0   0.0
  5.|-- ???                       100.0    10    0.0   0.0   0.0   0.0   0.0
  6.|-- 104.44.8.196               0.0%    10    3.5   3.0   1.8   3.7   0.3
  7.|-- ae69-0.pao-96cbe-1a.ntwk.  0.0%    10    1.3   1.7   1.2   4.3   0.8
  8.|-- 72.14.194.139              0.0%    10    1.2   1.3   1.2   1.8   0.0
  9.|-- 209.85.240.114             0.0%    10    1.6   1.6   1.5   1.6   0.0
 10.|-- 74.125.37.43               0.0%    10    1.7   1.7   1.7   1.9   0.0
 11.|-- nuq04s30-in-f4.1e100.net   0.0%    10    1.6   1.6   1.6   1.7   0.0

iptraf

网卡实时状态监控

网卡发包统计:iptraf -z eth0

网卡连接IP的实时带宽流量:iptraf -i eth0

网卡实时进出带宽:iptraf -d eth0

tcpdump

-i ANY :监听某个网口上的流量
-n:不解析主机名
-nn:不解析主机名、端口名
-X:同时用hex和ASCII两种格式显示包的内容
-XX:在-X基础上,显示以太网包头信息
-v/-vv/-vvv:显示更多内容
-c:获取指定数目包
-s:指定获取包的大小
-S:打印序列号
-e:获取以太网报文头
-q:显示部分协议信息
-E:指定密钥解密
-w:写入文件

strace

strace -p PID

跟踪进程执行过程中系统调用和信号情况

Disclaimer
  1. License under CC BY-NC 4.0
  2. Copyright issue feedback: dig +short txt issue.imzye.com
  3. Not all the commands and scripts are tested in production environment, use at your own risk
  4. No privacy information is collected here
Buy Me a Coffee