Know how much an individual process or system-wide consume CPU or memory.
As a sysadmin, you often have to deal with an incident where the application is slow or unresponsive due to high CPU/memory/network utilization. If the server host just one process, then it’s easy to find out when process consumes all the resources. However, imagine a shared server where multiple services are running, and you need to find which one is eating all the resources.
There are many monitoring software which does this out of the box. But if you don’t have one or looking for a command-based solution then here you go. They are all FREE!
You may want to start by looking into
htop result to see the processes overview.
As you can see below, it gives an excellent idea about what all processes are utilizing. If you look at the first one which is nodejs taking 3.9% of memory and 0.3% of CPU.
top is installed on almost all Linux distribution.
Once you identify the suspect, then you may want to focus on that process instead of everything like you saw above. You can still use
top command but with some argument.
Let’s say you know the process id (PID); you can use the below command.
top -p $PID
You may also use
top. Below an example of checking rabbitmq utilization.
Similar to the top but with more information. As you can, it got the command column, which is handy to identify the process path. And, also it is colorful.
htop may not be installed by default, but you can always do it by
apt-get install htop if using Ubuntu.
As the name says, you get system utilization view on a single screen. Running processes are sorted by their CPU utilization.
A similar to the above listed but with a brilliant feature to record the output in a file so you can view them later. Imagine, there is a pattern of having an issue at a specific time window. You can schedule to write the output in a file through crontab or other and later you can playback.
To record the output in a file:
atop -w filename
and, to playback:
atop -r filename
It supports multiple arguments like interval, samples, etc. and I would strongly recommend taking a look at the man page.
If you are just interested in real-time troubleshooting, then just execute
atop and you should see like below.
ps command now.
You can use ps command with PID to print their CPU and memory utilization.
ps -p $PID -o %cpu,%mem
The output should look like this.
[email protected]:~# ps -p 1048 -o %cpu,%mem %CPU %MEM 0.2 3.0 [email protected]:~#
Interactive command-line monitoring tool for CPU, memory, disks, network, NFS, and virtual memory utilization. To view the top process (by utilization), you can execute
nmon and press
Monit is a web-based and command-line open source solution to monitor server resources, daemons, files, directory, file systems, etc.
Monit also got a cool widget.
A lightweight open-source utility to monitor Linux server. Monitorix got in-built HTTP so you can check the utilization and other stuff on the web. Some of the other usage reports include:
- Filesystem and I/O
- Network traffic
Monitorix also offers alert configuration so you can get notified when things are not right. It will be a good choice when you are managing cloud-based servers and looking for a proactive monitoring solution.
Netdata is a real-time performance monitoring for system resources, applications, web servers, databases, DNS, mail, hardware sensors, and a lot more. It is open-source and getting started is easy. All the data is collected, stored, and streamed for you to visualize interactively. Data is collected every second, so you never miss anything.
Loved by many industry leaders.
So what you are waiting for, try and take control of your Linux servers.
I hope the above tools help you to visualize the server utilization in real-time so you can take necessary action. If you just started as a system administrator and looking to get hands-on training, then check out this Udemy course.