Open In App

How to Monitor System Usage, Outages and Troubleshoot Linux Servers

Improve
Improve
Like Article
Like
Save
Share
Report

As we know that Linux is very reliable and a great system administrator should always know the system’s behavior and its utilization at every moment of time. So if an administrator or a user wants to monitor its complete system then they have to do the following  

Storage Space Utilization

Linux provides two commands which are used to inspect storage space utilization these are as follows:

  • df– It stands for disk-free command so it is typically used to report complete disk space and its usage in by file system. 

For example, we want to inspect the inode usage 

df -hTi

df  -hTi command

so using the df command we can see the filesystem its size, total used, and where it is mounted on.

  • Du- This command is a disk usage command which is used to predict file space usage so with help of the du command we can easily get the files and also directories that consume a very large amount of space on the hard disk. 

Example: If we want to see the total disk space usage of the directory 

Du command

         

Memory and CPU Utilization

1. top: Linux Process Monitoring

This command is used in Linux to monitor the program performance that is being used mostly by many systems for its performance it is in Unix-like operating systems. So we can run the top command and display all running processes. It also displays the following

  • CPU Usage
  • Memory Usage 
  • Swap Memory
  • Cache Size 
  • Process PID
  • User 
top

Top Command 

2. VMStat: Virtual Memory Statistics

vmstat command is used for virtual memory Statistics which is a built-in utility used for monitoring in Linux this command is used to get the information of following 

  • Memory
  • System Processes
  • Paging 
  • Interrupts
  • Disk
  • CPU Scheduling

So by using the VMStat command we can observe the system virtually by giving the sample period.

vmstat

VMStat command 

3. LSof – List Open Files

The LSof command is used to display a list of all the open processes as well as files. The open files include following

  • disk files
  • network sockets
  • pipes, devices
  • processes

So the most important reason for using it is when the disk can’t be unmounted and also displays the error on files that are opened. so using the LSof command we can identify the files that are used.

lsof

LSof command

4. Tcpdump – Network Packet Analyzer

TCP dump command is one of the most used commands which is used for packet analyzers that are used to filter TCP/IP packets. We can also save the captured packages in one file. It is available in most of the distributions of Linux.

tcpDump

Tcpdump command

5. Netstat – Network Statistics

Netstat command is used to monitor the network packages which are ingoing and outgoing. It is a most useful tool for system administrators so that they can monitor the network performance and also troubleshoot the problems related to the network.

netstat

NetStat command

What Happened?

When there is any fault like power failure or hard disk failure it can be a planned or not planned (Unplanned) process, Then we can use Logs to determine what happened or the possibilities of issues that can occur.

cd /var/log

 

Some of the files in /var/Log are in the text which is in regular form, others are compressed files and directories. Suppose we want to check the names which have errors in their names but it may be time-consuming.

Example: Examining logs to identify the errors process 

Suppose There is a case when our Local area network clients are not able to print the network printers. So in this case first we have to go into the /var/log/cups directory and we have to find what is there then we have to use the tail command to display the last 10 lines of an error log, or we can also use the -f error log.

# cd /var/log/cups
# ls
# tail access_log

Log files Monitoring

Example: Examining the logs for hardware failures

Suppose we have a case of hardware failure as they are really difficult to troubleshoot we should check the messages logs for the hardware part.

cd /var/log/messages
ls

So in this, we will look at Linux system logs files. first, we have to use the cd command to go to this directory “/var/log” and then the list of all the files and folders using the “ls” command. So we can see the list of files and folders present inside it. These files and folders contain the logs records. 

 

As told earlier most of the time the system logs are saved in “Syslog” for the “/var/log” folder. So we can display the log records in the “Syslog” directory. For this, we have to use the sudo command. This is always started with the keyword sudo at the beginning we have to use cat to open the “Syslog” shown in below image

 

Let us focus on another file which consists of our logs files in the folder “/var/log”. This time we will opt for the “dmesg” files in this folder. It has simple log files and records.

 

The records inside the log files are always specified by type i.e error failed, ward, etc as we have seen in the previous picture. Let us specify our sudo command with the “dmesg ” keyword. So we are specifying the log files, especially error types. So this command has specified all the logs files of type “error”.

 

Conclusion

In this article, we have learned different types of commands to monitor the Linux system we have learned about the log file “/var/log/message”. We also discuss the different commands to get all the generic logs that warn, failed, and error. We have done this for specific folders in the var/log/folder.  

 In this article, we helped many users to be aware of the system’s overall performance. we also need to check that the operating system consists of installed packages that are updated and special note never try to check your logs. Then we can be headed, So with help of these commands, we can easily monitor the performance of our operating system and can reduce the size whenever required.


Last Updated : 11 Apr, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads