One of the most basic responsibilities of a DevOps engineer is to know how the various server instances under their control are performing. It forms a key part of DevOp techniques, driving infrastructure transparency and measuring the impact of changes, both prior to the change and after it has taken place.
There are many tools that are available for performance monitoring, from comprehensive Application Performance Monitoring (APM) tools through to focused monitoring for particular applications. We'll be covering these throughout the book; however, some of the best tools for basic server monitoring are already available with the operating system. Like most command-line tools, the performance monitoring tools that are shipped with the OS can be used standalone or can be chained with other commands to create complex tools.
The following tools are a part of the standard install of most Linux distributions and should be available with it, the exception being for sysstat
tools, which generally need to be installed. To install systat
tools on Ubuntu, issue the following command:
sudo apt-get install sysstat
This will make several performance-monitoring tools available, in particular sar
and mpstat
.
Let's gather basic OS statistics:
To gather basic information on your server, run the following command:
vmstat 1 99999
This should produce output similar to the following screenshot:
The command shows you the system statistics every second, for the number of times specified (
99999
in this instance).Note
By default, the columns in
vmstat
stand for the following:Procs – r
: Total number of processes waiting to runProcs – b
: Total number of busy processesMemory – swpd
: Used virtual memoryMemory – free
: Free virtual memoryMemory – buff
: Memory used as buffersMemory – cache
: Memory used as cache.Swap – si
: Memory swapped from disk (for every second)Swap – so
: Memory swapped to disk (for every second)IO – bi
: Blocks in (in other words) the blocks received from device (for every second)IO – bo
: Blocks out (in other words) the blocks sent to the device (for every second)System – in
: Interrupts per secondSystem – cs
: Context switchesCPU – us
,sy, id
,wa, st
: CPU user time, system time, idle time, and wait timeThe
vmstat
command can also be useful to show memory usage information, particularly active and inactive memory. To show vmstat information for memory usage, you can issue the following command:vmstat –a 1 999
This will give you an output similar to the following screenshot:
You can also reformat the output to be displayed in Mega Bytes using the following command:
vmstat –a –S M 1 999
The
vmstat
is not limited to gathering only CPU and RAM information; it can also be used to gather information for disks and other block devices. You can use the following command to gather basic disk statistics:vmstat -d 1 99999
This should produce an output that looks something like the following screenshot:
Sometimes, the output of
vmstat
can be slightly cluttered. You can widen the output using the -w options. This can be used on anyvmstat
command, such as the following:vmstat -d -w
Although
vmstat
is capable of displaying disk statistics, there is a tool that is better suited to this task in the shape ofiostat
. Theiostat
is able to display relatively detailed statistics of IO on a server in real time and can be used to reveal performance bottlenecks caused by disk devices.The following command will display basic statistics and just like
vmstat
, it will repeat the information every n seconds for n times, where n is a user-specified input:iostat 1 99999
This will give you an output similar to the following screenshot:
By default,
iostat
will show you the CPU information and disk information for all devices. You can drill into the information thatiostat
produces by using some simple options. For instance, you can show only information for devicesda
, and only disk statistics by using the following options:iostat -d -p sda 1 9999