Linux system status viewing tool Sysstat usage summary

Source: Internet
Author: User
Tags local time memory usage time interval cpu usage


1. About Sysstat;

Sysstat is a software package that includes a set of tools to monitor system performance and efficiency. These tools collect system performance data for us, such as CPU usage, hard disk and network throughput data, the collection and analysis of these data helps us determine whether the system is operating normally. It is a good assistant to improve the system operation efficiency and run the server safely;

The Sysstat software package integrates the following tools:
* The iostat tool provides data on CPU usage and hard disk throughput efficiency;
* The mpstat tool provides data related to a single processor or multiple processors;
* The sar tool collects, reports, and stores active system information;
* The sa1 tool collects and stores the daily system dynamic information to a binary file. It runs through the scheduled task tool cron,
Is a program front-end program designed for sadc;
* The sa2 tool writes the daily system activity information to the Summative Report. It is a front-end designed for sar and needs to be called through cron
* Sadc is a system dynamic data collection tool. The collected data is written into a binary file and used as the backend of the sar tool;
* Sadf displays data collected by sar in multiple formats;


We have a general understanding of this toolkit, and then let's take a look at the tools they contain:

◆ The iostat tool provides data on CPU usage and hard disk throughput efficiency;

◆ The mpstat tool provides data related to a single processor or multiple processors;

◆ The sar tool collects, reports, and stores active system information;

◆ The sa1 tool collects and stores the dynamic information of the system to a binary file every day. It runs through the scheduled task tool cron and is a program front-end program designed for sadc;

◆ Sa2
The tool is responsible for writing the daily system activity information into the Summative Report. It is a front-end designed for sar and needs to be called through cron

◆ Sadc is a system dynamic data collection tool. The collected data is written into a binary file and used as the backend of the sar tool;

◆ Sadf displays data collected by sar in multiple formats;

2. Install Sysstat and run it;

For most systems, this software package is available. The software name starts with sysstat. We can install it through the network;

2.1 Debian or deb software package-based systems;
[Root @ localhost ~] # Apt-get install sysstat

2.2 Fedora system or system managed with RPM packages;
[Root @ localhost ~] # Yum install sysstat
If it is an RPM Package, use the following command to install it;
[Root @ localhost ~] # Rpm-ivh sysstat *. rpm
For details about yum and rpm software package management tools, see Fedora/Redhat software package management guide.
2.3 Slackware system, for Slackware systems;
[Root @ localhost ~] # Installpkg sysstat *. pkg

2.4 compile and install the SDK through the source code package;

If you are using the source code package installation, please go to the official source code package http://perso.wanadoo.fr/sebastien.godard, currently the latest is sysstat-6.1.2;

If you think about the source code package, see: how to compile and install the source code package software
[Root @ localhost ~] # Tar zxvf sysstat-6.1.2.tar.gz
[Beinan @ localhost ~] $ Sysstat-6.1.2 cd
[Beinan @ localhost sysstat-6.1.2] #
[Beinan @ localhost sysstat-6.1.2] # make config
[Beinan @ localhost sysstat-6.1.2] # make
[Beinan @ localhost sysstat-6.1.2] # make install

2.5 about Sysstat scheduled tasks;

If you want the system information collected by the Sysstat tool set to be automatically stored in a file, you must perform the scheduled task for sa1 and sa2. You can modify the user's crontab. By default, Sysstat history is stored in the/var/log/sa file. If you want to define your own scheduled tasks, see: planning task tool cron configuration and description

In the root user, add the following section through crontab-e;
# 8am-7pm activity reports every 10 minutes during weekdays
0 8-18 ** 1-5/usr/lib/sa/sa1 600 6 &
# 7pm-8am activity reports every hour during weekdays
0 19-7 ** 1-5/usr/lib/sa/sa1 &
# Activity reports every hour on Saturday and Sunday
0 *** 0, 6/usr/lib/sa/sa1 &
# Daily summary prepared at 19: 05 5 19 ***/usr/lib/sa/sa2-&

Create the Sysstat startup script;

[Root @ localhost ~] # Touch/etc/rc. d/init. d/sysstat
[Root @ localhost ~] # Vi/etc/rc. d/init. d/sysstat
#! /Bin/sh
# Begin $ rc_base/init. d/sysstat
# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans-gerard@linuxfromscratch.org
./Etc/sysconfig/rc
. $ Rc_functions
Case "$1" in
Start)
Echo "Calling the system activity data collector (sadc )..."
/Usr/lib/sa/sadc-F-L-
Evaluate_retval
;;
*)
Echo "Usage: $0 start"
Exit 1
;;
Esac
# End $ rc_base/init. d/sysstat
[Root @ localhost ~] # Chmod 755/etc/rc. d/init. d/sysstat
[Root @ localhost ~] # Ln-sf/etc/rc. d/init. d/sysstat/etc/init. d/sysstat
With the Sysstat Daemon, the Sysstat daemon always serves us after we start the system. Sa, sa1, or sa2 automatically store the information in the binary file of the/var/log/sa Directory. We can use the sar tool to extract the history of the system information;
Of course, we can also manually open the Sysstat daemon, that is, the sysstat we created earlier;
[Root @ localhost ~] #/Etc/rc. d/init. d/sysstat start
The following methods are also supported;
[Root @ localhost ~] #/Usr/lib/sa/sa1
[Root @ localhost ~] #/Usr/lib/sa/sa2

3. Introduction to the Sysstat toolset;

3.1 sadc tool,
The sadc is located in the/usr/lib/sa Directory. If you have not set the executable path, use the absolute path to run it conveniently./usr/lib/sa/sadc; sadc writes data in a binary file. If you want to view the data content, you need to use the sadf tool for display;

Sadc usage;
/Usr/lib/sa/sadc [-d] [-F] [-I] [-L] [-V] [interval [count] [outfile]
Parameter description:
-D. Report statistics on hard disk settings;
-F forcibly writes data to a file;
-I reports all system interruption data;
Interval indicates the time interval in seconds, for example, 3;
Count: The number of statistical data. It is also a number;
Outfile outputs statistics to outfile files;
Note: The parameters in this tool are optional. If no parameters are specified, such as/usr/lib/sa/sadc -, the data is output to a file in the/var/log/sa/directory. We need to use the sadf or sar tool to view the details;
[Root @ localhost beinan] #/usr/lib/sa/sadc-
[Root @ localhost beinan] # ls/var/log/sa note: list all files in the sa Directory and determine which file is up-to-date based on the file time;
[Root @ localhost beinan] # sar-f/var/log/sa/sa12
Or
[Root @ localhost beinan] # sadf/var/log/sa/sa12
For example, we want to write the data collected by sadc to a specified file;
[Root @ localhost ~] #/Usr/lib/sa/sadc 1 10 sa000
[Root @ localhost ~] # Sar-f sa000

Linux 2.6.15-1.2054 _ FC5 (localhost. localdomain) May 12, 2006

09: 15 minutes 30 seconds CPU % user % nice % system % iowait % idle
09: 15 minutes 31 seconds all 3.00 0.00 0.00 1.00 96.00
09: 15 minutes 32 seconds all 0.00 0.00 0.00 0.00
09: 15 minutes 33 seconds all 0.00 0.00 0.00 0.00
09: 15 minutes 34 seconds all 0.00 0.00 0.00 0.00
09: 15 minutes 35 seconds all 0.00 0.00 0.00 0.00
36 seconds all 0.00 0.00 0.00 0.00 100.00
37 seconds all 0.00 0.00 0.00 0.00 100.00
09: 15 minutes 38 seconds all 0.00 0.00 0.00 0.00 100.00
09: 15 minutes 39 seconds all 0.00 0.00 0.00 0.00 100.00
Average: all 0.33 0.00 0.00 0.11 99.56

Note: We use sadc to collect system dynamic data, so that it can collect 10 dynamic information within 1 second. Then, we use the sar tool to view the system status. You can also use sadf to view the collected data, but it is not too intuitive. Try it by yourself. View the sa000 file and use sadf sa000;

3.2 sar tool;
The sar tool is powerful. It can collect CPU, hard disk, and dynamic data of the system, display dynamic data, and view binary data files. sar has many applications and is complex, data is more accurate. We only need to know the common content, and we can understand most of the content;
Usage:
Sar [parameter options]
Parameter description:
-A: displays all historical data by reading all the files in the/var/log/sar directory and displaying them in different categories;
-B: the read throughput of the device through I/O interruption;
-B reports memory or virtual memory swap statistics;
-C: The number of processes created per second;
-D reports information such as writing and reading of physical block devices (storage devices). If it is more intuitive, it can be used together with the p parameter.-dp
-F reads content from a binary data file, such as sar-f filename
-I interval: specifies the data collection time in seconds;
-N analyzes network device status statistics. The following parameters can be used: DEV, EDEV, NFS, NFSD, or SOCK. For example,-n DEV
-O writes statistics into a file, such as-o filename;
-P reports statistics on each processor application, which is used on a multi-processor machine and valid only when the SMP kernel is enabled;
-P displays the friendly device name for ease of viewing. It can also be used with the-d and-n parameters, such as-dp or-np.
-R memory and swap zone usage statistics;
-R
-T this option is useful for reading data from a file. Without this parameter, it will be read based on local time;
-U indicates the CPU usage parameters;
-V reports the resource occupation information of inode, files, or other kernel tables;
-W: report information about the system exchange activities; the number of data exchanges per small amount;
-W: Reporting System exchange of activity throughput information;
-X is used to monitor the process, and the PID value of the process must be specified later;
-X is used to monitor processes, but it specifies a sub-process ID;
Sar application example;
Example 1: If you only use the sar Command, sar reads the latest system status file in the/var/log/sa Directory.
[Root @ localhost ~] # Sar
[Root @ localhost ~] # Sar-A note: Read all file data in the/var/log/sa Directory;
If you want to know the CPU utilization rate and dynamic update, the following example updates the data once per second for a total of five times;
[Root @ localhost ~] # Sar-u 1 5
Linux 2.6.15-1.2054 _ FC5 (localhost. localdomain) May 12, 2006

Time CPU utilization nice value system occupied I/O occupied idle
11: 19 minutes 34 seconds CPU % user % nice % system % iowait % idle
11: 19 minutes 35 seconds all 2.97 0.00 0.00 0.00
11: 19 minutes 36 seconds all 11.11 0.00 9.09 0.00 79.80
37 seconds all 21.78 0.00 6.93 0.00 71.29
11: 19 minutes 38 seconds all 15.00 0.00 0.00 0.00
11: 19 minutes 39 seconds all 8.00 0.00 0.00 0.00 92.00
Average: all 11.78 0.00 3.19 0.00 85.03
Note:
CPU: indicates all CPUs in the machine;
% User indicates the CPU utilization;
% Nice indicates the percentage of CPU priority at the user layer, and 0 indicates normal;
% System indicates the CPU usage on the user application layer when the system is running;
% Iowait indicates the percentage of CPU used when requesting hard disk I/0 data to flow out;
% Idle indicates the percentage of idle CPU. The greater the value, the lower the system load;
You can output the dynamic information of CPU utilization to a text file and view it through more.
[Root @ localhost ~] # Sar-u 1 5> sar000.txt
[Root @ localhost ~] # More sar000.txt
It can also be output to a binary file and viewed through sar;
[Root @ localhost ~] # Sar-u 1 5-o sar002
[Root @ localhost ~] # Sar-f sar002
Note: If you output data to a binary file through-o filename, you cannot use the file content viewing tool more, less, or cat to view the data, the sar tool should be used for viewing. The-f parameter should be added;
Instance 2: view the throughput of the network device;
For example, we have the data updated every second for a total of 10 times;
[Root @ localhost ~] # Sar-n DEV 2 5
Time IFACE rxpck/s txpck/s rxbyt/s txbyt/s rxcmp/s txcmp/s rxmcst/s
Field 1: time;
IFACE: the device name;
Rxpck/s: Packets received per second;
Rxbyt/s: the volume of all packets received per second;
Txbyt/s: the volume of all packets transmitted per second;
Rxcmp/s: total number of packages that receive data cutting and compression per second;
Txcmp/s: the total number of compressed data packets that are cut per second;
Rxmcst/s: Multi-Point transfer packets received per second;
If we are engaged in extracting information from the eth0 device (that is, the network card eth0), we should use grep to filter. Then, it is displayed;
[Root @ localhost ~] # Sar-n DEV 2 5 | grep eth0
11: 52 minutes 37 seconds eth0 1.00 1.00 97.51 97.51 0.00 0.00 0.00
11: 52 minutes 39 seconds eth0 1.01 1.01 98.49 98.49 0.00 0.00 0.00
11: 52 minutes 41 seconds eth0 1.00 1.00 98.00 98.00 0.00 0.00 0.00
11: 52 minutes 43 seconds eth0 1.00 1.00 98.00 98.00 0.00 0.00 0.00
11: 52 minutes 45 seconds eth0 1.00 1.00 98.00 98.00 0.00 0.00 0.00
Average: eth0 1.00 1.00 98.00 98.00 0.00 0.00
If you want to know the network device error report, it is used to view the device failure. EDEV should be used; for example, the following example;
[Root @ localhost ~] # Sar-n EDEV 2 5

3.3 iostat
Iostat is used to display the real-time system of the system, such as CPU usage and hard disk device throughput;
[Root @ localhost ~] # Iostat
Linux 2.6.15-1.2054 _ FC5 (localhost. localdomain) May 12, 2006

Avg-cpu: % user % nice % system % iowait % idle
7.24 0.00 0.99 0.35 91.43

Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn
Hda 1.46 28.43 21.43 710589 535680

3.4 mpstat
Mpstat provides statistics on CPU utilization in a multi-processor system. You can also add a parameter to mpstat to specify the CPU with-P. The processor ID starts from 0. The following example shows how to view the data of two processors updated every two seconds. A total of 10 data entries must be displayed;
[Root @ localhost ~] # Mpstat-P 0 2 10 Note: view the first CPU
[Root @ localhost ~] # Mpstat-p 1 2 10 Note: view the second CPU
</Code>
<Code>
[Root @ localhost ~] # Mpstat 2 10 Note: View all CPUs;

3.5 sdaf
Sdaf can extract the data collected by sar from binary files. This is all you know. The displayed format is not friendly;
[Root @ localhost ~] # Sar-u 2 5-o sar003
[Root @ localhost ~] # Sadf sar003
Relatively speaking, it is better to use sar to read the content of the output file; for example, the following;
[Root @ localhost ~] # Sar-f sar003

4. Tools similar to Sysstat;

4.1 process management tools;
Process management tools, including ps, pgrep, top, kill, killall, and pkill. For more information, see Linux process management.

4.2 memory usage viewing tool;
Free memory usage
The free tool can view both physical memory and virtual memory usage;
[Root @ localhost ~] # Free
If the display unit is M, The-m parameter is added;
[Root @ localhost ~] # Free-m
Total used free shared buffers cached
Mem: 724 713 11 0 24 290
-/+ Buffers/cache: 398 326
Swap: 800 0 800

Vmstat instant display of memory tools;
Vmstat is a tool that instantly displays memory usage;
How to use vmstat:
Vmstat [-V] [-n] [delay [count]
-V displays the version of vmstat;
-N causes the headers not to be reprinted regularly.
-A: displays the status of all activated and inactive memory. print inactive/active page stats.
-D: Displays hard disk statistics. prints disk statistics
-D: Display the hard disk partition table; prints disk table
-P: displays the read/write status of the hard disk partition. prints disk partition statistics
-S: displays memory usage; prints vm table
-M prints slabinfo
-S defined unit, k K
Delay is the interval between two refreshes;
Unit volume: k: 1000 K: 1024 m: 1000000 M: 1048576 (K by default)
Count refresh times;

5. About this article;
I wrote an article about Sysstat in October 30, 2004. At that time, I didn't make it too clear about Sysstat. It was just a simple operation. For the original article, see sysstat, a common system maintenance tool.
This article was rewritten today, mainly because it was previously poorly written, so some parameters were tested and verified. I think this should be more convenient for new users.
This article is not a big and comprehensive man. We have to rely on ourselves to understand some parameters. I think it is enough to master some common parameters, and there is no need to thoroughly study a command. Some things are useless if we don't need them.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.