Linux System Activity Reporter (SAR) Command Tutorial With Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-system-activity-reporter-sar-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Monitoring Linux servers is important part of the system administration. There are a lot of way and tools to monitor Linux servers. System Activity Reporter or simply sar is one of the most popular and useful tool. Sar can save system stats from various subsystems like disk, CPU, memory, network etc. to file and used to review historical performance metrics. There is also different tools to provide graphical presentation from Sar stats. Sar saves systems stats in specified intervals. We will look them in details in this tutorial.

Install

Sar is provided by sysstat tool and can be installed from official repositories various distributions.

Install Sar

Install Sar

Syntax

Syntax

Syntax

Help

Simple and fast way to get help with sar command is providing -h option like below.

Help

Help

Show CPU Stats

One of the most wanted server metric to track in monitoring purposes is CPU usage. We will provide -u options for CPU stats. Also numbers 1 specifies time interval and 3 count which is how many time stats will be printed.

Show CPU Stats

Show CPU Stats

In the example CPU column provides information that all CPU’s metrics are provided. There is also time information for the performance metrics.

  • %user column is used to show user side load
  • %system columns is used to show system related load
  • %idle column shows how many CPU resource is do not used. In this case load is very low and idle value is range of %97

Show Specific All CPU Stats

In the previous example we have looked some stats of the CPU those are popular and most useful. But in some situations this can not be enough and we may need more stat about CPU like iowait . This stats can be printed with ALL option after -u like below.

LEARN MORE  How To Set Java Home Path?

In this example we can see the extra columns like %iowaint %irq , %gnice .

Show Specific CPU Stats

As we know modern CPU’s provides more than one core for more performance. While providing CPU stats by default all cores metrics are provided. But there is -P option which will filter and provide only specified core metrics like below. In this example we want to get second core information. Keep in mind that core index starts from 0 which means first core is numbered as 0 .

Show Specific CPU Stats

Show Specific CPU Stats

We can see from screenshot that first core is specified with -P 1 and other parameters like interval and count are provided too. If we look the CPU column we can see that the core index number 1 is printed as we expected.

Show Memory Stats

Another important performance metric for Linux servers is memory. Memory performance can be monitored with the -r parameter.

Show Memory Stats

Show Memory Stats

We can see a lot of information about the memory is provided.

  • kbmemfree column shows free memory as kilobyte
  • kbmemused column shows used memory as kilobyte
  • %memused columns shows percentage of used memory

Show Swap Stats

Swap is a memory increment mechanisms used years ago. Currently system administrator do not prefer this method because of the memory prices a low and the swap performance is not good. Swap stats can be get with -S option.

Show Swap Stats

Show Swap Stats

As we can see from output there is no swap usage in this Linux server.

  • kbswpfree columns shows free swap size in kilobyte
  • kbswpused columns shows used swap size in kilobyte
  • %swpused column shows used swap size as percentage
LEARN MORE  Linux Qemu-img Command Tutorial With Examples to Create, Change, Shrink Disk Images

Show I/O Stats

IO is another monitored metric for Linux systems.  IO parameter -b provides information about transactions per second, read and write transactions etc.

Show I/O Stats

Show I/O Stats

  • tps column shows transactions per second count
  • rtpd column show read transactions per second count
  • wtps column shows write transactions per second count
  • bread/s column shows byte read second count
  • wread/s column shows byte write second count

Show Specific Disk I/O Stats

Block devices or disk IO stats can be gathered with sar command too. To get this information required option is -d .

$ sar -d 1 3

  • DEV column show the devices minor and major numbers like dev252-0
  • tps column shows transactions per second count
  • rd_sec/s column shows  read operation done in a second
  • we_sec/s column shows  write operation done in a second
  • %util column show total utilization percentage

Show Disk Names

In previous example we have listed the stats with related disk device major and minor numbers by default. This is not readable from human point of view if we have a lot of disks on the Linux system. -p option can be used to list disk devices with their native names like sda , vda etc.

Show Disk Names

Show Disk Names

Show Context Switch Stats

As we know processes do not all ways run in their life time. Some times they sleep or wait some io. This status change is named as context switching . Information about context switching can be get with -w option.

Show Network Statistics

Network statistics can be printed with option -n . Also after the option a keyword must be provided. In this example we will print the device related metrics.

LEARN MORE  Creating File Systems In Linux With mkfs

  • IFACE columns shows related interface name
  • rxpck/s columns shows received packets count
  • txpck/s column shows transmitted packets count
  • rxkB/s column shows received packets sizes
  • txkB/s column shows transmitted packets sizes
  • %ifutil column show interface usage or load percentage

We have provided -n DEV to get device related stats. But there is other subsystems other than DEV to get information. Here are some of them

  • IP displays IP statistics
  • TCP displays TCP statistics
  • UDP displays UDP statistics
  • ALL displays all statics from above and those we have not mentioned

Show Paging Stats

As we know Linux memory management have some mechanisms to effectively and reliable way manage the memory. Paging is used to manage the memory system.

Show Paging Stats

Show Paging Stats

Write Sar Stats To A File

Up to now we have printed collected statistics and stats into the terminal. But in some situations we may need to save data and shot in a more shiny way or store historical data for inspection. -o option with a file name can be used to save collected information into a file.

Write Sar Stats To A File

Write Sar Stats To A File

Show Historic Sar Stats From File

In the previous example we have save sar data into a file. One of the sar usage scenario is saving this data and playing graphics according to this data. Sar can also read all ready saved data and show accordingly. -f with a data file name can be used for this purpose.

Show Historic Sar Stats

Show Historic Sar Stats

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-system-activity-reporter-sar-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)