ubuntu开启sar记录日志

发布时间 2023-04-06 01:28:27作者: 王恒志

背景

之前一直用CentOS系统,最近换到了ubuntu的,sar日志对分析系统状态和基本性能比较有帮助,发现在ubuntu上默认是不记录sar日志的

安装

apt-get install sysstat

开启服务

编辑/etc/default/sysstat文件,内容如下

#
# Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat
# and /etc/cron.daily/sysstat files
#

# Should sadc collect system activity informations? Valid values
# are "true" and "false". Please do not put other values, they
# will be overwritten by debconf!
ENABLED="true"

ENABLED的值修改成true

重启sysstat服务sudo systemctl restart sysstat.service

修改定时任务

sar记录日志是通过cron定时任务执行的
现在修改成每分钟记录一次
编辑/etc/cron.d/sysstat

# The first element of the path is a directory where the debian-sa1
# script is located
PATH=/usr/lib/sysstat:/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin

# Activity reports every 10 minutes everyday
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1

# Additional run at 23:59 to rotate the statistics file
59 23 * * * root command -v debian-sa1 > /dev/null && debian-sa1 60 2

将5-55/10 即5-55分之间,每10分钟记录一次改成*/1即每分钟记录一次

日志路径

和centos不一样的是
centos的路径在/var/log/sa
ubuntu的日志路径在/var/log/sysstat