Skip to content

Insight and analysis of technology and business strategy

Chart your course with sar

The sar (system activity reporter) is a Linux utility that actually started life long ago in System V Unix. In spite of its ancient origins, sar is still quite useful, and has even been enhanced in recent versions of Linux. The use of sar is not limited to root - any user can run sar and its utilities. Most Linux systems have sar installed and enabled by default to collect sar data at 10 minute intervals and retain that data for 10 days. The reports output by sar will look familiar:  
[sourcecode language="bash" padlinenumbers="true"] jkstill@poirot ~/tmp $ sar -d | head -20 Linux 4.4.0-53-generic (poirot.jks.com) 08/07/17 _x86_64_ (1 CPU) 00:00:01 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util 00:02:01 dev7-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-4 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-5 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev7-6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:02:01 dev8-0 0.40 0.00 4.97 12.43 0.00 0.26 0.26 0.01 00:02:01 dev252-0 0.63 0.00 4.90 7.78 0.00 0.16 0.16 0.01 00:02:01 dev252-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-1 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-2 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-3 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-4 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-5 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 00:04:01 dev7-6 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 [/sourcecode]
This report format is good for a quick look at different metrics to get an overall idea of system perform, disk metrics in the previously shown example. However what if you would like to collate this data into something more readily consumed for charting an analysis, such as a CSV file? The standard output of sar does not readily lend itself to such use without quite a bit of work. The sar utility is part of the Linux sysstat package and contains not only sar, but sadf. If sar is available then so is sadf. What is sadf you say? sadf is a the sar data formatting utility, and can output data in CSV, XML and other formats. Using sadf a bash script can be created that will extract sar data for many Linux subsystems and write that data in the format of your choice, CSV in this case. The asp.sh script does just that, creating CSV files that can then be used for charting and analysis.  
[sourcecode language="bash"] #!/bin/bash # Jared Still - Pythian # still@pythian.com jkstill@gmail.com # 2017-07-20 # asp - another sar processor # tested on Red Hat Enterprise Linux Server release 6.6 (Santiago) # also tested on Linux Mint help() { echo echo $0 -s source-dir -d dest-dir echo } # variables can be set to identify multiple sets of copied sar files sarSrcDir='/var/log/sa' # RedHat, CentOS ... #sarSrcDir='/var/log/sysstat' # Debian, Ubuntu ... sarDstDir="sar-csv" csvConvertCmd=" sed -e 's/;/,/g' " while getopts s:d:h arg do case $arg in d) sarDstDir=$OPTARG;; s) sarSrcDir=$OPTARG;; h) help; exit 0;; *) help; exit 1;; esac done cat << EOF Source: $sarSrcDir Dest: $sarDstDir EOF #exit mkdir -p $sarDstDir || { echo echo Failed to create $sarDstDir echo exit 1 } echo "lastSaDirEl: $lastSaDirEl" # sar options # -d activity per block device # -j LABEL: use label for device if possible. eg. sentryoraredo01 rather than /dev/dm-3 # -b IO and transfer rates # -q load # -u cpu # -r memory utilization # -R memory # -B paging # -S swap space utilization # -W swap stats # -n network # -v kernel filesystem stats # -w context switches and task creation #sarDestOptions=( '-d -j LABEL -p' '-b' '-q' '-u ALL' '-r' '-R' '-B' '-S' '-W' '-n DEV,EDEV,NFS,NFSD,SOCK,IP,EIP,ICMP,EICMP,TCP,ETCP,UDP' '-v' '-w') # break up network into a separate file for each option # not all options available depending on sar version # for disk "-d" you may want one of ID, LABEL, PATH or UUID - check the output and the sar docs sarDestOptions=( '-d -j ID -p' '-b' '-q' '-u ALL' '-r' '-R' '-B' '-S' '-W' '-n DEV' '-n EDEV' '-n NFS' '-n NFSD' '-n SOCK' '-n IP' '-n EIP' '-n ICMP' '-n EICMP' '-n TCP' '-n ETCP' '-n UDP' '-v' '-w') #sarDestFiles=( sar-disk.csv sar-io.csv sar-load.csv sar-cpu.csv sar-mem-utilization.csv sar-mem.csv sar-paging.csv sar-swap-utilization.csv sar-swap-stats.csv sar-network.csv sar-kernel-fs.csv sar-context.csv) sarDestFiles=( sar-disk.csv sar-io.csv sar-load.csv sar-cpu.csv sar-mem-utilization.csv sar-mem.csv sar-paging.csv sar-swap-utilization.csv sar-swap-stats.csv sar-net-dev.csv sar-net-ede.csv sar-net-nfs.csv sar-net-nfsd.csv sar-net-sock.csv sar-net-ip.csv sar-net-eip.csv sar-net-icmp.csv sar-net-eicmp.csv sar-net-tcp.csv sar-net-etcp.csv sar-net-udp.csv sar-kernel-fs.csv sar-context.csv) lastSarOptEl=$

Top Categories

  • There are no suggestions because the search field is empty.

Tell us how we can help!

dba-cloud-services
Upcoming-Events-banner