เกริ่นนำ

ส่วนใหญ่แล้ว LinuxAdmin มักต้องใช้ command บ่อยครั้งเพื่อวิเคราะห์ประสิทธิภาพเครื่องหรือแก้ปัญหาต่างๆ เช่น Disk(Storage), CPU, Memory, Network เป็นต้น ลองมาดูกันว่า มีคำสั่งอะไรบ้างที่ Linux Admin ไม่ควรลืม

บทความนี้ แปลจาก http://www.cyberciti.biz/tips/top-linux-monitoring-tools.html

top - Process Activity Command

The top command provides several useful hot keys:

Hot Key Usage

  • t Displays summary information off and on.
  • m Displays memory information off and on.
  • A Sorts the display by top consumers of various system resources. Useful for quick identification of performance-hungry tasks on a system.
  • f Enters an interactive configuration screen for top. Helpful for setting up top for a specific task.
  • o Enables you to interactively select the ordering within top.
  • r Issues renice command.
  • k Issues kill command.
  • z Turn on or off color/mono

แหล่งข้อมูลเพิ่มเติมhttp://www.cyberciti.biz/tips/how-do-i-find-out-linux-cpu-utilization.html

vmstat - System Activity, Hardware and System Information

  • คำสั่งปกติ
    $ vmstat
  • Display Memory Utilization Slabinfo
    $ vmstat -m
  • Get Information About Active / Inactive Memory Pages
    $ vmstat -a

Field Description For Vm Mode

  • (a) procs is the process-related fields are:
    • r: The number of processes waiting for run time.
    • b: The number of processes in uninterruptible sleep.
  • (b) memory is the memory-related fields are:
    • swpd: the amount of virtual memory used.
    • free: the amount of idle memory.
    • buff: the amount of memory used as buffers.
    • cache: the amount of memory used as cache.
  • © swap is swap-related fields are:
    • si: Amount of memory swapped in from disk (/s).
    • so: Amount of memory swapped to disk (/s).
  • (d) io is the I/O-related fields are:
    • bi: Blocks received from a block device (blocks/s).
    • bo: Blocks sent to a block device (blocks/s).
  • (e) system is the system-related fields are:
    • in: The number of interrupts per second, including the clock.
    • cs: The number of context switches per second.
  • (f) cpu is the CPU-related fields are:
    • These are percentages of total CPU time.
    • us: Time spent running non-kernel code. (user time, including nice time)
    • sy: Time spent running kernel code. (system time)
    • id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
    • wa: Time spent waiting for IO. Prior to Linux 2.5.41, shown as zero.

แหล่งข้อมูลเพิ่มเติมhttp://www.cyberciti.biz/tips/linux-resource-utilization-to-detect-system-bottlenecks.html

w - Find Out Who Is Logged on And What They Are Doing

w command displays information about the users currently on the machine, and their processes.

$ w 
$ w klainfo

uptime - Tell How Long The System Has Been Running

$ uptime

ps - Displays The Processes

  • Show Long Format Output
    $ ps -Al
  • To turn on extra full mode (it will show command line arguments passed to process):
    $ ps -AlF
  • To See Threads ( LWP and NLWP)
    $ ps -AlFH
  • To See Threads After Processes
    $ ps -AlLm
  • Print All Process On The Server
    $ ps ax
    $ ps axu
  • Print A Process Tree
    $ ps -ejH
    $ ps axjf
    $ pstree
  • Print Security Information
    $ ps -eo euser,ruser,suser,fuser,f,comm,label
    $ ps axZ
    $ ps -eM
  • See Every Process Running As User Vivek
    $ ps -U vivek -u vivek u
  • Set Output In a User-Defined Format
    $ ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm
    $ ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm
    $ ps -eopid,tt,user,fname,tmout,f,wchan
  • Display Only The Process IDs of Lighttpd
    $ ps -C lighttpd -o pid=
  • OR
    $ pgrep lighttpd
  • OR
    $ pgrep -u vivek php-cgi
  • Display The Name of PID 55977
    $ ps -p 55977 -o comm=
  • Find Out The Top 10 Memory Consuming Process
    $ ps -auxf | sort -nr -k 4 | head -10
  • Find Out top 10 CPU Consuming Process
    $ ps -auxf | sort -nr -k 3 | head -10

free - Memory Usage

$ free

iostat - Average CPU Load, Disk Activity

$ iostat

sar - Collect and Report System Activity

  • The sar command is used to collect, report, and save system activity information. To see network counter, enter:
    $ sar -n DEV | more
  • To display the network counters from the 24th:
    $ sar -n DEV -f /var/log/sa/sa24 | more
  • You can also display real time usage using sar:
    $ sar 4 5

mpstat - Multiprocessor Usage

The mpstat command displays activities for each available processor, processor 0 being the first one. mpstat -P ALL to display average CPU utilization per processor:

$ mpstat

pmap - Process Memory Usage

The command pmap report memory map of a process. Use this command to find out causes of memory bottlenecks.

$ pmap -d PID

Sample Output

47394:   /usr/bin/php-cgi
Address           Kbytes Mode  Offset           Device    Mapping
0000000000400000    2584 r-x-- 0000000000000000 008:00002 php-cgi
0000000000886000     140 rw--- 0000000000286000 008:00002 php-cgi
00000000008a9000      52 rw--- 00000000008a9000 000:00000   [ anon ]
0000000000aa8000      76 rw--- 00000000002a8000 008:00002 php-cgi
000000000f678000    1980 rw--- 000000000f678000 000:00000   [ anon ]
000000314a600000     112 r-x-- 0000000000000000 008:00002 ld-2.5.so
000000314a81b000       4 r---- 000000000001b000 008:00002 ld-2.5.so
000000314a81c000       4 rw--- 000000000001c000 008:00002 ld-2.5.so
000000314aa00000    1328 r-x-- 0000000000000000 008:00002 libc-2.5.so
000000314ab4c000    2048 ----- 000000000014c000 008:00002 libc-2.5.so
.....
......
..
00002af8d48fd000       4 rw--- 0000000000006000 008:00002 xsl.so
00002af8d490c000      40 r-x-- 0000000000000000 008:00002 libnss_files-2.5.so
00002af8d4916000    2044 ----- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b15000       4 r---- 0000000000009000 008:00002 libnss_files-2.5.so
00002af8d4b16000       4 rw--- 000000000000a000 008:00002 libnss_files-2.5.so
00002af8d4b17000  768000 rw-s- 0000000000000000 000:00009 zero (deleted)
00007fffc95fe000      84 rw--- 00007ffffffea000 000:00000   [ stack ]
ffffffffff600000    8192 ----- 0000000000000000 000:00000   [ anon ]
mapped: 933712K    writeable/private: 4304K    shared: 768000K
The last line is very important:

  • mapped: 933712K total amount of memory mapped to files
  • writeable/private: 4304K the amount of private address space
  • shared: 768000K the amount of address space this process is sharing with others

/Proc file system - Various Kernel Statistics

$ cat /proc/cpuinfo
$ cat /proc/meminfo
$ cat /proc/zoneinfo
$ cat /proc/mounts

Additional Tools

A few more tools:

  1. nmap - scan your server for open ports.
  2. lsof - list open files, network connections and much more.
  3. ntop web based tool - ntop is the best tool to see network usage in a way similar to what top command does for processes i.e. it is network traffic monitoring software. You can see network status, protocol wise distribution of traffic for UDP, TCP, DNS, HTTP and other protocols.
  4. Conky - Another good monitoring tool for the X Window System. It is highly configurable and is able to monitor many system variables including the status of the CPU, memory, swap space, disk storage, - temperatures, processes, network interfaces, battery power, system messages, e-mail inboxes etc.
  5. GKrellM - It can be used to monitor the status of CPUs, main memory, hard disks, network interfaces, local and remote mailboxes, and many other things.
  6. vnstat - vnStat is a console-based network traffic monitor. It keeps a log of hourly, daily and monthly network traffic for the selected interface(s).
  7. htop - htop is an enhanced version of top, the interactive process viewer, which can display the list of processes in a tree form.
  8. mtr - mtr combines the functionality of the traceroute and ping programs in a single network diagnostic tool.
 
linux-system-monitoring.txt · Last modified: 2010/02/02 01:25 (external edit) · [Old revisions]
Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki