Super practical! Sar commands that will make you a Linux master

王林
Release: 2024-03-01 08:01:02
forward
493 people have browsed it

Super practical! Sar commands that will make you a Linux master

I. Overview

The sar command presents a system usage report using data collected from system activity. These reports are made up of different sections, each containing the type of data and when the data was collected. The default mode of the sar command displays CPU usage at different time increments for various resources accessing the CPU (such as user, system, I/O scheduler, etc.). Additionally, it displays the percentage of idle CPU for a given time period. The average value for each data point is listed at the bottom of the report. sar reports collected data every 10 minutes by default, but you can use various options to filter and adjust these reports.

Similar to the uptime command, the sar command can also help you monitor the CPU load. sar allows you to understand when excessive load occurs and the specific details that may be causing it. sar provides more detailed data to help you better analyze system performance and deal with potential problems in a timely manner.

The syntax of the sar command is:

# sar [选项]
Copy after login

2. sar command example

1. Install sar command

To install the sar command, you need the "sysstat" package.

# yum install sysstat
# rpm -ivh sysstat-2.3.4
Copy after login

Configure sar to retain logs beyond the default 7 days.

# vi /etc/sysconfig/sysstat
Copy after login

Change the "HISTORY" parameter.

2.CPU usage

Get the current CPU usage.

# sar 2 10
# sar -p 2 10
# sar-P ALL 2 10
Copy after login

To get the CPU usage of the previous date, such as the 14th:

# sar -P ALL -f /var/log/sa/sa14
Copy after login

c. To get the CPU usage from 7am to 3pm on the 10th of the month (that is, at a specified time):

# sar -P ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

3.Memory usage

Get current memory usage:

# sar -r 2 10
Copy after login

To get the memory usage of the previous date, such as the 14th:

# sar -r -f /var/log/sa/sa14
Copy after login

To get the memory usage from 7am to 3pm on the 10th of the month (that is, the specified time):

# sar -r -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

4. Exchange usage

To get current swap usage:

# sar -S 2 10
Copy after login

To get the swap usage of the previous date, such as the 14th:

# sar -S -f /var/log/sa/sa14
Copy after login

To get swap usage from 7am to 3pm on the 10th of the month:

# sar -S -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

5.Load average

To get current load average statistics:

# sar -q 2 10
Copy after login

To get the load average statistics of the previous date, such as the 14th:

# sar -q -f /var/log/sa/sa14
Copy after login

To get load average statistics for the 10th of the month (7am to 3pm):

# sar -q -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

6. Use paging

To get the current paging usage:

# sar -B 2 10
Copy after login

To get the pagination usage of the previous date, such as the 14th:

# sar -B -f /var/log/sa/sa14
Copy after login

To get usage from 7am to 3pm on the 10th of the month:

# sar -B -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

7.IO usage

Get current IO usage:

# sar -b 2 10
Copy after login

To get the IO usage of the previous date, such as the 14th:

# sar -b -f /var/log/sa/sa14
Copy after login

To get IO usage from 7am to 3pm on the 10th of the month:

# sar -b -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

8. Disk IO usage

Get current disk IO usage:

# sar -d -p 2 10
Copy after login

To get the disk IO usage of the previous date, such as the 14th:

# sar -d -p -f /var/log/sa/sa14
Copy after login

To get the disk IO usage from 7am to 3pm on the 10th of the month:

# sar -d -p -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

9.Network statistics

To obtain current network device statistics:

# sar -n DEV 2 10
Copy after login

To obtain the network device statistics of the previous date, such as the 14th:

# sar -n DEV -f /var/log/sa/sa14
Copy after login

To get network device statistics from 7am to 3pm on the 10th of the month:

# sar -n DEV -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

10. Power management statistics

To get current power management usage:

# sar -m 2 10
Copy after login

To get the power management usage of the previous date, such as the 14th day:

# sar -m -f /var/log/sa/sa14
Copy after login

To get power management usage from 7am to 3pm on the 10th of the month:

# sar -m ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

11.Memory Statistics (Page Activity)

To get current memory statistics:

# sar -R 2 10
Copy after login

To get the memory statistics of the previous date, such as the 14th day:

# sar -R -f /var/log/sa/sa14
Copy after login

To get memory statistics for the 10th of this month (7am to 3pm):

# sar -R ALL -f /var/log/sa/sa10 -s 07:00:00 -e 15:00:00
Copy after login

The above is the detailed content of Super practical! Sar commands that will make you a Linux master. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:mryunwei.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template