Difference between revisions of "Sar"

From wikieduonline
Jump to navigation Jump to search
 
(77 intermediate revisions by 4 users not shown)
Line 1: Line 1:
 +
{{lowercase}}
 
<code>[[Wikipedia: sar (Unix)|sar]]</code> (System Activity Report) is a system utility command used to collect and report different metrics such us [[system load]], CPU activity, [[memory]] (<code>[[sar -r]]</code>), paging (<code>sar -B</code>), swap (<code>sar -S</code>), disk ([[sar -d]]), device load and network. It is extremely useful in analyzing current and recent recorded [[system performance]]. Most Linux distributions provide sar utility binary in the <code>sysstat</code> package. You will also find sar in Solaris, AIX, HP-UX but not in MacOs or FreeBSD.
 
<code>[[Wikipedia: sar (Unix)|sar]]</code> (System Activity Report) is a system utility command used to collect and report different metrics such us [[system load]], CPU activity, [[memory]] (<code>[[sar -r]]</code>), paging (<code>sar -B</code>), swap (<code>sar -S</code>), disk ([[sar -d]]), device load and network. It is extremely useful in analyzing current and recent recorded [[system performance]]. Most Linux distributions provide sar utility binary in the <code>sysstat</code> package. You will also find sar in Solaris, AIX, HP-UX but not in MacOs or FreeBSD.
  
== Installation ==
+
== [[Sar installation]] ==
One line command for installation and basic configuration for collecting :
 
* Debian/Ubuntu:
 
:: <code>apt-get -y install sysstat; [[sed]] -i 's/ENABLED="false"/ENABLED="true"/g' /etc/default/sysstat && service sysstat restart && sar</code>
 
::Optionally modify collection interval in: <code>/etc/[[cron.d]]/sysstat</code>
 
::Optionally modify collection options in (SADC_OPTIONS="-S XALL"): <code>/etc/sysstat/sysstat</code> (<code>man sadc</code>)
 
* Redhat/Oracle Linux/AWS AMI:
 
:: <code>yum -y install sysstat && service sysstat start</code>
 
  
 +
== Binaries ==
 +
*<code>/usr/bin/[[sadc]]</code> - System Activity Data Collector, a backend to the sar command. Writes binary log of kernel data to the <code>/var/log/sa/saXX</code> file, where the XX parameter indicates the current day
 +
*<code>/usr/bin/sadf</code> - System Activity Data Formatter.        Display data collected by sar in multiple formats.
 +
*<code>/usr/bin/sar.sysstat</code> -- (sar is a symbolink link to this binary)
  
Installing sar Debian, you have to install sysstat package that includes sar and some other performance tools:
+
*<code>/usr/bin/cifsiostat</code>
* <code>[[apt-get]] -y install sysstat</code>
+
*<code>/usr/bin/[[iostat]]</code>
* Checking installation: <code>[[dpkg]] -l sysstat</code>
+
*<code>/usr/bin/[[mpstat]]</code>
* Binaries installed in ''/usr/bin/'' directory: <code>dpkg -L sysstat | grep "/usr/bin"</code>. Sysstat package contains sar and some other utilities.
+
*<code>/usr/bin/pidstat</code>
* [[Installing sysstat using Ansible]]
+
*<code>/usr/bin/tapestat</code>
<pre>
 
/usr/bin/sadc - System Activity Data Collector, a backend to the sar command. Writes binary log of kernel data to the /var/log/sa/saXX file, where the XX parameter indicates the current day
 
/usr/bin/sadf - System Activity Data Formatter.        Display data collected by sar in multiple formats.
 
/usr/bin/sar.sysstat  (sar is a symbolink link to this binary)
 
</pre>
 
<pre>
 
/usr/bin/cifsiostat
 
/usr/bin/iostat
 
/usr/bin/mpstat
 
/usr/bin/pidstat
 
/usr/bin/tapestat
 
</pre>
 
  
 
== Configuration files ==
 
== Configuration files ==
[[Debian]]/[[Ubuntu]]:
+
* [[Debian]]/[[Ubuntu]]:
:<code> /etc/default/sysstat</code>
+
:<code>[[/etc/default/sysstat]]</code>
:<code> /etc/cron.d/sysstat</code>   // Collection interval defined in cron configuration
+
:<code>[[/etc/cron.d/sysstat]]</code>     (Collection interval defined in cron configuration)
:<code> /etc/sysstat/sysstat</code>
+
:<code>[[/etc/sysstat/sysstat]]</code>   ([[SADC]]_OPTIONS)
 
:<code>/etc/sysstat/sysstat.ioconf</code>
 
:<code>/etc/sysstat/sysstat.ioconf</code>
::Data directory: <code>/var/log/sysstat</code>
+
::Data directory: <code>[[/var/log/sysstat/]]</code>
  
[[RHEL]]
+
* [[RHEL]]
cat /etc/sysconfig/sysstat
+
:<code>cat [[/etc/sysconfig/sysstat]]</code>
cat /etc/cron.d/sysstat
+
:<code>cat [[/etc/cron.d/sysstat]]</code>
  
 
== Activation in Debian ==
 
== Activation in Debian ==
* To start collection data modify file <code>/etc/default/sysstat</code>, changing text <code>disabled</code> by <code>enabled</code>: <code>vi /etc/default/sysstat</code>
+
* To start collection data modify file <code>[[/etc/default/sysstat]]</code>, changing text <code>disabled</code> by <code>enabled</code>: <code>vi /etc/default/sysstat</code>
* <code>service sysstat restart</code> (sysstat written with two "ss" do not misspell with systat with just one "s")
+
* <code>[[service sysstat restart]]</code> (sysstat written with two "ss" do not misspell with systat with just one "s")
  
 
Modifying number of days to keep and some other options are done in <code>/etc/sysstat/sysstat</code> file. By default Debian collect files for <code>HISTORY=7</code> 7 days.
 
Modifying number of days to keep and some other options are done in <code>/etc/sysstat/sysstat</code> file. By default Debian collect files for <code>HISTORY=7</code> 7 days.
Line 64: Line 50:
 
=== Collection interval configuration  ===
 
=== Collection interval configuration  ===
 
To change for every 10 minutes to every 2 minutes or every minute, modify [[cron]] job in file: <code>/etc/cron.d/sysstat</code>
 
To change for every 10 minutes to every 2 minutes or every minute, modify [[cron]] job in file: <code>/etc/cron.d/sysstat</code>
<pre>
 
5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
 
  
Every 5 minutes
+
5-55/10 * * * * root command -v [[debian-sa1]] > /dev/null && debian-sa1 1 1
*/5 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
+
 
 +
Every minute
 +
* * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
  
Every 2 minutes
+
Every 5 minutes
*/2 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
+
*/5 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
  
Every minute
+
Every 2 minutes
* * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
+
*/2 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
</pre>
 
  
 
== Usage ==
 
== Usage ==
Line 81: Line 66:
  
 
Binaries
 
Binaries
* <code>/usr/bin/sar</code> -- reporting utility --  it is a link to /usr/bin/sar.sysstat
+
* <code>[[/usr/bin/sar]]</code> -- reporting utility --  it is a link to /usr/bin/sar.sysstat
 
* <code>/usr/lib64/sa/sadc</code>  -- System activity data collector binary, a backend to the sar command. Writes binary log of kernel data to the /var/log/sa/sadd file, where the dd parameter indicates the current day
 
* <code>/usr/lib64/sa/sadc</code>  -- System activity data collector binary, a backend to the sar command. Writes binary log of kernel data to the /var/log/sa/sadd file, where the dd parameter indicates the current day
  
Scripts
+
[[Shell]] scripts
* <code>/usr/lib64/sa/sa1</code>
+
* <code>/usr/lib64/sa/[[sa1]]</code> or <code>[[/usr/lib/sysstat/sa1]]</code >Collect and store binary data
* <code>/usr/lib64/sa/sa2</code>
+
* <code>/usr/lib64/sa/[[sa2]]</code> Create a report
 +
 
 +
 
 +
* <code>[[sar --help]]</code>
  
 
== Basic Usage ==
 
== Basic Usage ==
 
* Displays collected system activity, execute <code>sar</code>, you will have to wait some time, depending on your configuration, for getting collected information:  
 
* Displays collected system activity, execute <code>sar</code>, you will have to wait some time, depending on your configuration, for getting collected information:  
:<code>sar</code>
+
:<code>[[sar (example)|sar]]</code>
:<code>sar -A</code> Report all collected date
+
:<code>[[sar -A]]</code> Report all collected date
 +
 
 
'''[[Memory]]'''
 
'''[[Memory]]'''
 
:<code>[[sar -r]]</code>
 
:<code>[[sar -r]]</code>
'''Disk'''
+
 
 +
'''[[Swap]]'''
 +
:<code>[[sar -S]]</code>
 +
:<code>[[sar -W]]</code>
 +
 
 +
'''Disk, [[filesystems]]'''
 
:<code>[[sar -d]]</code> To report disk activity. See also <code>[[iostat]] -x</code>.
 
:<code>[[sar -d]]</code> To report disk activity. See also <code>[[iostat]] -x</code>.
:<code>[[sar -F]]</code> To report disk and [[inodes]] usage. Requires sadc option in <code>/etc/sysstat/sysstat</code> <code>-S XDISK</code> or <code>-S XALL</code> activated.
+
:<code>[[sar -F]]</code> To report filesystems statistics, disk and [[inodes]] usage. Requires sadc option in <code>/etc/sysstat/sysstat</code> <code>-S XDISK</code> or <code>-S XALL</code> activated.
'''network'''
+
'''[[Network]]'''
:<code>sar -n ALL</code> To show '''network''' data collected
+
:<code>[[sar -n ALL]]</code> To show '''network''' data collected
 
'''power management'''
 
'''power management'''
 
:<code>sar -m ALL</code> To show [[power management]] data collected including [[cpu temperature]] (Requires <code>[[sensors]]/[[lm-sensors]]</code> utility to be installed)
 
:<code>sar -m ALL</code> To show [[power management]] data collected including [[cpu temperature]] (Requires <code>[[sensors]]/[[lm-sensors]]</code> utility to be installed)
'''[[process]]'''
+
'''[[Process]]'''
 
:<code>[[sar -q]]</code>
 
:<code>[[sar -q]]</code>
  
 +
'''[[Interrupts]]'''
 +
:<code>[[sar -I]] ALL</code>
  
  
* <code>[[systemctl]] status sysstat</code>
+
* <code>[[systemctl status sysstat]]</code>
 
* <code>systemctl restart sysstat</code>
 
* <code>systemctl restart sysstat</code>
  
Line 112: Line 108:
 
# Install and configure sar to record system activity every 5 minutes
 
# Install and configure sar to record system activity every 5 minutes
 
# Read [[sysstat changelog]]: https://github.com/sysstat/sysstat/blob/master/CHANGES
 
# Read [[sysstat changelog]]: https://github.com/sysstat/sysstat/blob/master/CHANGES
# Read data from day 07 to day 11: <code>echo sa{07..11}  | [[xargs]] -n1 sar -f</code>
+
# Read data from day 07 to day 11: <code>echo /var/log/sysstat/sa{07..11}  | [[xargs]] -n1 sar -f</code>
 +
# [[Read all sar collected files]]: <code>[[for]] SA_FILE in $(ls -1 [[/var/log/sysstat/]]sa??); do sar -f $SA_FILE; done</code>
 +
 
 +
== Related==
 +
* <code>[[collectl]]</code>
 +
* [[Prometheus Node exporter]]
 +
* [[Grafana agent]]
 +
* [[Metricbeat]]
 +
* [[Zabbix agent]]
 +
* [[libsensors4]] package
 +
* <code>[[%nice]]</code>
  
 
== See also ==
 
== See also ==
* <code>[[atop]]</code>
 
 
* {{io performance commands}}
 
* {{io performance commands}}
* [[netdata]], [[MetricBeat]]
+
* {{sar}}
* [http://sebastien.godard.pagesperso-orange.fr System Activity Report Homepage]
 
* isag - [[wikipedia:tcl]] based command to plot sar/sysstat data
 
* sargraph https://github.com/sysstat/sysstat/blob/master/contrib/sargraph/sargraph2
 
* [[w:Ksar (Unix sar grapher)]]
 
 
* systat [[FreeBSD]]<ref>https://www.freebsd.org/cgi/man.cgi?query=systat&apropos=0&sektion=1&manpath=FreeBSD+Ports+11.2&arch=default&format=html</ref> or NetBSD commands.
 
* systat [[FreeBSD]]<ref>https://www.freebsd.org/cgi/man.cgi?query=systat&apropos=0&sektion=1&manpath=FreeBSD+Ports+11.2&arch=default&format=html</ref> or NetBSD commands.
* Telegraph https://docs.influxdata.com/telegraf/v1.12/introduction/getting-started/
+
* {{sysstat}}
 +
* {{Metrics collectors}}
  
 
[[Category:Server administration]]
 
[[Category:Server administration]]
[[Category:Operating systems]]
 
[[Category:Linux]]
 
 
[[Category:monitoring]]
 
[[Category:monitoring]]
  

Latest revision as of 05:31, 9 June 2024

sar (System Activity Report) is a system utility command used to collect and report different metrics such us system load, CPU activity, memory (sar -r), paging (sar -B), swap (sar -S), disk (sar -d), device load and network. It is extremely useful in analyzing current and recent recorded system performance. Most Linux distributions provide sar utility binary in the sysstat package. You will also find sar in Solaris, AIX, HP-UX but not in MacOs or FreeBSD.

Sar installation[edit]

Binaries[edit]

  • /usr/bin/sadc - System Activity Data Collector, a backend to the sar command. Writes binary log of kernel data to the /var/log/sa/saXX file, where the XX parameter indicates the current day
  • /usr/bin/sadf - System Activity Data Formatter. Display data collected by sar in multiple formats.
  • /usr/bin/sar.sysstat -- (sar is a symbolink link to this binary)
  • /usr/bin/cifsiostat
  • /usr/bin/iostat
  • /usr/bin/mpstat
  • /usr/bin/pidstat
  • /usr/bin/tapestat

Configuration files[edit]

/etc/default/sysstat
/etc/cron.d/sysstat (Collection interval defined in cron configuration)
/etc/sysstat/sysstat (SADC_OPTIONS)
/etc/sysstat/sysstat.ioconf
Data directory: /var/log/sysstat/
cat /etc/sysconfig/sysstat
cat /etc/cron.d/sysstat

Activation in Debian[edit]

  • To start collection data modify file /etc/default/sysstat, changing text disabled by enabled: vi /etc/default/sysstat
  • service sysstat restart (sysstat written with two "ss" do not misspell with systat with just one "s")

Modifying number of days to keep and some other options are done in /etc/sysstat/sysstat file. By default Debian collect files for HISTORY=7 7 days.

Configuration in Debian/Ubuntu[edit]

Main Configuration file: /etc/sysstat/sysstat[edit]

/etc/sysstat/sysstat Everything configured in this file, including data collection (sadc) options, except collection interval configured in crontab: /etc/cron.d/sysstat

/etc/sysstat/sysstat
HISTORY=7
COMPRESSAFTER=10
SADC_OPTIONS="-S XALL"
SA_DIR=/var/log/sysstat
ZIP="bzip2"

By default configuration SADC_OPTIONs is configure to SADC_OPTIONS="-S DISK" you can change SADC_OPTIONS default option to collect all data: SADC_OPTIONS from -S DISK to -S XALL. See man sadc for more options: { DISK | INT | IPV6 | POWER | SNMP | XDISK | ALL | XALL [,...] }.

Collection interval configuration[edit]

To change for every 10 minutes to every 2 minutes or every minute, modify cron job in file: /etc/cron.d/sysstat

5-55/10 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
Every minute
* * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
Every 5 minutes
*/5 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1
Every 2 minutes
*/2 * * * * root command -v debian-sa1 > /dev/null && debian-sa1 1 1

Usage[edit]

System activity collection is provided by 4 programs, two binaries sar,sadc and two shell scriptssa1sa2.

Binaries

  • /usr/bin/sar -- reporting utility -- it is a link to /usr/bin/sar.sysstat
  • /usr/lib64/sa/sadc -- System activity data collector binary, a backend to the sar command. Writes binary log of kernel data to the /var/log/sa/sadd file, where the dd parameter indicates the current day

Shell scripts


Basic Usage[edit]

  • Displays collected system activity, execute sar, you will have to wait some time, depending on your configuration, for getting collected information:
sar
sar -A Report all collected date

Memory

sar -r

Swap

sar -S
sar -W

Disk, filesystems

sar -d To report disk activity. See also iostat -x.
sar -F To report filesystems statistics, disk and inodes usage. Requires sadc option in /etc/sysstat/sysstat -S XDISK or -S XALL activated.

Network

sar -n ALL To show network data collected

power management

sar -m ALL To show power management data collected including cpu temperature (Requires sensors/lm-sensors utility to be installed)

Process

sar -q

Interrupts

sar -I ALL


Activities[edit]

  1. Install and configure sar to record system activity every 5 minutes
  2. Read sysstat changelog: https://github.com/sysstat/sysstat/blob/master/CHANGES
  3. Read data from day 07 to day 11: echo /var/log/sysstat/sa{07..11} | xargs -n1 sar -f
  4. Read all sar collected files: for SA_FILE in $(ls -1 /var/log/sysstat/sa??); do sar -f $SA_FILE; done

Related[edit]

See also[edit]


Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. By using this site, you agree to the Terms of Use and Privacy Policy.

Original source: https://en.wikiversity.org/wiki/Linux_server_administration/sar

Advertising: