Useful Unix Commands and Tips - Part 6
Let us learn about tools that can help in troubleshooting performance related problems:
1) top: Top provides statistics about cpu, memory utilization, load averages, resident memory, virtual memory etc. The screen refreshes automatically.
i) top u oracle to see all the processes initiated by user oracle.ii) Press ‘1’ to see the individual cores.iii) top -p <pid> : To monitor only processes with a given process id.iv) top -H -p <pid>: Show all threads.We can press H on top output screen as well to get thread info.v) -b Batch mode. Useful for sending output from top to other programs or to a file.vi) To sort memory usage in ‘top’ output, press ‘SHIFT+m’
vii) List of process are sorted and displayed by default based on CPU utilization. We can change it by pressing “<” or “>”, sort column changes accordingly.
top command consumes reasonable cpu. So, don’t run too many top sessions.
2) htop: htop is similar to top but it has better display of output with colors. Most of the distributions don’t come with htop installed.
3) uptime: Gives load averages and time since OS has been booted. Load average gives quick snapshot of the load on the system.
4) vmstat: It gives key server stats like memory, cpu and io.
5) mpstat: Prints cpu time breakdown by cpu.
6) pidstat: Prints memory, disk and cpu utilization per process. We can print stats per thread as well.
i) pidstat by default displays cpu stats.
pidstat 1 # Prints cpu stats for every 1 second
ii) To display disk stats of a process for every 1 sec.
pidstat -p <pid>-d 1
iii) To display paging activity for every 1 sec.pidstat -p 23493 -r 1iv) To display thread activities for every second:
pidstat -t -p <pid> 1
pidstat -t -d <pid>1
v) To display all thread statistics in a single line:
pidstat -rudt -h -p <pid>
vi) To find per thread cpu:
pidstat -tu -p <pid>
7) iostat: Displays disk device stats.
8) sar: It is a versatile tool. We can gets stats for cpu, memory, network, disk etc. One other useful feature is it stores historic reports at /var/log/sa.
9) free: This command displays memory details like total memory, free memory, swap utilization, memory used by cache and buffer.
References:
https://medium.com/netflix-techblog/linux-performance-analysis-in-60-000-milliseconds-accc10403c55
Comments
Post a Comment