Linux OS server commands for hardware info performance network monitoring

Brief introduction to Linux OS server

Linux provides a set of commands via terminal interface to gather hardware info as well as to monitor performance of the system. These commands are quite handy for initial set up of the system or any performance testing. Many commands can provide a large set of  information while some commands are quite specific.

Linux OS server commands for hardware info

Find number of Physical Processors on linux server

This command returns number of physical processors on the machine.

$ grep 'physical id' /proc/cpuinfo | sort | uniq | wc -l 

Find number of Virtual Processors on linux server

This command returns number of virtual processors on the machine.

$ grep ^processor /proc/cpuinfo | wc -l 

Find number of cores on linux server

This command returns number of cores on the machine.

$ grep 'cpu cores' /proc/cpuinfo 
cpu cores       : 2

Here “2” indicates the two physical processors are dual-core, resulting in 4 virtual processors. If “1” was returned, the two physical processors are single-core. If the processors are single-core, and the number of virtual processors is greater than the number of physical processors, the CPUs are using hyper-threading. Hyper-threading is supported if ht is present in the CPU flags and you are using an SMP kernel. Also a 64-bit processor will have lm (“long mode”) in the flags section of cpuinfo. A 32-bit processor will not.

Important points to note:

  1. Any cpu with the same physical id are threads or cores in the same physical socket.
  2. Physical id and core id are not necessarily consecutive but they are unique. Any cpu with the same core id are hyperthreads in the same core. (See “ht” flag under flags section in file /proc/cpuinfo)

For more details see How do I detect a dual-core CPU
Linux commands for hardware info and performance monitoring

Linux OS server commands for performance monitoring

For Linux OS server performance monitoring the areas of interest include :

  1. Central Processing Unit usage
  2. Physical memory usage
  3. Virtual memory usage
  4. Disk utilization

Linux Disk Utilization Commands

linux iostat command

$ iostat -d -x 5 3
  • -d : Display the device utilization report (d == disk)
  • -x : Display extended statistics including disk utilization
  • interval : It is time period in seconds between two samples . iostat 2 will give data at each 2 seconds interval.
  • count : It is the number of times the data is needed . iostat 2 5 will give data at 2 seconds interval 5 times

If svctm, %util, r/s or w/s are high:

  • Get high speed disk and controller for file system
  • Tune software or application or kernel or file system for better disk utilization
  • Use RAID array to spread the file system

CPU Utilization Commands

Following commands help identify the CPU utilization.

linux Top command

To view the top CPU consuming processes use the  top command. To start top , type top (shown below) in a terminal window. The top command then displays a text screen listing the current processes, arranged in the order of CPU usage, along with various other information, such as memory and swap-space usage.

$ top 
top - 20:55:28 up 2 min,  1 user,  load average: 0.47, 0.33, 0.13 
Tasks:  48 total,   1 running,  47 sleeping,   0 stopped,   0 zombie 
Cpu(s): 11.9%us, 30.1%sy,  0.0%ni, 57.7%id,  0.2%wa,  0.0%hi,  0.2%si,  0.0%st
Mem:    515872k total,   170536k used,   345336k free,    19340k buffers 
Swap:   262120k total,        0k used,   262120k free,    77652k cached 
  1 root      15   0  2036  708  604 S  0.0  0.1   0:04.89 init
  1. The first line shows the current time, how long the system has been up, how many users are logged in, and three load averages — the average number of processes ready to run during the last 1, 5, and 15 minutes.
  2. The second line lists the total number of processes and the status of these processes.
  3. The third line shows CPU usage — what percentage of CPU time is used by user processes, what percentage by system (kernel) processes, and during what percentage of time the CPU is idle.
  4. The fourth line shows how the physical memory is being used — the total amount, how much is used, how much is free, and how much is allocated to buffers (for reading from the hard drive, for example).
  5. The fifth line shows how the virtual memory (or swap space) is being used — the total amount of swap space, how much is used, how much is free, and how much is being cached.
  6. PID The process ID of the process
  7. USER Username under which the process is running
  8. PR Priority of the process
  9. NI Nice value of the process — the value ranges from -20 (highest priority) to 19 (lowest priority) and the default is 0. (The nice value represents the relative priority of the process: the higher the value the lower the priority and the nicer the process — because it yields to other processes.)
  10. VIRT The total amount of virtual memory used by the process, in kilobytes
  11. RES Total physical memory used by a task (typically shown in kilobytes, but an m suffix indicates megabytes)
  12. SHR Amount of shared memory used by process
  13. S State of the process (S for sleeping, D for uninterruptible sleep, R for running, Z for zombies — processes that should be dead but are still running — or T for stopped)
  14. %CPU Percentage of CPU time used since last screen update
  15. %MEM Percentage of physical memory used by the process
  16. TIME+ Total CPU time the process has used since it started
  17. COMMAND Shortened form of the command that started the process

linux vmstat command

You can get summary information about the overall system usage with the vmstat utility. To view system usage information averaged over 5-second intervals, type the following command

$ vmstat 5 8 
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu---- 
r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa 
0  0      0 341388  22512  77752    0    0    27    11  100   82  1  1 98  0
  1. procs Number of processes and their types: r = processes waiting to run, b = processes in uninterruptible sleep, w = processes swapped out but ready to run.
  2. memory Information about physical memory and swap-space usage (all numbers in kilobytes): swpd = virtual memory used, free = free physical memory, buff = memory used as buffers, cache = virtual memory that’s cached
  3. swap Amount of swapping (the numbers are in kilobytes per second): si = amount of memory swapped in from disk, so = amount of memory swapped to disk
  4. io Information about input and output. (The numbers are in blocks per second where the block size depends on the disk device.) bi = rate of blocks sent to disk, bo = rate of blocks received from disk
  5. system Information about the system: in = number of interrupts per second (including clock interrupts), cs = number of context switches per second — how many times the kernel changed which process was running
  6. cpu Percentages of CPU time used: us = percentage of CPU time used by user processes, sy = percentage of CPU time used by system processes, id = percentage of time CPU is idle, wa = time spent waiting for input or output (I/O). If wa time is large it means that there is disk bottleneck and therefore needs attention.

linux mpstat command

Collects and displays performance statistics for all logical CPUs in the system.

$ mpstat -P ALL

-P cpu | ALL Indicates the processor number for which statistics are to be reported. cpu is the processor number. Note that processor 0 is the first processor. The ALL keyword indicates that statistics are to be reported for all processors.

  1. CPU Processor number. The keyword all indicates that statistics are calculated as averages among all processors.
  2. %user Show the percentage of CPU utilization that occurred while exe- cuting at the user level (application).
  3. %nice Show the percentage of CPU utilization that occurred while exe- cuting at the user level with nice priority.
  4. %system Show the percentage of CPU utilization that occurred while exe- cuting at the system level (kernel). Note that this does not include the time spent servicing interrupts or softirqs.
  5. %iowait Show the percentage of time that the CPU or CPUs were idle dur- ing which the system had an outstanding disk I/O request.
  6. %irq Show the percentage of time spent by the CPU or CPUs to service interrupts.
  7. %soft Show the percentage of time spent by the CPU or CPUs to service softirqs. A softirq (software interrupt) is one of up to 32 enumerated software interrupts which can run on multiple CPUs at once.
  8. %idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
  9. intr/s Show the total number of interrupts received per second by the CPU or CPUs. A high number could mean issue with the devices.

linux sar (system activity report) command

The sar command writes to standard output the contents of selected cumulative activity counters in the Linux operating system.

$ sar -u 2 5 (for each 2 seconds. 5 lines are displayed)
$ iostat -xtc 5 3 (3 outputs every 5 seconds)

Network monitoring and utilization Commands on linux

Following commands report the network utilization.

$ netstat -i $ sar -n DEV

Memory leak Commands on linux

In order to be sure that there is no memory leak processes should be checked often. If there is consistent increase in RSS memory used between regular intervals then there could be a possible memory leak.

$ ps aux | grep


Related Posts