Check all articles
Commands to monitor services in CentOS 7
In the same way, we write our article Commands to monitor services on Solaris, now it is the turn of services in Linux. Since Linux is an Unix-like operating system, many of the names of the commands (and the corresponding syntax) are very similar with Solaris. This article is a guide with the most frequently used commands to monitor services and resources in CentOS. At least, the commands that I often use.
If you need a server with CentOS 7 to do your own lab and test ... check the article Installation of CentOS 7.
The commands to monitor services are listed below:
How to look for help
It is very important before using any command to know its functionality together with the parameters it supports. For that, we use the man utility with the name of the command that we want to know in detail. For example, if we want to know about the shutdown command, we write:
The man command also allows you to search inside all the help entries that its documentation has, by adding the -k (in lowercase) parameter with a "keyword" ... search for matches over entries. Using the -K (in upper case) parameter we will find the keyword in the description of the commands with matching in their documentation in an iterative way:
$man -k keyword
$man -K keyword
It is recommended that for each command that we are going to learn in this article, verify its documentation using the man command to fully cover the parameters that these commands accept. Consider this task for improving our learning process of CentOS 7.
Know the server
The following commands allow us to obtain general information about the server that we are going to check.
Get the date/time of the system.
Obtain the operating system version.
Obtain the full version of the operating system, processor architecture and server name.
Get the name of the server.
Obtain server identification.
Know the total physical memory.
$grep MemTotal /proc/meminfo
To know the total physical memory, you could also use:
$lshw -c memory
Know the total swap memory.
$grep SwapTotal /proc/meminfo
Obtain the processor architecture.
$lscpu | grep Architecture
Know the number of processors, manufacturer, brand and cores per socket.
Verify CPU usage
We need to know how the CPU is being used as a whole.
The reporter of the system activity called sar, is a utility that lets us know how much CPU is being used at the user level (% user), at the user level with priority (% nice), at the system level (%system), when it is inactive waiting for the completion of an I/O operation (%iowait), used percentage by the hypervisor between virtual processors (%steal) and the percentage of available CPU (%idle). The result of this command is a snapshot (photograph) that indicates how our equipment is working; we will call this result "a sample". This command can receive 2 numeric parameters, the first is the interval in seconds that we want to obtain between sample and sample, the second is the quantity of these samples.
$sar 5 10
To have a continuous view of the use of resources for each system process we use the command top. This command give a continuous output, for stopping press the "q" key on your keyboard in order to quit.
Verify memory usage
To know the usage of memory let's execute the command vmstat that has as output the RAM memory, SWAP memory, blocks sent/received in the input/output, system and CPU operations. It is also obtained as a snapshot, the first parameter is the time in seconds of the interval between the samples and the second is the number of samples.
$vmstat 2 5
It is a utility to obtain metrics on the activity to the terminal, disks, tape and the use of the CPU. The result that shows is the number of transfers per second that were made to the device, indicates the KBytes in the input/output operations and the number of blocks in the input/output operations.
$iostat 5 10
Verify space usage
To verify the allocated, used and available space of our storage, execute:
Verify network usage
To show the status of the network, let's use netstat, this command accepts several parameters like those we have already seen for cpu and memory. Depending on what we want to check:
Statistics by protocol:
The status of network interfaces:
Continuous statistics every second:
To monitor open ports:
Verify running processes
To have a list with the detail of the processes/services that are being executed, use:
Check the error log
To verify recent messages that have been sent by the kernel, execute:
If we want to see all the messages registered in the system, execute:
$sudo more /var/log/messages
To have a continuous output of the last messages as they occur, execute:
$sudo tail -f /var/log/messages
Monitor in graphic mode
If we have access to the operating system's desktop, we can see information: about the system's processes, a graphic view of the resources and the usage of the file system. To display this screen, from the menu on the desktop select the option /Applications/System Tools/System Monitor.