Skip to content

Performance monitor and tracing command in Linux

homepage-banner

ifconfig

Number of network cards, IP address, MAC address, MTU size

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

Current user and running programs, 1-minute, 5-minute, 10-minute load average

 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

Disk usage, mount directories, total capacity, usage, etc.

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

View inode usage

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

View processes

ps auxfww

pmap

View the memory occupied by the various libraries called by a process

pmap -d PID

Memory usage monitoring

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

View 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

View TCP, UDP ports and their related programs

netstat -tunlp
netstat -tan

View disk 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

Real-time monitoring and collection of CPU, disk, network, and system performance

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

A tool that integrates ping and traceroute, used to view request and packet loss situations, etc.

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

Real-time status monitoring of network cards

  • Network card packet statistics: iptraf -z eth0
  • Real-time bandwidth flow of network card connections to IP: iptraf -i eth0
  • Real-time input/output bandwidth of network card: iptraf -d eth0
  • Real-time statistics of network card connections to port: iptraf -p eth0

tcpdump

-i ANY :Listen to the traffic on a particular network interface
-n:Don't resolve hostnames
-nn:Don't resolve hostnames or port names
-X:Print packet contents in both hex and ASCII
-XX:Print packet contents in both hex and ASCII, including Ethernet header information
-v/-vv/-vvv:Increase the verbosity level
-c:Capture a specified number of packets
-s:Capture a specified number of bytes of each packet
-S:Print TCP sequence numbers
-e:Print Ethernet header information
-q:Print less protocol information
-E:Specify a decryption

strace

strace -p PID
Leave a message