Thursday, December 27, 2012

20 Linux System Monitoring Tools


Need to monitor Linux server performance? When a performance issue arises, there are 4 main areas to consider: CPU, Memory, Disk I/O, and Network. The commands discussed below are some of the most basic commands when it comes to system analysis and debugging server issues such as:
  1. Monitoring System Resource
  2. Monitoring Disks (storage) .
  3. Monitoring Users.
  4. Network bottlenecks.
1.Monitoring System Resource

1.1 Top – Linux Process Monitoring
The top will display a continually updating report of system resource usage. The top portion of the report lists information such as the system time, uptime, CPU usage, physical ans swap memory usage, and number of processes.
You can modify the output of top while is is running. If you hit an i, top will no longer display idle processes. Hit i again to see them again. Hitting M will sort by memory usage, S will sort by how long they processes have been running, and P will sort by CPU usage again.
In addition to viewing options, you can also modify processes from within the top command. You can use u to view processes owned by a specific user, k to kill processes, and r to renice them.
For more in-depth information about processes you can look in the /proc filesystem. In the /proc filesystem you will find a series of sub-directories with numeric names. These directories are associated with the processes ids of currently running processes. In each directory you will find a series of files containing information about the process.

1.2 Iostat – Input/Output Statistics
The iostat will display the current CPU load average and disk I/O information. This is a great command to monitor your disk I/O usage. IoStat is simple tool that will collect and show system input and output storage device statistics. This tool is often used to trace storage device performance issues including devices, local disks, remote disks such as NFS.

1.3 VmStat – Virtual Memory Statistics 
The vmstat command will provide a report showing statistics for system processes, memory, swap, I/O, and the CPU. These statistics are generated using data from the last time the command was run to the present. In the case of the command never being run, the data will be from the last reboot until the present.By default vmstat command is not available under Linux systems you need to install a package called sysstat that includes a vmstat progra.

1.4 Lsof – List Open Files
The lsof command will print out a list of every file that is in use. Since Linux considers everything a file, this list can be very long. However, this command can be useful in diagnosing problems. An example of this is if you wish to unmount a filesystem, but you are being told that it is in use. You could use this command and grep for the name of the filesystem to see who is using it.
Or suppose you want to see all files in use by a particular process. To do this you would use lsof -p -processid-.

1.5 ps - Process Status command
 The ps will provide you a list of processes currently running. There is a wide variety of options that this command gives you. A common use would be to list all processes currently running. To do this you would use the ps -ef command.
The first column shows who owns the process. The second column is the process ID. The Third column is the parent process ID. This is the process that generated, or started, the process. The forth column is the CPU usage (in percent). The fifth column is the start time, of date if the process has been running long enough. The sixth column is the tty associated with the process, if applicable. The seventh column is the cumulitive CPU usage (total amount of CPU time is has used while running). The eighth column is the command itself.


2. Monitoring Disks (storage) .

2.1 Df command
The df will show disk usage for all your mounted filesystems in 1K block. You can also use the -h to see the output in "human-readable" format. This will be in K, Megs, or Gigs depending on the size of the filesystem. In addition to space usage, you could use the -i option to view the number of used and available inodes.

2.2 The du command
To view usage by a directory or file you can use du. Unless you specify a file name du will act recursively. Or like the df I can use the -h and get the same output in "human-readable" form. For example: 

 
If you just want a summary of that directory you can use the -s option.

2.3 The Fdisk command
The fdisk command is a text-based utility for viewing and managing hard disk partitions on Linux. It’s one of the most powerful tools you can use to manage partitions.
fdisk -l commands lists the partitions on your system. To view all partitions of the /dev/sda hard disk
fdisk -l /dev/sda

3. Monitoring Users.


0 nhận xét:

Post a Comment