sar

sar - Collect, report, or save system activity information.

配置

修改配置文件

若 /usr/lib/systemd/system/ 和 /etc/systemd/system 目录下存在同名文件,systemd 将解析 /etc/systemd/system 下的文件

# 不直接编辑原始文件,相当于做一个备份
cp /usr/lib/systemd/system/sysstat-collect.timer /etc/systemd/system/
vim /etc/systemd/system/sysstat-collect.timer

[Timer]
# 默认每10分钟运行一次
# OnCalendar=*:00/10
# 修改为2分钟运行一次
OnCalendar=*:00/02

启动

systemctl daemon-reload
systemctl enable --now sysstat-collect.timer

说明

选项说明

选项
说明

-B

Reports memory paging statistics

-b

Reports I/O and transfer statistics for all devices

-d

Reports disk I/O statistics for each block device

-n

Reports network statistics

-q

Reports queue length and load averages

-r

Reports memory utilization statistics

-o

Save the readings in the file in binary form

-f

Extract records from filename (created by the -o filename flag)

-p

Pretty-print device names. Use this option in conjunction with option -d.

-q 选项输出列说明

列名
说明

runq-sz

Run queue length (number of tasks waiting for run time)

plist-sz

Number of tasks in the task list

ldavg-1

System load average for the last minute. The load average is calculated as the average number of runnable or running tasks (R state), and the number of tasks in uninterruptible sleep (D state) over the specified interval

ldavg-5

System load average for the past 5 minutes

ldavg-15

System load average for the past 15 minutes

blocked

Number of tasks currently blocked, waiting for I/O to complete

示例

以2秒为间隔报告3次,并将结果保存至文件中

从文件读取信息

使用 - 采集日志

收集一段时间日志,并写入文件保存

非交互式使用(写入定时任务)

The sa1 script invokes /usr/lib64/sa/sadc that collects data for a single one second measuring interval.

By default, the cron command runs the sa1 script every 10 minutes, and the sa2 script writes a daily report to the /var/log/sa/ saDD or the /var/log/ sa/saYYYMMDD file, where DD is the current day, MM is the current month, and YYYY is the current year.

使用 - 查看日志

日志路径

查看指定日志文件内容

修改时间为 24h 制显示

或者修改命令 alias 也可达到 24h 制显示效果

查看指定时段日志

对指定时段日志结果进行处理排序

Last updated