Home Operation and Maintenance Linux Operation and Maintenance How to set up system monitoring on Linux

How to set up system monitoring on Linux

Jul 04, 2023 pm 10:41 PM
Linux system monitoring settings

How to set up system monitoring on Linux

On the Linux operating system, system monitoring is an important task. By monitoring the system, we can obtain information about system performance, resource usage, service running status, etc., so that problems can be discovered and solved in a timely manner. This article explains how to set up system monitoring on Linux and provides code examples.

1. Use the top command to monitor system performance

The top command is a very commonly used system monitoring tool, which can display the running status and process information of the system in real time. We can install the top command through the following command:

sudo apt-get install top
Copy after login

After the installation is completed, you can run the top command directly in the terminal to view the running status of the system. The output results of the top command include system load, CPU usage, memory usage, process list, etc.

2. Use the sar command to record system performance data

The sar command is the abbreviation of System Activity Reporter. It can record system performance data and save it in text or binary format. We can install the sar command through the following command:

sudo apt-get install sysstat
Copy after login
Copy after login

After the installation is complete, you can use the following command to generate a report of system performance data:

sar -A > performance_report.txt
Copy after login

This command will display the system’s CPU usage, memory Usage, disk IO, network transmission and other data are saved to the performance_report.txt file.

3. Use the nmon command to monitor system resources

nmon is an efficient system monitoring tool that can display system CPU utilization, memory usage, disk IO, network transmission and other data. We can install the nmon command through the following command:

sudo apt-get install nmon
Copy after login

After the installation is completed, you can use the following command to start nmon:

nmon
Copy after login

After the nmon command is started, various items of the system will be displayed in an interactive interface Resource usage. You can follow the prompts to view detailed information about different resources.

4. Use the sysstat tool for system monitoring

sysstat is a set of system performance monitoring tools, including sar, iostat, mpstat and other commands. We can install the sysstat tool through the following command:

sudo apt-get install sysstat
Copy after login
Copy after login

After the installation is complete, you can use the following command to query system performance data:

sar -u
Copy after login

This command will display the CPU usage of the system. You can use other parameters to view data on different resources, such as sar -r to view memory usage, sar -n DEV to view network transmission, etc.

5. Use Zabbix for remote monitoring

Zabbix is ​​a powerful network monitoring tool that can monitor the performance data of multiple hosts in real time. We can install Zabbix Agent through the following command:

sudo apt-get install zabbix-agent
Copy after login

After the installation is completed, you need to edit some configuration files and set the IP address and port number of Zabbix Server in the zabbix_agentd.conf file. Then restart the Zabbix Agent service:

sudo service zabbix-agent restart
Copy after login

Finally, configure monitoring items and triggers on Zabbix Server to achieve remote monitoring.

6. Use Python to write custom monitoring scripts

In addition to using existing monitoring tools, we can also use Python to write custom monitoring scripts. The following is a simple example that can detect the CPU usage of the system:

import psutil

def get_cpu_usage():
    cpu_percent = psutil.cpu_percent()
    return cpu_percent

if __name__ == "__main__":
    cpu_usage = get_cpu_usage()
    print("CPU Usage: {}%".format(cpu_usage))
Copy after login

The above code uses the psutil library to obtain the CPU usage of the system. You can write monitoring scripts for other functions as needed, such as monitoring memory usage, disk IO, network transmission, etc.

Summary:

On the Linux operating system, the monitoring system is an important means to ensure system stability and performance optimization. This article introduces several common system monitoring methods and tools, including top command, sar command, nmon command, sysstat tool, Zabbix, etc. In addition, we can also use Python to write custom monitoring scripts to meet specific needs. By monitoring the system in a timely manner, we can effectively detect problems and take appropriate measures to deal with them to ensure the normal operation of the system.

The above is the detailed content of How to set up system monitoring on Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Two Point Museum: All Exhibits And Where To Find Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Tutorial on finding keywords for common Linux commands Tutorial on finding keywords for common Linux commands Mar 05, 2025 am 11:45 AM

This tutorial demonstrates efficient keyword searching in Linux using the grep command family and related tools. It covers basic and advanced techniques, including regular expressions, recursive searches, and combining commands like awk, sed, and xa

Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do? Work content of Linux operation and maintenance engineers What does Linux operation and maintenance engineers do? Mar 05, 2025 am 11:37 AM

This article details the multifaceted role of a Linux system administrator, encompassing system maintenance, troubleshooting, security, and collaboration. It highlights essential technical and soft skills, salary expectations, and diverse career pr

How do I use regular expressions (regex) in Linux for pattern matching? How do I use regular expressions (regex) in Linux for pattern matching? Mar 17, 2025 pm 05:25 PM

The article explains how to use regular expressions (regex) in Linux for pattern matching, file searching, and text manipulation, detailing syntax, commands, and tools like grep, sed, and awk.

How do I monitor system performance in Linux using tools like top, htop, and vmstat? How do I monitor system performance in Linux using tools like top, htop, and vmstat? Mar 17, 2025 pm 05:28 PM

The article discusses using top, htop, and vmstat for monitoring Linux system performance, detailing their unique features and customization options for effective system management.

How do I implement two-factor authentication (2FA) for SSH in Linux? How do I implement two-factor authentication (2FA) for SSH in Linux? Mar 17, 2025 pm 05:31 PM

The article provides a guide on setting up two-factor authentication (2FA) for SSH on Linux using Google Authenticator, detailing installation, configuration, and troubleshooting steps. It highlights the security benefits of 2FA, such as enhanced sec

How do I configure SELinux or AppArmor to enhance security in Linux? How do I configure SELinux or AppArmor to enhance security in Linux? Mar 12, 2025 pm 06:59 PM

This article compares SELinux and AppArmor, Linux kernel security modules providing mandatory access control. It details their configuration, highlighting the differences in approach (policy-based vs. profile-based) and potential performance impacts

Methods for uploading files for common Linux commands Methods for uploading files for common Linux commands Mar 05, 2025 am 11:42 AM

This article compares Linux commands (scp, sftp, rsync, ftp) for uploading files. It emphasizes security (favoring SSH-based methods) and efficiency, highlighting rsync's delta transfer capabilities for large files. The choice depends on file size,

How do I back up and restore a Linux system? How do I back up and restore a Linux system? Mar 12, 2025 pm 07:01 PM

This article details Linux system backup and restoration methods. It compares full system image backups with incremental backups, discusses optimal backup strategies (regularity, multiple locations, versioning, testing, security, rotation), and da

See all articles