Home > Computing, Linux > Useful linux console system monitoring commands

Useful linux console system monitoring commands

December 9th, 2008 Leave a comment Go to comments

There are lots of commands available to manage a linux computer. So many in fact, that I decided to make this list as a reference for future use. I hope this overview will help some other people too.

Not all of these commands are included in the standard installation of linux. If you need them install them through the package manager of your distro. Most of the included images are from a barely loaded webserver, and some are from a medium loaded webserver. 

top
Top is the command I use most to check the current status on my machines. It shows a screen most like the processes list in the windows task manager. In the header it displays the current system time, system up-time, number of logged in users, load averages, number of processes and their status, physical memory usage and swap memory usage. You can change the refresh interval from the default 3 seconds by pressing “s”. The top command defaults to sorting by CPU usage. Press “F” to change the order of the rows. You have to select the column you want to sort by pressing its associated letter from the table that pops up after pressing “F”. To add or remove columns, press “f”. There are many more useful options for the top screen. For example the option to kill processes, or re-nice them to a different priority. Exit top by pressing “q”. To see al the available options, press “h”. 

The default screen of the top command.

The default screen of the top command.

 

 

iostat
Iostat gives you vital info about the filesystem usage. It also gives some info about CPU usage. “iostat -d” will display only the device report in kilobytes. To run this command in interval, add the time between reports in seconds and optionally how many reports (iostat -dk 3 10, 10 reports at 3 second intervals).  It will continu unhindered if you do not specify the number of reports. Exit iostat with “ctrl-c” in that case.

If you have network filesystem shares (NFS) you can check their statistics with “iostat -n”. All speeds are in blocks/second. These blocks represent sectors on the harddrive. To view the statistics in kilobytes/second or megabytes/second use the options “k” and “m” respectively.

iotop
Iotop is a top like application to show i/o usage. This is very useful when you want to look up which processes put the most load on the filesystem. The “left en right arrow keys” can be used to selected the sorting column. To change the ordering from ascending to descending and back use the “r” key. Exit iotop with the “q” key.

The default iotop screen.

The default iotop screen.

 

 

 

 

 

ps
Shows a list of currently running processes. I mostly use this command to easily look up processes by piping the output of ps to grep. I usually use “ps -ef” to give me full overview using the standard syntax. To look up a process use “ps -ef | grep <process name>”. More about redirecting output from stdout to a different place can be found in my post Basic linux administration with the console (which I’m currently writing so the link may be broken).

sar
Sar is a versatile system management application. It is a front end to the activity counters in linux and it can also read from files. I don’t have experience with sar so I’ll leave this one for you to find out.

vmstat
Vmstat gives you info about the virtual memory (processes, memory, paging, block IO, traps, and cpu activity). To run it at an interval, use “vmstat <delay in seconds> <optional number of reports>. Exit with “ctrl+c”.

sa
Statistics about previously executed commands. This can be accessed by command name, or by username. This command needs to be initialized to record and summarize the commands first. I also don’t use this one so I’ll leave it at that.

apachetop
Apachetop is a command useful for keeping an eye on apache requests and transfer speeds. It watches the apache access log to generate its statistics. You can specify a different logfile with “apachetop -f <logfile>”. You can specify multiple -y options to watch multiple logfiles at once. Exit by pressing “q”.

The apachetop statistics screen.

The apachetop statistics screen.

mytop
Mytop is a top variant to check the processlist of your MySQL server. Unfortunately it cannot accept a password through a password input line like the mysql commands do, but you have to specify it on the commandline. Make sure you delete your command line history with “history -c” after using this command. To use mytop use this command: “mytop -d <database> -u <user> -p <password>”.

The default mytop screen.

The default mytop screen.

mysqlreport
Mysqlreport is a very useful mysql server optimization tool. It analyzes the server and outputs a detailed report with which you can check or improve on the servers health. The command can be downloaded from hackmysql.  The manual for this tool, and what all the values mean can be found in their guide.

iftop
Iftop is a top variant to monitor the network interfaces. It displays al connections and current bandwidth. DNS name resolving can be disabled by using the “-n” option, or pressing the “r” key in iftop. To specify a different interface use the “-i <interfacename, eth0 for example>” option. You can exit iftop with the “q” key.

The iftop default console.

The iftop default console.

mpstat
This command shows info about all the cores and/or processors in the machine.  You can show a combines status report, or by each core/processor seperately. It gives a bit more depth of information than the other commands. To put this command in an interval use “mpstat <optional time between reports in seconds>”. This shows all cores/processors. If you want to display a single core or processor use “mpstat -P <core/processor number> <optional interval in seconds>”. Press “ctrl+c” to exit mpstat.

The default mpstat console screen with an interval of 1 second.

The default mpstat console screen with an interval of 1 second.

free
Free displays the amount of free and used memory. I don’t think this one is particularly useful because this info can be found in other statistical commands too. It displays the values in kilobytes by default. To run this report with an interval use the command “free -s <interval in seconds>”. Again, exit with “ctrl-c”.

lsof
Lsof will show a list of open files. This command is simmilar to ps.

df
Df shows disc usage for al partitions that are currently mounted. To show the values in human readable form, use “df -h”

pstree
Shows the process tree with all parent and child processes.

tload
I rarely use tload, it shows the current load avarages. Top will do just fine for this purpose.

  1. No comments yet.
  1. No trackbacks yet.