关于 sysstat
sysstat 是一个软件包, 包含监测系统性能及效率的一组工具, 这些工具对于收集系统性能数据, 比如 CPU 使用率, 硬盘和网络吞吐数据, 这些数据的收集和分析, 有利于判断系统是否正常运行和提高系统运行效率.
sysstat 软件包集成如下工具
iostat提供 CPU 使用率及硬盘吞吐效率的数据mpstat提供单个处理器或多个处理器相关数据sar负责收集, 报告并存储系统活跃的信息pidstat提供 Linux 进程的 I/O, CPU , Memory 等相关信息sadc收集系统 activity data, 是为 sar 所设计的后端sa1负责收集并存储每天系统动态信息到一个二进制的文件中. 它是通过计划任务工具cron来运行, 是为 sadc 所设计的程序前端程序sa2负责把每天的系统活跃性息写入总结性的报告中. 它是为 sar 所设计的前端, 要通过cron来调用sadc是系统动态数据收集工具, 收集的数据被写一个二进制的文件中, 它被用作 sar 工具的后端sadf显示被sar通过多种格式收集的数据nfsiostat提供 NFS input/output 的统计数据cifsiostat提供 CIFS 统计数据
安装 sysstat
对于大多数系统, 都有这个软件包, 软件名以 sysstat 开头.
对于 Debian 或 deb 软件包为基础的系统
[bash]
[root@localhost ~]# apt-get install sysstat
[/bash]
Fedora 系统或以 RPM 包管理的系统
[bash]
[root@localhost ~]# yum install sysstat
[/bash]
如果是RPM包, 可用下面的命令来安装
[bash]
[root@localhost ~]#rpm -ivh sysstat-*.*.*-*.src.rpm
[/bash]
通过源码包编译安装
到官方下载源码包, 目前最新版本是 sysstat-10.0.0, 下载地址
[bash]
[root@localhost ~]# tar zxvf sysstat-10.0.0.tar.gz
[root@localhost ~]$ cd sysstat-10.0.0
[root@localhost sysstat-10.0.0]# ./configure
[root@localhost sysstat-10.0.0]# make
[root@localhost sysstat-10.0.0]# make install
[/bash]
在运行配置脚本时, 可设置各参数.通过
./configure -help可获得各参数列表及其说明.NOTE:sysstat <= v7.0.4 不支持配置脚本, 所以在配置 sysstat 时需要用
make config来代替./configuresysstat 计划任务及其运行
如果想得到 sysstat 工具集所收集的系统信息自动存为某个文件中, 则必须通过cron 为 sa1 和sa2 做计划任务. 我们可以通过修改用户的crontab. 在默认的情况下, sysstat 历史信息将被存放在/var/log/sa文件中.
cron 计划
在root用户, 通过
crontab -e 来添加下面的一段(如果安装时有修改过参数, 请对照执行修改如下)[bash]
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/local/lib/sa/sa1 -d 1 1
# 0 * * * * root /usr/local/lib/sa/sa1 -d 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/local/lib/sa/sa2 -A
[/bash]
每天运行得到的信息都会保存到
/var/log/sa目录, 运行sar -A 命令可得到类似于该报告的信息. 创建 sysstat 的启动脚本
[bash]
[root@localhost ~]# touch /etc/rc.d/init.d/sysstat
[root@localhost ~]# vim /etc/rc.d/init.d/sysstat
[/bash]
将如下代码加入 /etc/rc.d/init.d/sysstat
[bash]
#!/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
[/bash]
保存后, 执行如下命令
[bash]
[root@localhost ~]# chmod 755 /etc/rc.d/init.d/sysstat
[/bash]
sysstat 启动脚本需要在系统启动时就开始运行. 所以, 需要为其在 /etc/rc.d/rcsysinit.d下创建一符号链接.命令如下:
[bash]
[root@localhost ~]# ln -sf /etc/rc.d/init.d/sysstat /etc/init.d/rc.sysinit/sysstat
[/bash]
有了 sysstat 的守护进程, 这样开机后, sysstat的守护进程, 就时时刻刻的为我们服务了. sa , sa1或sa2自动把信息存在 /var/log/sa 目录的二进制文件中.
当然, 也可以通过手动的方法来打开 sysstat 的守护程序;
[bash]
[root@localhost ~]# /etc/rc.d/init.d/sysstat start
[/bash]
or
[bash]
[root@localhost ~]# /usr/local/lib/sa/sa1
[root@localhost ~]# /usr/local/lib/sa/sa2
[/bash]
NOTE:如果在配置时有加入
--enable-install-cron参数, 则上面所创建的 crontab, startup script and link在安装时自动创建. REFRENCE: sysstat
[...] 是sysstat 一组件, 用来即时显示系统, 比如 自从系统启动开始的 CPU 平均时间 (与 [...]
回复删除