sysstat-----获取服务器负载历史记录

 sysstat工具与负载历史回放

  很多系统负载过高的时候我们是无法立即获知或者立即解决的,当检测到或者知道历史的高负载状况时,可能需要回放历史监控数据,这时 sar 命令就派上用场了,sar命令同样来自sysstat工具包,可以记录系统的CPU负载、I/O状况和内存使用记录,便于历史数据的回放。

  Ubuntu系统上,sysstat的配置文件在/etc/default/sysstat,sysstat默认关闭,通过将该文件中的ENABLED改为"true"启用;历史日志的存放位置为/var/log/sysstat

  Red Hat系统上,sysstat的配置文件在/etc/sysconfig/sysstat文件,历史日志的存放位置为/var/log/sa

  两种系统上,统计信息都是每10分钟记录一次,每天的23:59会分割统计文件,这些操作的频率都在/etc/cron.d/sysstat文件配置。

1. sar命令查看CPU、内存和磁盘记录

  默认情况下,sar命令显示当天的统计信息,不带参数显示CPU统计信息,参数-r显示收集的内存记录,-b显示磁盘I/O

例6. 使用sar命令查看当天CPU使用

复制代码
 1 # sar
 2 Linux 3.13.0-55-generic (ISeR-Server1)     08/12/2015     _x86_64_    (4 CPU)
 3 
 4 12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
 5 12:05:01 AM     all      3.83      0.02      4.24      0.61      0.00     91.30
 6 12:15:01 AM     all      3.57      0.02      4.28      0.58      0.00     91.54
 7 12:25:01 AM     all      3.83      0.02      5.16      0.60      0.00     90.39
 8 12:35:01 AM     all      3.98      0.02      5.66      0.58      0.00     89.76
 9 12:45:01 AM     all      3.86      0.02      5.26      0.59      0.00     90.28
10 12:55:01 AM     all      3.77      0.02      5.19      0.60      0.00     90.42
复制代码

例7. 使用sar命令查看当天内存使用

复制代码
1 # sar -r
2 Linux 3.13.0-55-generic (ISeR-Server1)     08/12/2015     _x86_64_    (4 CPU)
3 
4 12:00:01 AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit  kbactive   kbinact   kbdirty
5 12:05:01 AM   6420736   5839392     47.63    242640   1366912   6811944     55.56   4324000   1202152        24
6 12:15:01 AM   6423128   5837000     47.61    242640   1367348   6830944     55.72   4320608   1202400        48
7 12:25:01 AM   6430984   5829144     47.55    242640   1367548   6814980     55.59   4314376   1202468        48
8 12:35:01 AM   6422924   5837204     47.61    242640   1367848   6817224     55.60   4321604   1202576        48
9 12:45:01 AM   6427300   5832828     47.58    242640   1368056   6822240     55.65   4318412   1202572        28
复制代码

例8. 使用sar命令查看当天IO统计记录

复制代码
1 # sar -b
2 Linux 3.13.0-55-generic (ISeR-Server1)     08/12/2015     _x86_64_    (4 CPU)
3 
4 12:00:01 AM       tps      rtps      wtps   bread/s   bwrtn/s
5 12:05:01 AM      7.44      0.00      7.44      0.00    279.22
6 12:15:01 AM      6.45      0.00      6.45      0.00    255.84
7 12:25:01 AM      6.59      0.00      6.59      0.00    260.20
8 12:35:01 AM      6.51      0.00      6.51      0.00    261.42
9 12:45:01 AM      6.42      0.00      6.42      0.00    255.79
复制代码

2. 使用sar查看指定时间、指定日期的历史记录

例9. 使用参数-s和-e限定查看的时间

复制代码
1 # sar -s 20:00:00
2 Linux 3.13.0-55-generic (ISeR-Server1)     08/12/2015     _x86_64_    (4 CPU)
3 
4 08:05:01 PM     CPU     %user     %nice   %system   %iowait    %steal     %idle
5 08:15:01 PM     all      3.98      0.02      6.07      0.58      0.00     89.34
6 08:25:01 PM     all      4.32      0.02      5.74      0.58      0.00     89.34
7 Average:        all      4.15      0.02      5.91      0.58      0.00     89.34
复制代码

   例9 只查看当天20:00:00后的CPU统计记录

例10. 使用参数-f查看本月内之前某一天的历史统计信息

复制代码
 1 # sar -f /var/log/sysstat/sa08
 2 Linux 3.13.0-55-generic (ISeR-Server1)     08/08/2015     _x86_64_    (4 CPU)
 3 
 4 12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
 5 12:05:01 AM     all      3.65      0.02      2.79      0.60      0.00     92.94
 6 12:15:01 AM     all      3.45      0.02      3.03      0.56      0.00     92.94
 7 12:25:01 AM     all      3.43      0.02      3.25      0.56      0.00     92.74
 8 12:35:01 AM     all      3.44      0.01      3.09      0.56      0.00     92.89
 9 12:45:01 AM     all      3.25      0.02      1.35      0.55      0.00     94.83
10 12:55:01 AM     all      3.36      0.02      1.77      0.56      0.00     94.29
原文地址:https://www.cnblogs.com/python-cat/p/7607787.html