This article describes how to install in addition to purpose sar (sysstat) a organization performance tools for Linux. It comes alongside plenty of sar examples in addition to usage. Sar is business office of the sysstat package. According to the packet description it includes the next organization performance tools:
- sar: collects in addition to reports organization activity information;
- iostat: reports CPU utilization in addition to disk I/O statistics;
- mpstat: reports global in addition to per-processor statistics;
- pidstat: reports statistics for Linux tasks (processes);
- sadf: displays information collected yesteryear sar inward diverse formats.
Using sar you lot tin monitor performance of diverse Linux subsystems (CPU, Memory, I/O..) inward existent time. You tin also collect all performance information on an on-going basis, shop them, in addition to create historical analysis to position bottlenecks. I create non accept credits for this post, I get got only collected pieces of information from dissimilar websites that I constitute useful in addition to set them together. I give thank you lot Ramesh Natarajan from TheGeekStuff.com for publishing his master copy post service dorsum inward 2011. I couldn’t get got done whatsoever better. Credits added equally due.
What SAR tin do?
In this article I volition demonstrate how to install in addition to configure sysstat packet (which contains sar utility) in addition to explains how to monitor the next Linux performance statistics using sar.
- Collective CPU usage
- Individual CPU statistics
- Memory used in addition to available
- Swap infinite used in addition to available
- Overall I/O activities of the system
- Individual device I/O activities
- Context switch statistics
- Run queue in addition to charge average data
- Network statistics
- Report sar information from a specific time
The statistics reported yesteryear sar bargain alongside I/O transfer rates, paging activity, process-related activities, interrupts, network activity, retentivity in addition to swap infinite utilization, CPU utilization, heart activities in addition to TTY statistics, amid others. Both UP in addition to SMP machines are fully supported.
sysstat – SAR examples in addition to usage
This outset business office describes SAR examples in addition to usage along alongside installation.
Step 1. Install sysstat Package
sysstat is ordinarily non installed inward Linux organization yesteryear default. You demand to install it. You also demand to brand for sure you lot get got the right repositories added. As I personally purpose Kali Linux, I’ve added Kali Linux official repositories. Follow your distro documentation to add together yours. But it is pretty direct forward.
To install sysstat package:
sudo apt-get install sysstat
(or)
yum install sysstat
(or)
rpm -ivh sysstat-10.0.0-1.i586.rpm
Step 2. Enable stat collection
In novel systems 1 time you’ve installed sysstat, it enables statistics collections yesteryear default. In instance it is non you lot tin enable it yesteryear editing 1 give-and-take inward the next file:
vi /etc/default/sysstat
Change ENABLED=”false”
to ENABLED=”true”
#
# Default settings for /etc/init.d/sysstat, /etc/cron.d/sysstat
# in addition to /etc/cron.daily/sysstat files
#
# Should sadc collect organization activity informations? Valid values
# are "true" in addition to "false". Please create non set other values, they
# volition live on overwritten yesteryear debconf!
ENABLED="true"
Save the file. Restart sysstat.
service sysstat restart
(or)
/etc/init.d/sysstat restart
Once it’s restarted, it volition start collecting data.
Step 3. Changing collection intervals
Default sysstat configuration collects information every 10 minutes. You tin modify it easily. If you lot got a fast organization or you lot demand to a greater extent than intensive monitoring of your organization (i.e. a spider web server alongside plenty RAM in addition to Processor), hence you lot mightiness desire to trim down the collection interval from 10 minutes to 2 minutes. Alternatively, you lot tin modify it to xv minutes if you lot got a deadening system. Either way, it’s tardily to create in addition to hither are the steps:
vi /etc/cron.d/sysstat
# The outset chemical component of the path is a directory where the debian-sa1
# script is located
PATH=/usr/lib/sysstat:/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin
# Activity reports every 10 minutes everyday
5-55/10 * * * * root ascendence -v debian-sa1 > /dev/null && debian-sa1 1 1
# Additional run at 23:59 to rotate the statistics file
59 23 * * * root ascendence -v debian-sa1 > /dev/null && debian-sa1 threescore 2
Change
5-55/10 * * * * root ascendence -v debian-sa1 > /dev/null && debian-sa1 1 1
To
*/2 * * * * root ascendence -v debian-sa1 > /dev/null && debian-sa1 1 1
Save the file in addition to restart sysstat.
service sysstat restart
(or)
/etc/init.d/sysstat restart
Step 4. Check sysstat version
Once installed, verify the sar version using the next command:
root@kali: # sar -V
sysstat version 10.0.5
(C) Sebastien Godard (sysstat <at> orange.fr)
Step 5: Practical sar examples in addition to usage
There are 2 ways to purpose sar.
- sar followed yesteryear an choice (without specifying a saXX information file). This volition await for the electrical flow day’s saXX information file in addition to written report the performance information that was recorded until that dot for the electrical flow day.
- sar followed yesteryear an option, in addition to additionally specifying a saXX information file using -f option. This volition written report the performance information for that item day. i.e XX is the solar daytime of the month.
In all the examples below, nosotros are going to explicate how to sentiment for sure performance information for the electrical flow day. To await for a specific day, add together “-f /var/log/sysstat/saXX” at the halt of the sar command.
All the sar ascendence volition get got the next equally the 1st describe of piece of employment inward its output.
root@kali: # sar -u
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
21:42:01 all 8.20 0.00 1.21 0.31 0.00 90.28
Average: all 7.76 0.02 1.97 0.43 0.00 89.82
21:42:26 LINUX RESTART
21:44:01 CPU %user %nice %system %iowait %steal %idle
Average: all 6.70 0.00 0.63 0.28 0.00 92.38
root@kali: #
- Linux 3.14-kali1-amd64 – Linux heart version of the system.
- (kali) – The hostname where the sar information was collected.
- 17/06/14 – The appointment when the sar information was collected.
- _x86_64_ – The organization architecture
- (4 CPU) – Number of CPUs available on this system. On multi core systems, this indicates the total issue of cores.
As a final infinitesimal check, let’s banking concern check roughly historical Sysstat files.
root@kali: # ls /var/log/sysstat/
sa03 sa04 sa05 sa17 sa28
root@kali: # sar -u -f /var/log/sysstat/sa03
Linux 3.14-kali1-amd64 (kali) 03/06/14 _x86_64_ (4 CPU)
18:13:32 LINUX RESTART
18:14:01 CPU %user %nice %system %iowait %steal %idle
18:16:01 all 4.20 0.00 0.82 0.53 0.00 94.45
Average: all 1.43 0.00 0.36 0.30 0.00 97.90
root@kali: #
In this way, you lot tin teach dorsum since the appointment you’ve enabled sysstat / sar to banking concern check historical data.
1. CPU Usage of ALL CPUs (sar -u)
This gives the cumulative real-time CPU usage of all CPUs. “1 3″ reports for every 1 seconds a total of 3 times. Most probable you’ll focus on the final land “%idle” to come across the cpu load.
root@kali: # sar -u 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
21:57:24 CPU %user %nice %system %iowait %steal %idle
21:57:25 all 1.01 0.00 0.51 0.51 0.00 97.98
21:57:26 all 1.03 0.00 0.51 0.00 0.00 98.46
21:57:27 all 1.26 0.00 0.25 0.50 0.00 97.98
Average: all 1.10 0.00 0.42 0.34 0.00 98.14
root@kali: #
Following are few sar examples:
- sar -u Displays CPU usage for the electrical flow solar daytime that was collected until that point.
- sar -u 1 3 Displays existent fourth dimension CPU usage every 1 2d for 3 times.
- sar -u ALL Same equally “sar -u” but displays additional fields.
- sar -u ALL 1 3 Same equally “sar -u 1 3″ but displays additional fields.
- sar -u -f /var/log/sysstat/sa10 Displays CPU usage for the 10day of the calendar month from the sa10 file.
2. CPU Usage of Individual CPU or Core (sar -P)
If you lot get got four Cores on the machine in addition to would similar to come across what the private cores are doing, create the following.
“-P ALL” indicates that it should displays statistics for ALL the private Cores.
In the next sar examples nether “CPU” column 0, 1, 2, in addition to 3 indicates the corresponding CPU core numbers.
root@kali: # sar -P ALL 1 1
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:05:24 CPU %user %nice %system %iowait %steal %idle
22:05:25 all 1.25 0.00 0.50 0.25 0.00 97.99
22:05:25 0 0.00 0.00 0.00 1.00 0.00 99.00
22:05:25 1 3.00 0.00 1.00 0.00 0.00 96.00
22:05:25 2 1.02 0.00 0.00 0.00 0.00 98.98
22:05:25 3 0.00 0.00 0.99 0.00 0.00 99.01
“-P 1″ indicates that it should displays statistics solely for the 2nd Core. (Note that Core issue starts from 0).
root@kali: # sar -P 2 1 1
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:07:40 CPU %user %nice %system %iowait %steal %idle
22:07:41 2 1.00 0.00 0.00 0.00 0.00 99.00
Average: 2 1.00 0.00 0.00 0.00 0.00 99.00
root@kali: #
Following are few sar examples:
- sar -P ALL Displays CPU usage broken downward yesteryear all cores for the electrical flow day.
- sar -P ALL 1 3 Displays existent fourth dimension CPU usage for ALL cores every 1 2d for 3 times (broken downward yesteryear all cores).
- sar -P 1 Displays CPU usage for core issue 1 for the electrical flow day.
- sar -P 1 1 3 Displays existent fourth dimension CPU usage for core issue 1, every 1 2d for 3 times.
- sar -P ALL -f /var/log/sysstat/sa10 Displays CPU usage broken downward yesteryear all cores for the 10day solar daytime of the calendar month from sa10 file.
3. Memory Free in addition to Used (sar -r)
This reports the retentivity statistics. “1 3″ reports for every 1 seconds a total of 3 times. Most probable you’ll focus on “kbmemfree” in addition to “kbmemused” for gratis in addition to used memory.
root@kali: # sar -r 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:08:54 kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact
22:08:55 4644240 3550716 43.33 153180 2204384 2612376 27.44 1756372 1438360
22:08:56 4644240 3550716 43.33 153180 2204384 2612376 27.44 1756468 1438360
22:08:57 4643744 3551212 43.33 153188 2204384 2612376 27.44 1757084 1438360
Average: 4644075 3550881 43.33 153183 2204384 2612376 27.44 1756641 1438360
root@kali: #
Following are few sar examples:
- sar -r
- sar -r 1 3
- sar -r -f /var/log/sysstat/sa10
4. Swap Space Used (sar -S)
This reports the swap statistics. “1 3″ reports for every 1 seconds a total of 3 times. If the “kbswpused” in addition to “%swpused” are at 0, hence your organization is non swapping.
root@kali: # sar -S 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:10:03 kbswpfree kbswpused %swpused kbswpcad %swpcad
22:10:04 1325052 0 0.00 0 0.00
22:10:05 1325052 0 0.00 0 0.00
22:10:06 1325052 0 0.00 0 0.00
Average: 1325052 0 0.00 0 0.00
root@kali: #
Following are few sar examples:
- sar -S
- sar -S 1 3
- sar -S -f /var/log/sysstat/sa10
Notes:
- Use “sar -R” to position issue of retentivity pages freed, used, in addition to cached per 2d yesteryear the system.
- Use “sar -H” to position the hugepages (in KB) that are used in addition to available.
- Use “sar -B” to generate paging statistics. i.e Number of KB paged inward (and out) from disk per second.
- Use “sar -W” to generate page swap statistics. i.e Page swap inward (and out) per second.
5. Overall I/O Activities (sar -b)
This reports I/O statistics. “1 3″ reports for every 1 seconds a total of 3 times.
Following fields are displays inward the instance below.
- tps – Transactions per 2d (this includes both read in addition to write)
- rtps – Read transactions per second
- wtps – Write transactions per second
- bread/s – Bytes read per second
- bwrtn/s – Bytes written per second
root@kali: # sar -b 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:11:28 tps rtps wtps bread/s bwrtn/s
22:11:29 0.00 0.00 0.00 0.00 0.00
22:11:30 0.00 0.00 0.00 0.00 0.00
22:11:31 0.00 0.00 0.00 0.00 0.00
Average: 0.00 0.00 0.00 0.00 0.00
root@kali: #
Following are few sar examples:
- sar -b
- sar -b 1 3
- sar -b -f /var/log/sysstat/sa10
Note: Use “sar -v” to display issue of inode handlers, file handlers, in addition to pseudo-terminals used yesteryear the system.
6. Individual Block Device I/O Activities (sar -d)
To position the activities yesteryear the private block devices (i.e a specific mountain point, or LUN, or partition), purpose “sar -d”
root@kali: # sar -d 1 1
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:12:08 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
22:12:09 dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
22:12:09 dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
Average: dev8-0 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: dev8-16 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
root@kali: #
In the higher upwardly instance “DEV” indicates the specific block device.
For example: “dev53-1″ agency a block device alongside 53 equally major number, in addition to 1 equally minor fry number.
The device mention (DEV column) tin display the actual device mention (for example: sda, sda1, sdb1 etc.,), if you lot purpose the -p choice (pretty print) equally shown below.
root@kali: # sar -p -d 1 1
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:13:33 DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
22:13:34 sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
22:13:34 sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: DEV tps rd_sec/s wr_sec/s avgrq-sz avgqu-sz await svctm %util
Average: sda 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: sdb 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
root@kali: #
Following are few sar examples:
- sar -d
- sar -d 1 3
- sar -d -f /var/log/sysstat/sa10
- sar -p -d
7. Display context switch per 2d (sar -w)
This reports the total issue of processes created per second, in addition to total issue of context switches per second. “1 3″ reports for every 1 seconds a total of 3 times.
root@kali: # sar -w 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:14:45 proc/s cswch/s
22:14:46 14.00 2817.00
22:14:47 14.00 3355.00
22:14:48 14.00 2450.00
Average: 14.00 2874.00
root@kali: #
Following are few sar examples:
- sar -w
- sar -w 1 3
- sar -w -f /var/log/sysstat/sa10
8. Reports run queue in addition to charge average (sar -q)
This reports the run queue size in addition to charge average of final 1 minute, five minutes, in addition to xv minutes. “1 3″ reports for every 1 seconds a total of 3 times.
root@kali: # sar -q 1 3
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:15:18 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
22:15:19 0 392 0.31 0.26 0.29 0
22:15:20 1 392 0.31 0.26 0.29 0
22:15:21 0 392 0.31 0.26 0.29 0
Average: 0 392 0.31 0.26 0.29 0
root@kali: #
Note: The “blocked” column displays the issue of tasks that are currently blocked in addition to waiting for I/O functioning to complete.
Following are few sar examples:
- sar -q
- sar -q 1 3
- sar -q -f /var/log/sysstat/sa10
9. Report network statistics (sar -n)
This reports diverse network statistics. For example: issue of packets received (transmitted) through the network card, statistics of packet failure etc.,. “1 3″ reports for every 1 seconds a total of 3 times.
sar -n KEYWORD
KEYWORD tin live on 1 of the following:
- DEV – Displays network devices vital statistics for eth0, eth1, etc.,
- EDEV – Display network device failure statistics
- NFS – Displays NFS customer activities
- NFSD – Displays NFS server activities
- SOCK – Displays sockets inward purpose for IPv4
- IP – Displays IPv4 network traffic
- EIP – Displays IPv4 network errors
- ICMP – Displays ICMPv4 network traffic
- EICMP – Displays ICMPv4 network errors
- TCP – Displays TCPv4 network traffic
- ETCP – Displays TCPv4 network errors
- UDP – Displays UDPv4 network traffic
- SOCK6, IP6, EIP6, ICMP6, UDP6 are for IPv6
- ALL – This displays all of the higher upwardly information. The output volition live on real long.
root@kali: # sar -n DEV 1 1
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
22:16:15 IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
22:16:16 eth0 4.00 4.00 0.92 0.26 0.00 0.00 0.00
22:16:16 lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
Average: eth0 4.00 4.00 0.92 0.26 0.00 0.00 0.00
Average: lo 0.00 0.00 0.00 0.00 0.00 0.00 0.00
root@kali: #
10. Report Sar Data Using Start Time (sar -s)
When you lot sentiment historic sar information from the /var/log/sysstat/saXX file using “sar -f” option, it displays all the sar information for that specific solar daytime starting from 12:00 a.m for that day.
Using “-s hh:mi:ss” option, you lot tin specify the start time. For example, if you lot specify “sar -s 10:00:00″, it volition display the sar information starting from 10 a.m (instead of starting from midnight) equally shown below.
You tin combine -s choice alongside other sar option.
For example, to written report the charge average on 26th of this calendar month starting from xi p.m inward the morning, combine the -q in addition to -s choice equally shown below.
root@kali: # sar -q -f /var/log/sysstat/sa17 -s 23:00:01 | head
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
23:00:01 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
23:02:01 2 381 0.19 0.36 0.37 0
23:04:01 0 381 0.19 0.28 0.33 0
23:06:01 0 382 0.07 0.20 0.30 0
23:08:01 1 382 0.17 0.18 0.28 0
23:10:01 1 373 0.06 0.14 0.25 0
23:12:01 0 372 0.10 0.13 0.23 0
23:14:01 0 372 0.36 0.19 0.24 0
root@kali: #
There is no choice to boundary the end-time. You only get got to teach creative in addition to purpose caput ascendence equally shown below.
For example, starting from 2300hrs (11PM) if you lot desire to come across vii entries, you lot get got to pipage the higher upwardly output to “head”
root@kali: # sar -q -f /var/log/sysstat/sa17 -s 23:00:01 | head
Linux 3.14-kali1-amd64 (kali) 17/06/14 _x86_64_ (4 CPU)
23:00:01 runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
23:02:01 2 381 0.19 0.36 0.37 0
23:04:01 0 381 0.19 0.28 0.33 0
23:06:01 0 382 0.07 0.20 0.30 0
23:08:01 1 382 0.17 0.18 0.28 0
23:10:01 1 373 0.06 0.14 0.25 0
23:12:01 0 372 0.10 0.13 0.23 0
23:14:01 0 372 0.36 0.19 0.24 0
root@kali: #
Step 6. If you lot desire to relieve the statistics for farther analysis to a file use:
root@kali: # sar -A > $(date +`hostname`-%d-%m-%y-%H%M.log)
Conclusion
sysstat or sar is real powerful in addition to useful tool to have. It allows you lot to monitor your Linux or Solaris systems activity closely in addition to using sar you lot should live on able to position bottlenecks. Now this is non the halt of sar usage in addition to examples. You tin purpose kSar which is the graphical halt of sar to sentiment graphs inward a proper Graphical interface. kSar allows you lot to dig downward into historical information or fifty-fifty teach information from a dissimilar workstation to sentiment inward a remote machine.
Thanks for reading in addition to don’t forget to share. Stay tuned for kSar guide.
References
- sysstat (sar): http://sebastien.godard.pagesperso-orange.fr/]
- ksar: http://sourceforge.net/projects/ksar/
- TheGeekstuff: TheGeekStuff
- Debian: http://www.debian.org/
- Ubuntu: http://www.ubuntu.com/
- CentOS: http://www.centos.org/
- Gentoo: http://www.gentoo.org/