Showing posts with label linux/unix. Show all posts
Showing posts with label linux/unix. Show all posts

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.


Friday, January 20, 2012

Editing Text Files With Vim Editor


Here are some of the fundamental things you'll need to do when you edit a document in vi.

Starting vi

To start vi, just type the command
vi
to the UNIX shell. If you want vi to start with a file already loaded into a buffer, type
vi <filename>
where <filename> is the name of the file you want to edit.

Quitting vi

To exit vi and return to the UNIX shell, type :q. If you have made changes to the buffer since the last time you saved it to disk, vi will say "No write since last change (":quit!" overrides)". Type :q! to exit without saving or :wq to exit with saving.

Getting help

vi does not have an on-line help system.You can temporarily exit to the shell and see the man page by typing the command :!man vi.
Vim editor has 3 mode:
Command mode: Cursor movement, change, delete, yank, put, search
Insert mode: type in new text, return to command mode with <ESC>
Ex mode: configuring, exiting, saving, search and repalce

Cursor motion

In addition to basic cursor motion, vi provides some other handy cursor motion functions:
  • (number zero) or ^ (Shift-6) moves the cursor to the start of the current line.
  • $ moves the cursor to the end of the current line.
  • w moves the cursor forward to the next word.
  • b moves the cursor back to the previous word.
  • 1G moves the cursor to the start of the buffer. *
  • G moves the cursor to the end of the buffer. *
  • #G moves to the line where # is the line number.
  • Control-F moves the cursor forward one screen.*
  • Control-B moves the cursor backward one screen.*
  • Control-D moves the cursor forward one half screen.*
  • Control-U moves the cursor backward one half screen.*
Here are some ways to search for a text string which will reposition the cursor. Wild cards include . (period) to match a single character and * to match any string:
  • /x searches forward for string x.*
  • searches forward for next occurence of found text.*
  • ?x searches backward for string x.*
  • N searches backward for previous occurence of found text.*
Command marked with asterisk (*) can also be used with the more utility to view files.

Inserting and deleting text

Deleting text is easy but neither the Backspace nor Delete key will delete a character. Here are some ways to delete text:
  • x deletes forward one character.
  • deletes backward one character.
  • or d$ deletes from the point to the end of the line.
  • dw deletes forward one word.
  • dd deletes one line.
  • #dd deletes multiple lines where # is the number of lines to delete

Cutting and pasting text regions

Changing text

Here are some ways to replace text using c (change) and r (replace) commands:
  • cw allows the current word to be replaced until terminated with Escape.
  • cc allows the current line to be replaced until terminated with Escape.
  • C or c$ allows the rest of the line to be replaced until terminated with Escape.
  • r allows the current character to be replaced by the next character that is typed.
  • allows all text to be replaced until terminated with Escape.

Undoing changes

It is possible to undo the change you have made to a file by entering the command u.