Skip to main content

sysstat

sysstat

概述

sysstat是一个监测系统性能及效率的工具,比如CPU使用率、硬盘和网络吞吐数据。收集和分析这些系统性能数据,有利于判断系统是否正常运行,是提高系统运行效率、安全运行服务器的得力助手。sysstat软件包集成的工具如下:

■iostat工具:提供CPU使用率及硬盘吞吐效率的数据。

■mpstat工具:提供处理器相关数据。

■sar工具:负责收集、报告并存储系统活跃的信息。

■sa1工具:负责收集并存储每天系统动态信息到一个二进制的文件中。它是通过计划任务工具cron来运行。

■sa2工具:负责把每天的系统活跃性息写入总结性的报告中。它是为sar所设计的前端,要通过cron来调用。

■sadc工具:负责收集系统动态数据,将收集的数据写入一个二进制的文件中,它被用作sar工具的后端。

■sadf工具:显示被sar通过多种格式收集的数据。

安装sysstat工具

yum install sysstat -y

配置文件

■修改的配置文件为“/etc/sysconfig/sysstat”。

■sa和sar收集的数据默认保存路径为“/var/log/sa”,需修改时,可以参见“/etc/sysconfig/sysstat”配置文件的SA_DIR配置项。

命令介绍

sadc工具

sadc工具存放在“/usr/lib64/sa/”目录中。该工具把数据写在一个二进制的文件中,如需要查看数据内容,则使用sadf工具来显示。在终端界面,执行man 8 sadc命令,可查看其他更多参数及其含义。

sar工具

sar工具主要收集系统CPU、硬盘动态数据,还可以收集动态显示。在终端界面,执行man 1 sar命令,可查看其他更多参数及其含义。

SAR(1) SAR(1) Linux User's Manual NAME sar- Collect,report,or save system activity information. SYNOPSIS sar[-A[-B][-b][-C][-D][-d][-F[MOUNT]][-H][-h][-p][-q][-r[ALL]][-S][-t][ -U[ ALL]][-V] --help kevword [filename]|-[0-9]+][-iinterval][-s[hh:mm:ss]]][-e[hhmmss]]][interval[count]] DESCRIPTION he sar command writes to standard output the contents of selected cumulative activity counters in the operating system. The accounting system,based on the values in the countand nterva paramters,writes nformation the specified number oftimes spacedat the specified intervals in seconds. If the interval parameter is set to zero,the sar command dis- plays the average statistics for the time since the sys tem was started.If the interval parameter is specified without the count parameter,then reports are generated continuous ly.The collected data can also be saved in the file specified by the -ofilename flag,in addition to being displayed onto the screen.If filename is omitted,sar uses the standar system activity daily data file (see be Low).By default all the data available from the kernel are saved in the data file. he sar command extracts and writes to standard outputrecordspreviously savedin a file.This file can be either the one specified by the -f flag or,by default,the standard system activity daily data file. It is also possible to enter -1,-2 etc.as an argument to sar to display data of that days ago.For example,-1 will point at the standard system ac- tivity file of yesterday. Standardsystem activity daily data files are named saDD or saYYYyMDD,where YYYY stands for the current year,MM for the current month and DD for the currentday.They are the default files used by sar only when no filename has been ex- plicitly specified. when used to write data to files (with its option -o),sar will use saYYYYMMDD if option-Dhas als been specified,else it will use saDD.when sed to display the records previously saved in a file,sar will look for the most recent of saDD and saYYYYMMDD,and use it. standardsystem activity daily data files are Located in the/var/log/sa directory by default.Yet it is possible ta specify an alternate Location for them: If a directory (instead of a plain file)is used with options-f or-othen it will be considered as the directory containing the data files. withoutthe-Pflag,the sar command reports system-wide (gLobal among all processors) statistics,which are calculate as averages for values expressed as percentages,and as sum otherwise.If the-p flag is given,the sar command reports activitywhchelatestothespecified processor or processors.If-pALLisgiven,the sar command reports statistics for each individual processor and alobal statistics among all processors.offl ine processors are not disnlaved


#### iostat工具

iostat工具用于显示系统CPU使用状态、硬盘设备的吞吐率。在终端界面,执行man iostat命令,可查看其他更多参数及其含义。

![](/img/docs/image160.png)

#### mpstat工具

mpstat工具主要是用于多处理器系统中的CPU的利用率的统计。mpstat也可以加参数,用-P来指定哪个CPU,且处理器的ID是从0开始的。PROC文件系统必须先挂载,默认情况下,系统已经挂在了proc文件系统。在终端界面,执行man 1 mpstat命令,可查看其他更多参数及其含义。

MPSTAT(1)
Linux User's Manual
MPSTAT(1)
NAME
mpstat - Report processors related statistics.
SYNOPSIS
 y ke  I-  
mpstatI
DESCRIPTION
The mpstat commandwritesto standrd outputactivities for each availableprocessor,processore beingthe first one
Global average activities among all processors are also reported.The mpstat command can be used both on SMP and UP ma
chines,but in the latter,only global average activities will be printed.If no activity has been selected,then the de
fault report is the CPU utilization report.
Theinterval parameter specifies the amount of time in seconds between each report.A value of (or no parameters at
all) indicates that processors statistics are to be reported for the time since system startup (boot).The count parame
ter can be specified in conjunction with the interval parameter if this one is not set to zero. The value of count deter
mines the number of reports generated at interval seconds apart.If the interval parameter is specified without the count
parameter,the mpstat command generates reports continuous ly.
OPTIONS
-A
This option is equivalent to specifying -n -u-I ALL -N ALL -P ALL
--dec={0|1|2}
Specify the number of decimal places to use (e to 2,default value is 2).
-I { keyword [.... I ALL }
Report interrupts statistics.
Possible keywords are cPu,SCPU,and SUM
with the P keyword,the number of each individual interrupt received per second by the CPU or CPUs is displayed.
Interrupts are those listed in /proc/interrupts file.
with the P keyword,the number of eachindividual software interrupt received per second by the Pu or CPUs is
displayed.his option works only with kernels2.6.31and Later. Software interrupts are those listed in
/proc/softirqs file.
with the SUM keyword,the mpstat command reportsthe total number of interrupts per processor.The following val
ues are displayed:
CPU
Processor number.The keywordall indicates that statistics are calculated as averages among all proces-
sors.

sadf工具

sdaf工具主要是从二进制文件中提取sar所收集的数据,并以多种格式进行显示。在终端界面,执行man 1 sadf命令,可查看其他更多参数及其含义。

SADF(1) Linux User's Manual SADF(1) NAME sadf- Display data collected by sar in multiple formats. SYNOPSIS ifacelist][--sar options][ interval[ count]][ datafile|-[0-9]+] DESCRIPTION The sadf command is used for displaying the contents of data files created by the sar(1) command.But unlike sar,sadf can write its data in many different formats(Sv,XM,etc.)The defaultformatisone that can easily be handled by pattern processing commands like awk (see option -p).The sad command can also be used to draw graphs for the various activities collected by sar and display them as SVG (Scalable Vector Graphics)graphics in your web browser (see option -g). The sadf command extracts and writes to standard output records saved in the datafile file.This file must have been cre ated by a version of sar which is compatible with that of sadf.If datafile is omitted,sadf uses the standard system activity daily data file.It is also possible to enter-1,-2etc,as an argument to sadf to display data of that days ago. For example,-l will point at the standard system activity file of yesterday. The standard system activity daily data file is named saDD or sayMDD,where YYYY stands for the current year,MM for the current month and DD for the current day.sadf will look for the most recent of saD and saYYYMMDD,and use it.By defaultitsocatedinthe/var/Log/sadirectory.Yetit1spossbleto specifyanalternate Location for it:If datafile is a directory (instead of a plain file) then it will be considered as the directory where the standard system activity daily data file is located. The interval and count parameters are used to tell sadf to select count records at interval seconds apart.If the count parameter is not set,then all the records saved in the data file will be displayed. Allthe activity flags of sar may be entered on the command line to indicate which activities are to be reported.Before specifying them, put a pair of dashes (--)on the command Line in order not to confuse the flags with those of sadf.Not specifying any flags selects only CPU activity. OPTIONS -C Tell sadf to display comments present in file. Convert an old system activity binary datafile (version 9.1.6 and later) to current up-to-date format.Use the -C following syntax: sadf -c old_datafile>new_datafile


### 功能测试

使用sadc收集系统动态数据,让它在每秒收集一次,共收集5次动态信息,并写到一个指定的文件。再通过sar工具来查看系统的状态。

[root@localhost sa]#/usr/lib64/sa/sadc 1 5 record_1
[rootalLocalhost sa]# sar -f record1
Linux 4.19.9-2003.4..0036.uel20.aarch64(Localhost. localdomain)
2020年06月24日
(4 CPU)
aarch64
17时48分57秒
Bidle
CPU
ouser
%nice
9system
iowait
steal
17时48分58秒
all
0.00
0.00
0.00
100.00
0.00
0.00
17时48分59秒
alt
0.00
0.00
0.00
0.00
0.00
100.00
17时49分00秒
all
0.00
0.00
0.00
0.00
0.00
100.00
17时49分01秒
all
0.00
0.00
0.00
0.00
0.00
100.00
all
平均时间:
0.00
0.00
0.00
0.00
0.00
100.00
[rootaLocalhost sa]#

281CPU利用率动态更新,每秒获取一次数据,共获取5次。

[rootalocalhost sa]#sar -u15 Linux 4.19.90-2003.4.0.0036.uel20.aarch64 (Localhost.Localdomain) 2020年06月24日 aarch64_ (4 CPU) 17时49分54秒 CPU %user nice system 10wait osteal %idle all 17时49分55秒 0.00 0.00 0.00 0.00 0.00 100.00 17时49分56秒 all 0.00 0.00 100.00 0.00 0.00 0.00 17时49分57秒 al 0.00 0.00 0.00 0.00 0.00 100.00 17时49分58秒 0.00 0.00 0.00 0.00 0.00 100.00 all 0.00 17时49分59秒 0.00 0.00 0.00 0.00 100.00 all 平均时间: 0.00 0.00 0.00 0.00 0.00 100.00 [rootalocalhost sa]#


282查看网络设备的吞吐情况,让数据每1秒获取一次,共获取5次。

[rootalocalhost sa]# sar -n DEV15 (4 CPU) Linux 4.19.90-2003.4.0.0036.uel20.aarch64 (lLocalhost.localdomain) 2020年06月24日 aarch64_ 8ifutil 17时50分37秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 17时50分38秒 Lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 17时50分38秒 enp3s0 1.00 1.00 0.05 0.10 0.00 0.00 0.00 0.00 ifutil 17时50分38秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 17时50分39秒 Lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 2.00 17时50分39秒 enp3s0 3.00 0.23 0.28 0.00 0.00 0.00 0.00 17时50分39秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s ifutil 17时50分40秒 Lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 17时50分40秒 enp3s0 1.00 3.00 0.05 0.38 0.00 0.00 0.00 0.00 17时50分40秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s 8ifutil 17时50分41秒 2.00 0.00 0.00 0.00 0.00 0.00 Lo 0.00 0.00 17时50分41秒 enp3s0 1.00 0.17 0.10 0.00 0.00 0.00 0.00 17时50分41秒 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s rxmcst/s 8ifutil txcmp/s lo 0.00 0.00 0.00 0.00 0.00 17时50分42秒 0.00 0.00 0.00 17时50分42秒 enp3s0 1.00 2.00 0.05 0.23 0.00 0.00 0.00 0.00 平均时间: IFACE rxpck/s txpck/s rxkB/s txkB/s 8ifutil rxcmp/s txcmp/s rxmcst/s 平均时间: 0.00 0.00 0.00 lo 0.00 0.00 0.00 0.00 0.00 平均时间: enp3s0 1.60 1.80 0.11 0.22 0.00 0.00 0.00 0.00 [rootalocalhost sa]#


283显示CPU使用率。

[rootalocalhost sa]# iostat-0 Linux 4.19.90-2003.4.0.0036.uel20.aarch64(Localhost, Localdomain) 2020年06月24日 (4CPU) aarch64 avg-cpu:user nice system iowait 8steal idle 0.14 0.00 0.08 0.26 0.00 99.51 [rootalLocalhost sa]#


284统计多处理器系统中的CPU0利用率。

#[es o 00.0 00.0 00.0 00.0 00:0 00.0 00.0 00:0 间平 00.000 00.0 0 ecinb% 1san6% 1e01s% f1os% bJT9 10 cin JSU% Ud edt% s s% 00:0 00.0 671 00.000 00.0 00.0 00:0 00:0 00:0 00.0 00.0 0 tnp% 1san6% f10s% pJT% sAs% 91n8 Ud edts 1eats% 1018 JSU% 5025471 00.000 00:0 00.0 00:0 00:0 00:0 00.0 00:0 00.0 00.0 0 50571 ecrne% 1san6% lpt% 1ea1s% 310s% b1T8 11O% s s% ecin Jsn% Ud 4025411 00.000 00.0 00:0 00.0 00:0 00.0 00:0 00.0 00:0 00.0 0 71 alpT% ecrn% 1san6% 1ea1s% 110s% bT9 0 s s% ctn Jsn% UPC 02571 00.000 00.0 00.0 00.0 00.0 00:0 00.0 00.0 00.0 0 3071 00.0 r 1san6% eats% 11os% b1T9 11OT s s% ctn JSU% UP 02511 edt 71 00.000 00.0 00:0 00.0 00:0 00.0 00.0 00.0 00.0 00.0 0 edt% acrnp% 1san6% 1eats% f1os% b118 1O1 sAs% ec1n8 JSU% Ud 025471 ahp1ee (nd) t

42000024
oeosohojah.en,000.400-0.9l14h
5 tp#ier tsoheoo)

285从当前的日常数据文件中提取cpu1的统计数据。

00.160d% P T316412020-70-0000 T sohec T 00.016019% 32I64:2070-700002 tohec 1 ohec 00.8fieo 1 T36412070-70-0000 00.1 etsys TU3:6412070-700002 T sohec T 00.0 ni 1 T3:64:070-70-0000 soe Jesn% T36412070-70-00000 1 tohec0 00.0 33 79.66 alp1% P U Z:0412070-70-0002 tohrec oheco 00.06019% T226412020-70-00000 33 00.0 fieot T:6412020-70-02020 33 ohrec 2.0 etsy T64:070-70-0000 33 tohrec ecinse T0412070-70-00020 33 tohec 00:0 12.0 Jasn% 2I64:2070-7000020 33 oheco ohec 00.000 OLPT% 1 T9415412070-70-0000 T 00.0609% 1 T6415412070-70-00000 T sohec 00.0 e0 1 T94154:2070-70-2200 T tohrec 00.0etsys P TO6415412070-20-00000 T trohrec 00.0 n% IP T64:51412070-70-0002 T tohrec ohrec0 00.0 Jasn% 1 T9415412070-70-0000 T 00.66 1d T841412070-70-00000 T ohrec LP1% 00.016919% 1 T84154:2020-70-2200 T trohreco 1 T8415412070-70-00020 00.0 fieo T tohrec0 00.es IP 84:5412070-70=0002 T ohreco T 00.0 lne 1 T8415412070-70-0000 sohec T 00.0 Josn% P T841541070-702000 sohrec d- - s#[-roheo00o]