Linux Tools

Linux performance and Monitoring Tools

[root@rhel6server ~]# sar -b 1 3
Linux 2.6.32-131.0.15.el6.i686 (rhel6server) 07/31/2017 _i686_ (1 CPU)

10:26:23 PM tps rtps wtps bread/s bwrtn/s
10:26:24 PM 0.00 0.00 0.00 0.00 0.00
10:26:25 PM 0.00 0.00 0.00 0.00 0.00
10:26:26 PM 0.00 0.00 0.00 0.00 0.00
Average: 0.00 0.00 0.00 0.00 0.00

Network Packet Analyzer
[root@rhel6server ~]# tcpdump -A -i eth0
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
22:31:00.323017 ARP, Request who-has RHEL6CLIENT tell RHEL6SERVER, length 28
……….)i.<.............. 22:31:01.322651 ARP, Request who-has RHEL6CLIENT tell RHEL6SERVER, length 28 ..........)i.<.............. 2 packets captured 2 packets received by filter 0 packets dropped by kernel [root@rhel6server ~]# iostat Linux 2.6.32-131.0.15.el6.i686 (rhel6server) 07/31/2017 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 1.86 0.01 2.45 1.12 0.00 94.55 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 2.87 119.29 71.63 1136128 682178 scd0 0.01 0.05 0.00 452 0 [root@rhel6server ~]# [root@rhel6server ~]# iostat -p sda Linux 2.6.32-131.0.15.el6.i686 (rhel6server) 07/31/2017 _i686_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 1.90 0.01 2.46 1.12 0.00 94.51 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn sda 2.85 118.14 70.98 1136144 682594 sda1 0.06 0.50 0.00 4814 42 sda2 2.74 117.20 70.97 1127106 682552 sda3 0.04 0.31 0.00 3024 0 [root@rhel6server ~]# Processor Statistics [root@rhel6server ~]# mpstat Linux 2.6.32-131.0.15.el6.i686 (rhel6server) 07/31/2017 _i686_ (1 CPU) 10:40:08 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 10:40:08 PM all 1.91 0.01 2.40 1.11 0.01 0.05 0.00 0.00 94.50 [root@rhel6server ~]# mpstat -P ALL Linux 2.6.32-131.0.15.el6.i686 (rhel6server) 07/31/2017 _i686_ (1 CPU) 10:41:03 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 10:41:03 PM all 1.90 0.01 2.39 1.11 0.01 0.05 0.00 0.00 94.52 10:41:03 PM 0 1.90 0.01 2.39 1.11 0.01 0.05 0.00 0.00 94.52 [root@rhel6server ~]# Execute every 1 sec for 3 times [root@rhel6server ~]# vmstat 1 3 procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 1211856 57996 581932 0 0 58 35 82 144 2 2 94 1 0 0 0 0 1211848 57996 581932 0 0 0 52 64 78 1 0 99 0 0 1 0 0 1211848 57996 581932 0 0 0 0 207 323 9 6 85 0 0 [root@rhel6server ~]# Process belongs to specific username [root@rhel6server ~]# ps -f -u root,avk | head -3 UID PID PPID C STIME TTY TIME CMD root 1 0 0 19:56 ? 00:00:01 /sbin/init root 2 0 0 19:56 ? 00:00:00 [kthreadd] [root@rhel6server ~]# Shows which Parent process forked Child process [root@rhel6server ~]# ps -e -o pid,args --forest | head -5 PID COMMAND 2 [kthreadd] 3 \_ [migration/0] 4 \_ [ksoftirqd/0] 5 \_ [migration/0] [root@rhel6server ~]# Display information about Physical RAM and swap memory of system [root@rhel6server ~]# free total used free shared buffers cached Mem: 2071588 860316 1211272 0 58216 581940 -/+ buffers/cache: 220160 1851428 Swap: 4161528 0 4161528 In MB and total memory [root@rhel6server ~]# free -mto total used free shared buffers cached Mem: 2023 840 1182 0 56 568 Swap: 4063 0 4063 Total: 6087 840 5246 [root@rhel6server ~]# free -mt total used free shared buffers cached Mem: 2023 840 1182 0 56 568 -/+ buffers/cache: 214 1808 Swap: 4063 0 4063 Total: 6087 840 5246 [root@rhel6server ~]# [root@rhel6server ~]# top | head top - 22:55:50 up 2:59, 3 users, load average: 0.01, 0.06, 0.05 Tasks: 177 total, 1 running, 176 sleeping, 0 stopped, 0 zombie Cpu(s): 2.2%us, 2.5%sy, 0.0%ni, 94.2%id, 1.0%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 2071588k total, 860872k used, 1210716k free, 58360k buffers Swap: 4161528k total, 0k used, 4161528k free, 581952k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2221 root 20 0 72728 26m 9372 S 9.5 1.3 4:45.66 Xorg 1 root 20 0 2852 1412 1200 S 0.0 0.1 0:01.53 init 2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd [root@rhel6server ~]# top -u avk | head top - 22:58:35 up 3:01, 3 users, load average: 0.05, 0.06, 0.04 Tasks: 177 total, 1 running, 176 sleeping, 0 stopped, 0 zombie Cpu(s): 2.2%us, 2.5%sy, 0.0%ni, 94.1%id, 1.0%wa, 0.0%hi, 0.1%si, 0.0%st Mem: 2071588k total, 861004k used, 1210584k free, 58464k buffers Swap: 4161528k total, 0k used, 4161528k free, 581980k cached PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 2445 avk 20 0 38928 3500 2972 S 0.0 0.2 0:00.03 gnome-keyring-d 2454 avk 20 0 49660 10m 8804 S 0.0 0.5 0:00.48 gnome-session 2463 avk 20 0 3588 732 520 S 0.0 0.0 0:00.00 dbus-launch [root@rhel6server ~]# Displays Memory map of given Process [root@rhel6server ~]# pmap 2482 | head -5 2482: /usr/libexec/gconfd-2 00110000 92K r-x-- /lib/libpthread-2.12.so 00127000 4K r---- /lib/libpthread-2.12.so 00128000 4K rw--- /lib/libpthread-2.12.so 00129000 8K rw--- [ anon ] [root@rhel6server ~]# Additional information about memory maps: [root@rhel6server ~]# pmap -x 2482 | head -5 2482: /usr/libexec/gconfd-2 Address Kbytes RSS Dirty Mode Mapping 00110000 92 52 0 r-x-- libpthread-2.12.so 00127000 4 4 4 r---- libpthread-2.12.so 00128000 4 4 4 rw--- libpthread-2.12.so [root@rhel6server ~]# Displays network related information [root@rhel6server ~]# netstat | head Active Internet connections (w/o servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 1 0 RHEL6SERVER:32908 a60-254-131-55.deploy.:http CLOSE_WAIT Active UNIX domain sockets (w/o servers) Proto RefCnt Flags Type State I-Node Path unix 2 [ ] DGRAM 8829 @/org/kernel/udev/udevd unix 2 [ ] DGRAM 12983 @/org/freedesktop/hal/udev_event unix 6 [ ] DGRAM 27116 /dev/log unix 3 [ ] STREAM CONNECTED 36774 @/tmp/dbus-wonsjcx0dP unix 3 [ ] STREAM CONNECTED 36773 [root@rhel6server ~]# Listing both Listening and Non listening Ports [root@rhel6server ~]# netstat -a | head Active Internet connections (servers and established) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 *:ftp *:* LISTEN tcp 0 0 *:ssh *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN tcp 0 0 localhost:smtp *:* LISTEN tcp 0 0 *:sunrpc *:* LISTEN tcp 1 0 RHEL6SERVER:32908 a60-254-131-55.deploy.:http CLOSE_WAIT tcp 0 0 *:ssh *:* LISTEN tcp 0 0 localhost:ipp *:* LISTEN [root@rhel6server ~]# On which port a program is running [root@rhel6server ~]# netstat -ap | grep ssh tcp 0 0 *:ssh *:* LISTEN 1954/sshd tcp 0 0 *:ssh *:* LISTEN 1954/sshd unix 2 [ ACC ] STREAM LISTENING 17135 2445/gnome-keyring- /tmp/keyring-yGdxbp/socket.ssh [root@rhel6server ~]# [root@rhel6server ~]# netstat -an | grep ':39065' udp 0 0 0.0.0.0:39065 0.0.0.0:* [root@rhel6server ~]# Debugging and troubleshooting of executables [root@rhel6server ~]# strace ls execve("/bin/ls", ["ls"], [/* 20 vars */]) = 0 brk(0) = 0x9e52000 mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7773000 access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY) = 3 fstat64(3, {st_mode=S_IFREG|0644, st_size=52708, ...}) = 0 mmap2(NULL, 52708, PROT_READ, MAP_PRIVATE, 3, 0) = 0xb7766000 close(3) Display Specific System call [root@rhel6server ~]# strace -e open ls open("/etc/ld.so.cache", O_RDONLY) = 3 open("/lib/libselinux.so.1", O_RDONLY) = 3 open("/lib/librt.so.1", O_RDONLY) = 3 open("/lib/libcap.so.2", O_RDONLY) = 3 open("/lib/libacl.so.1", O_RDONLY) = 3 open("/lib/libc.so.6", O_RDONLY) = 3 open("/lib/libdl.so.2", O_RDONLY) = 3 open("/lib/libpthread.so.0", O_RDONLY) = 3 open("/lib/libattr.so.1", O_RDONLY) = 3 open("/usr/lib/locale/locale-archive", O_RDONLY|O_LARGEFILE) = 3 open(".", O_RDONLY|O_NONBLOCK|O_LARGEFILE|O_DIRECTORY|O_CLOEXEC) = 3 1 anaconda-ks.cfg install.log install.log.syslog nmapexclude.txt packettrace.txt shellscript testmsg [root@rhel6server ~]# List of open files [root@rhel6server ~]# lsof | head -5 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME init 1 root cwd DIR 8,2 4096 2 / init 1 root rtd DIR 8,2 4096 2 / init 1 root txt REG 8,2 145180 524352 /sbin/init init 1 root mem REG 8,2 122232 659247 /lib/libgcc_s-4.4.5-20110214.so.1 [root@rhel6server ~]# [root@rhel6server ~]# lsof -u avk | head -5 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME gnome-key 2445 avk cwd DIR 8,2 4096 266148 /var/gdm gnome-key 2445 avk rtd DIR 8,2 4096 2 / gnome-key 2445 avk txt REG 8,2 701524 796500 /usr/bin/gnome-keyring-daemon (deleted) gnome-key 2445 avk mem REG 8,2 133136 659453 /lib/libpthread-2.12.so [root@rhel6server ~]# List of users of particular file [root@rhel6server bin]# lsof /bin/bash COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME bash 2658 avk txt REG 8,2 877480 4902 /bin/bash bash 2685 root txt REG 8,2 877480 4902 /bin/bash bash 6266 avk txt REG 8,2 877480 4902 /bin/bash [root@rhel6server bin]# who logged on [root@rhel6server ~]# w 23:32:16 up 3:35, 3 users, load average: 0.23, 0.10, 0.02 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT avk tty1 :0 11:11 12:21m 6:39 0.09s pam: gdm-password avk pts/0 :0.0 11:12 0.00s 0.62s 29.18s /usr/bin/gnome-terminal -x /bin/sh -c cd '/home/avk/Desktop' && exec $SHELL -l avk pts/1 :0.0 22:30 1:01m 0.02s 0.02s bash [root@rhel6server ~]# [root@rhel6server ~]# uptime 23:32:58 up 3:36, 3 users, load average: 0.30, 0.13, 0.03 [root@rhel6server ~]# Socket Statistics [root@rhel6server ~]# ss -l | head -5 Recv-Q Send-Q Local Address:Port Peer Address:Port 0 32 *:ftp *:* 0 128 :::ssh :::* 0 128 *:ssh *:* 0 128 127.0.0.1:ipp *:* [root@rhel6server ~]# [root@rhel6server ~]# ss -o state established Recv-Q Send-Q Local Address:Port Peer Address:Port [root@rhel6server ~]# [root@rhel6server ~]# ss -s Total: 703 (kernel 720) TCP: 11 (estab 0, closed 1, orphaned 0, synrecv 0, timewait 0/0), ports 6 Transport Total IP IPv6 * 720 - - RAW 0 0 0 UDP 8 6 2 TCP 10 6 4 INET 18 12 6 FRAG 0 0 0 [root@rhel6server ~]#