专栏首页云计算与大数据How to view past performance with sar in Linux

How to view past performance with sar in Linux

There are many tools/utilities that can be used to analyze the current system performance. But how do we gauge the historic system performance? For that you can use the System Activity Report (SAR) tool. Using the sar tool, you will be able to look back over a period of time and see how the server has been running.

In this post we will see how to install and use the sysstat tools; thus, allowing you to examine historical system statistics.

Installing sysstat

First thing first, install the “sysstat” which provides the sar utility.

# apt-get install sysstat       ### Debian-based distributions
# yum install sysstat           ### RedHat Based distribution

The historic data for various linux distribution is stored in below directories: 1. Red Hat, Fedora, CentOS, and Scientific Linux should use the /var/log/sa directory 2. Debian, Mint, and Ubuntu users should use the /var/log/sysstat directory

By default, sar stats are collected every 10 minutes. The data is collected using a simple cron job configured within /etc/cron.d/sysstat. This job can be amended to collect the data as frequently as you require. Example /etc/cron.d/sysstat file is provided below.

# cat /etc/cron.d/sysstat
# Run system activity accounting tool every 10 minutes
*/10 * * * * root /usr/lib64/sa/sa1 1 1
# 0 * * * * root /usr/lib64/sa/sa1 600 6 &
# Generate a daily summary of process accounting at 23:53
53 23 * * * root /usr/lib64/sa/sa2 -A

Gathering historical sar data

1. Getting live sar data is easy with sar. By default sar operates in CPU mode. Simply using the command as named, we will receive CPU activity samples for every 10 minutes of the current day.

# sar
Linux 2.6.32-504.el6.x86_64 (geeklab)   09/28/2018      _x86_64_        (16 CPU)

12:00:01 AM     CPU     %user     %nice   %system   %iowait    %steal     %idle
12:10:01 AM     all      7.28      0.00      2.94      0.02      0.00     89.77
12:20:01 AM     all      7.16      0.00      2.47      0.02      0.00     90.35
12:30:01 AM     all      6.96      0.00      2.43      0.01      0.00     90.59
12:40:01 AM     all      6.92      0.00      2.42      0.01      0.00     90.64
...

2. Lets suppose you want to analyse the system performance at some past time. For example view system performance between 10 A.M. to 12 A.M. when application team faced a slowness in their app.

# sar -r -s 10:00:00 -e 12:00:00

sar uses the -s arguement to specify the start time of a data extract and another (-e) to set the end time. These parameters must be written in HH:MM:SS format, or sar will ignore them with an error. The -r argument is used to display memory usage data.

3. sar historic data is stored in /var/log/sa directory in case of RedHat based distributions. Files are simply binary formats containing sar data for each retained date. Files are prefixed with sa. Thus, sa23 is the sar data for the 23rd of the month. For example, on a CenOS/RHEL system.

# ls /var/log/sa
sa01  sa04  sa07  sa10  sa13  sa16  sa19  sa22  sa25  sa28  sar01  sar04  sar07  sar10  sar13  sar16  sar19  sar22  sar25  sar30
sa02  sa05  sa08  sa11  sa14  sa17  sa20  sa23  sa26  sa30  sar02  sar05  sar08  sar11  sar14  sar17  sar20  sar23  sar26  sar31
sa03  sa06  sa09  sa12  sa15  sa18  sa21  sa24  sa27  sa31  sar03  sar06  sar09  sar12  sar15  sar18  sar21  sar24  sar27

Execute the following command to view past I/O statistics for the 10th of the month:

# sar -f /var/log/sysstat/sa10 -b

Changing sar historical data retention

One can change the historical sar data retention using the file /etc/sysconfig/sysstat or /etc/sysstat/sysstat. Change the HISTORY parameter setting to the desired amount of days to retain data. For example, to keep 28 days of records, we could use this:

# cat /etc/sysconfig/sysstat
# sysstat-9.0.4 configuration file.

# How long to keep log files (in days).
# If value is greater than 28, then log files are kept in
# multiple directories, one for each month.
HISTORY=28

# Compress (using gzip or bzip2) sa and sar files older than (in days):
COMPRESSAFTER=31

# Parameters for the system activity data collector (see sadc manual page)
# which are used for the generation of log files.
SADC_OPTIONS="-S DISK"

# Compression program to use.
ZIP="bzip2"

本文分享自微信公众号 - 黑洞日志(heidcloud)

原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。

原始发表时间:2019-12-12

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • Configuring Spring Boot's Server, GZip compression, HTTP/2

    Spring Boot is powerful yet flexible. It tries to auto-configure most of the stu...

    heidsoft
  • Import Kafka data into OSS using E-MapReduce service

    Overview Kafka is a frequently-used message queue in open-source communities. A...

    heidsoft
  • TCP Flow Control

    TCP is the protocol that guarantees we can have a reliable communication channel...

    heidsoft
  • hdu 4405Aeroplane chess(概率DP)

    Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32...

    Gxjun
  • kube-scheduler最佳配置

    version: kubernetes 1.6.2 ##kube-scheduler Configuration 下面是我梳理的kube-scheduler的完...

    Walton
  • SAP CRM settype的重要性

    Product settype acts as a very important role in CRM WebClient UI architecture.

    Jerry Wang
  • centos7中python3环境支持s

    在centos7环境中常规安装python3的话无法支持sqlite3和ssl,所以在安装pytho3是需要带上sqlite3库和ssl库:

    py3study
  • V系列存储配置HyperSwap卷的时候报错,位图空间不够

    在一次配置双活过程中,按客户要求,需要配置11TB容量的卷,但是创建过程中,出现以下错误

    Mr.Mao Notes
  • Python简单验证文本的Zipf分布

    齐普夫定律是语言学专家Zipf在研究英文单词出现的频率时,发现如果把单词出现的频率按由大到小的顺序排列,则每个单词出现的频率与它的名次的常数次幂存在简单的反比关...

    周小董
  • 会说话的ABAP report

    report代码直接call的MS的sound engine,通过sapi.dll暴露出来,

    Jerry Wang

扫码关注云+社区

领取腾讯云代金券