sar 指令應用


    Sar - RedHat/CentOS 內建的系統效能分析工具。


    • 內建在 CentOS/RedHat 5+版本,無需另外安裝。
    • 可查詢最近幾日的系統資源使用歷史紀錄,常作為事件後的問題偵錯工具。



    • CPU / IO / System / Nice / Idle percentages
    • Network Traffic / Network Errors
    • Load Average and Run queue
    • Interrupts
    • Memory Free / Cached / Buffered / Swapped
    • Device usage per Major/Minor number
    • And many others

    官方連結:How to use SAR to Monitor System Performance in Red Hat Enterprise Linux (如無法存取連結,請見下方附檔區)

    Sar 如何運作

    • SAR writes to log files in /var/log/sa. This directory holds two types of files - sa\#\# files (binary) and sar\#\# files (text).
    • The number at the end of the file corresponds to the day of the month that file was recording.
    • For example, an sa03 file refers to the 03 day of the month.
    • When the sysstat package is installed it places a file into /etc/cron.d/sysstat.
    • This sets up two cron jobs.
      1. job to record statistics every 10 minutes.
      2. job to write the binary sa\#\# file to a text sar\#\# file once a day (typically right before midnight).
    • Additionally, it places a configuration file in /etc/sysconfig/sysstat.
    • 預設是保留最近七日的歷史資料,若要變更,可以修改 /etc/sysconfig/sysstat。
      Note that RHEL 4/5 sysstat does not support keeping more than 1 month of data; however, in RHEL6 if a HISTORY value greater than 28 is declared, SAR log files are automatically split up into separate directories.

    Sar Cron Jobs:


    # run system activity accounting tool every 10 minutes 
    */10 * * * * root /usr/lib/sa/sa1 1 1 
    # generate a daily summary of process accounting at 23:53 
    53 23 * * * root /usr/lib/sa/sa2 -A

    If it is desired for SAR to collect data more frequently, simply change "*/10" to a new interval.

    For example, if to make SAR to track every 5 minutes, simply change to "*/5".

    NOTE: SAR does not add significant load to a server. It safely can be tuned down to 2 minute intervals without seeing a significant problem. SAR also does not grab individual block data.


    RedHat 5/6/7

    yum install sysstat


    顯示今日 CPU 狀態

    // 每個處理器
    sar -P ALL
    // 顯示 CPU
    sar -u 

    顯示最近月份 13 號的網路狀態

    sar -n ALL -f /var/log/sa/sa13

    顯示最近一個月份 7 號 時間 10:00 - 14:00 的記憶體使用狀況,並將結果導出一個檔案

    sar -r -s 10:00:00 -e 14:00:00 -f /var/log/sa/sa07 -o /tmp/mem.txt


    sar -u 1
    sar -u 1 10
    sar -r 1
    sar -r 1 10
    sar -S 1
    sar -S 1 10
    sar -b 1
    sar -b 1 10
    sar -p -d 1
    sar -p -d 1 10 


    RedHat 提供幾個透過線上的工具來分析

    I/O 使用分析:

    在系統內先執行 lsblk 將輸出內容導出一個檔案 lsblk.out,將此檔連同要分析的任一個 sarXX 檔上傳該網址,即可以圖形顯示系統 I/O 的使用狀態。

    Memory 使用分析:

    標籤 (Edit tags)
    • No tags

    文件 1

    How to use SAR to Monitor System Performance in Red Hat Enterprise Linux
    99.77 KB09:46, 8 Feb 2017alang動作
    您必須 登入 才能發佈評論。
    Powered by MindTouch Core