Difference between revisions of "Sar (sysstat)"
(New page: In computing, <code>`sar`</code> (System Activity Report) is a Solaris-derived system monitor command used to report on various system loads, including CPU activity, memory/paging, device ...) |
(→External links) |
||
(6 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
In computing, <code>`sar`</code> (System Activity Report) is a Solaris-derived system monitor command used to report on various system loads, including CPU activity, memory/paging, device load, network, etc. Linux distributions provide <code>`sar`</code> through the <code>sysstat</code> package. | In computing, <code>`sar`</code> (System Activity Report) is a Solaris-derived system monitor command used to report on various system loads, including CPU activity, memory/paging, device load, network, etc. Linux distributions provide <code>`sar`</code> through the <code>sysstat</code> package. | ||
+ | |||
+ | These utilities are especially useful in Cloud Computing. | ||
==Utilities== | ==Utilities== | ||
Line 12: | Line 14: | ||
The statistics reported by <code>`sar`</code> deal with I/O transfer rates, paging activity, process-related activities, interrupts, network activity, memory and swap space utilization, CPU utilization, kernel activities, and TTY statistics, among others. Both UP and SMP machines are fully supported. | The statistics reported by <code>`sar`</code> deal with I/O transfer rates, paging activity, process-related activities, interrupts, network activity, memory and swap space utilization, CPU utilization, kernel activities, and TTY statistics, among others. Both UP and SMP machines are fully supported. | ||
+ | |||
+ | ==Example usage== | ||
+ | * CPU usage for all CPU cores on your machine | ||
+ | |||
+ | This gives the cumulative real-time CPU usage of all CPUs on your machine. "<code>1 3</code>" reports for every 1 seconds a total of 3 times. The most useful column/field in this report is "<code>%idle</code>" for the CPU load: | ||
+ | <pre> | ||
+ | $ sar -u 1 3 | ||
+ | Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) | ||
+ | |||
+ | 17:12:06 CPU %user %nice %system %iowait %steal %idle | ||
+ | 17:12:07 all 7.93 0.00 4.35 0.00 0.26 87.47 | ||
+ | 17:12:08 all 13.04 0.00 4.35 0.00 0.51 82.10 | ||
+ | 17:12:09 all 11.70 0.00 4.83 0.00 0.00 83.46 | ||
+ | Average: all 10.89 0.00 4.51 0.00 0.26 84.34 | ||
+ | </pre> | ||
+ | |||
+ | * CPU usage for all CPU core on your machine with extended output: | ||
+ | <pre> | ||
+ | $ sar -u ALL 1 3 | ||
+ | Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) | ||
+ | |||
+ | 17:16:04 CPU %usr %nice %sys %iowait %steal %irq %soft %guest %idle | ||
+ | 17:16:05 all 7.87 0.00 3.30 0.00 0.25 0.00 0.00 0.00 88.58 | ||
+ | 17:16:06 all 7.75 0.00 3.88 0.00 0.26 0.00 0.00 0.00 88.11 | ||
+ | 17:16:07 all 8.46 0.00 4.87 0.00 0.26 0.00 0.00 0.00 86.41 | ||
+ | Average: all 8.03 0.00 4.01 0.00 0.26 0.00 0.00 0.00 87.70 | ||
+ | </pre> | ||
+ | |||
+ | * CPU usage for second day of the month (Note: On some distros, the location of the <code>`sar`</code> logs is stored under <code>/var/log/sa/</code>): | ||
+ | $ sar -u -f /var/log/sysstat/sa02 | ||
+ | |||
+ | * CPU usage of an individual CPU or core | ||
+ | |||
+ | If you have 4 cores on your machine and would like to see what the individual cores are doing, execute the following command (note: the "<code>-P ALL</code>" displays statistics for all the individual cores and, in the following example, the "<code>CPU</code>" column has fields 0, 1, 2, and 3 and they indicate the corresponding CPU core numbers): | ||
+ | <pre> | ||
+ | $ sar -P ALL 1 1 | ||
+ | Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) | ||
+ | |||
+ | 17:29:05 CPU %user %nice %system %iowait %steal %idle | ||
+ | 17:29:06 all 7.65 0.00 4.59 0.00 0.26 87.50 | ||
+ | 17:29:06 0 10.42 0.00 3.12 0.00 1.04 85.42 | ||
+ | 17:29:06 1 13.13 0.00 11.11 0.00 0.00 75.76 | ||
+ | 17:29:06 2 4.12 0.00 3.09 0.00 0.00 92.78 | ||
+ | 17:29:06 3 2.00 0.00 2.00 0.00 0.00 96.00 | ||
+ | |||
+ | Average: CPU %user %nice %system %iowait %steal %idle | ||
+ | Average: all 7.65 0.00 4.59 0.00 0.26 87.50 | ||
+ | Average: 0 10.42 0.00 3.12 0.00 1.04 85.42 | ||
+ | Average: 1 13.13 0.00 11.11 0.00 0.00 75.76 | ||
+ | Average: 2 4.12 0.00 3.09 0.00 0.00 92.78 | ||
+ | Average: 3 2.00 0.00 2.00 0.00 0.00 96.00 | ||
+ | </pre> | ||
+ | |||
+ | Or, if you only want to display the statistics for a single core, try the following (e.g., for only the second core. Note that core numbers start from 0): | ||
+ | <pre> | ||
+ | $ sar -P 1 1 1 | ||
+ | Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) | ||
+ | |||
+ | 19:15:36 CPU %user %nice %system %iowait %steal %idle | ||
+ | 19:15:37 1 0.00 0.00 3.06 0.00 1.02 95.92 | ||
+ | Average: 1 0.00 0.00 3.06 0.00 1.02 95.92 | ||
+ | </pre> | ||
+ | |||
+ | Variations of the previous commands include: | ||
+ | |||
+ | $ sar -P ALL # Displays CPU usage broken down by all cores for the current day. | ||
+ | $ sar -P ALL 1 3 # Displays real time CPU usage for ALL cores every 1 second for 3 times (broken down by all cores). | ||
+ | $ sar -P 1 # Displays CPU usage for core number 1 for the current day. | ||
+ | $ sar -P 1 1 3 # Displays real time CPU usage for core number 1, every 1 second for 3 times. | ||
+ | $ sar -P ALL -f /var/log/sa/sa10 # Displays CPU usage broken down by all cores for the 10day day of the month from sa10 file. | ||
+ | |||
+ | ==See also== | ||
+ | * [http://www.gropp.org/?id=projects&sub=bwm-ng bwm-ng] (aka "Bandwidth Monitor NG") — a small and simple console-based live network and disk io bandwidth monitor for Linux | ||
+ | * [http://traceroute.sourceforge.net/ traceroute] | ||
+ | * [http://www.bitwizard.nl/mtr/ mtr] — combines the functionality of the 'traceroute' and 'ping' programs in a single network diagnostic tool. | ||
+ | * [http://humdi.net/vnstat/ vnStat] — a console-based network traffic monitor for Linux | ||
+ | * [http://iptraf.seul.org/about.html IPTraf] — a console-based network statistics utility for Linux | ||
+ | * [http://www.ntop.org/ ntop] &mdsah; a network traffic probe that shows the network usage | ||
+ | * [http://www.ex-parrot.com/~pdw/iftop/ iftop] — display bandwidth usage on an interface | ||
+ | * [http://sntop.sourceforge.net/ sntop] — simple network top | ||
==External links== | ==External links== | ||
* [http://pagesperso-orange.fr/sebastien.godard/ Official website] | * [http://pagesperso-orange.fr/sebastien.godard/ Official website] | ||
+ | * [http://www.rackspace.com/knowledge_center/article/monitoring-network-traffic Monitoring Network Traffic] — examples of how to install and use `iptraf` and `vnstat` on various Linux distros. | ||
[[Category:Linux Command Line Tools]] | [[Category:Linux Command Line Tools]] |
Latest revision as of 05:04, 28 July 2014
In computing, `sar`
(System Activity Report) is a Solaris-derived system monitor command used to report on various system loads, including CPU activity, memory/paging, device load, network, etc. Linux distributions provide `sar`
through the sysstat
package.
These utilities are especially useful in Cloud Computing.
Utilities
The sysstat package contains the following system performance tools:
sar
- collects and reports system activity information
iostat
- reports CPU utilization and disk I/O statistics
mpstat
- reports global and per-processor statistics
pidstat
- reports statistics for Linux tasks (processes)
sadf
- displays data collected by sar in various formats
nfsiostat
- reports I/O statistics for network filesystems
cifsiostat
- reports I/O statistics for CIFS filesystems
The statistics reported by `sar`
deal with I/O transfer rates, paging activity, process-related activities, interrupts, network activity, memory and swap space utilization, CPU utilization, kernel activities, and TTY statistics, among others. Both UP and SMP machines are fully supported.
Example usage
- CPU usage for all CPU cores on your machine
This gives the cumulative real-time CPU usage of all CPUs on your machine. "1 3
" reports for every 1 seconds a total of 3 times. The most useful column/field in this report is "%idle
" for the CPU load:
$ sar -u 1 3 Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) 17:12:06 CPU %user %nice %system %iowait %steal %idle 17:12:07 all 7.93 0.00 4.35 0.00 0.26 87.47 17:12:08 all 13.04 0.00 4.35 0.00 0.51 82.10 17:12:09 all 11.70 0.00 4.83 0.00 0.00 83.46 Average: all 10.89 0.00 4.51 0.00 0.26 84.34
- CPU usage for all CPU core on your machine with extended output:
$ sar -u ALL 1 3 Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) 17:16:04 CPU %usr %nice %sys %iowait %steal %irq %soft %guest %idle 17:16:05 all 7.87 0.00 3.30 0.00 0.25 0.00 0.00 0.00 88.58 17:16:06 all 7.75 0.00 3.88 0.00 0.26 0.00 0.00 0.00 88.11 17:16:07 all 8.46 0.00 4.87 0.00 0.26 0.00 0.00 0.00 86.41 Average: all 8.03 0.00 4.01 0.00 0.26 0.00 0.00 0.00 87.70
- CPU usage for second day of the month (Note: On some distros, the location of the
`sar`
logs is stored under/var/log/sa/
):
$ sar -u -f /var/log/sysstat/sa02
- CPU usage of an individual CPU or core
If you have 4 cores on your machine and would like to see what the individual cores are doing, execute the following command (note: the "-P ALL
" displays statistics for all the individual cores and, in the following example, the "CPU
" column has fields 0, 1, 2, and 3 and they indicate the corresponding CPU core numbers):
$ sar -P ALL 1 1 Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) 17:29:05 CPU %user %nice %system %iowait %steal %idle 17:29:06 all 7.65 0.00 4.59 0.00 0.26 87.50 17:29:06 0 10.42 0.00 3.12 0.00 1.04 85.42 17:29:06 1 13.13 0.00 11.11 0.00 0.00 75.76 17:29:06 2 4.12 0.00 3.09 0.00 0.00 92.78 17:29:06 3 2.00 0.00 2.00 0.00 0.00 96.00 Average: CPU %user %nice %system %iowait %steal %idle Average: all 7.65 0.00 4.59 0.00 0.26 87.50 Average: 0 10.42 0.00 3.12 0.00 1.04 85.42 Average: 1 13.13 0.00 11.11 0.00 0.00 75.76 Average: 2 4.12 0.00 3.09 0.00 0.00 92.78 Average: 3 2.00 0.00 2.00 0.00 0.00 96.00
Or, if you only want to display the statistics for a single core, try the following (e.g., for only the second core. Note that core numbers start from 0):
$ sar -P 1 1 1 Linux 3.8.0-30 (foobar) 11/09/13 _x86_64_ (4 CPU) 19:15:36 CPU %user %nice %system %iowait %steal %idle 19:15:37 1 0.00 0.00 3.06 0.00 1.02 95.92 Average: 1 0.00 0.00 3.06 0.00 1.02 95.92
Variations of the previous commands include:
$ sar -P ALL # Displays CPU usage broken down by all cores for the current day. $ sar -P ALL 1 3 # Displays real time CPU usage for ALL cores every 1 second for 3 times (broken down by all cores). $ sar -P 1 # Displays CPU usage for core number 1 for the current day. $ sar -P 1 1 3 # Displays real time CPU usage for core number 1, every 1 second for 3 times. $ sar -P ALL -f /var/log/sa/sa10 # Displays CPU usage broken down by all cores for the 10day day of the month from sa10 file.
See also
- bwm-ng (aka "Bandwidth Monitor NG") — a small and simple console-based live network and disk io bandwidth monitor for Linux
- traceroute
- mtr — combines the functionality of the 'traceroute' and 'ping' programs in a single network diagnostic tool.
- vnStat — a console-based network traffic monitor for Linux
- IPTraf — a console-based network statistics utility for Linux
- ntop &mdsah; a network traffic probe that shows the network usage
- iftop — display bandwidth usage on an interface
- sntop — simple network top
External links
- Official website
- Monitoring Network Traffic — examples of how to install and use `iptraf` and `vnstat` on various Linux distros.