Blog

How SAR command work in LINUX VPS

SAR stands for System Activity Report, as its name suggests command is used to collect, report & save CPU, Memory, I/O usage in Unix like operating system. SAR command produces the reports on the fly and can also save the reports in the log files as well.

This article explains how to install and configure the sysstat package (which contains sar utility) and explains how to monitor the following Linux Vps performance statistics using sar.

1 ) Collective CPU usage

2 ) Individual CPU statistics

3) Run queue and load average data

4 ) Swap space used and available

5 ) Report sar data from a specific time

6 ) Individual device I/O activities

7 ) Memory used and available

8 ) Context switch statistics

9 ) Network statistics

10 ) Overall I/O activities of the system

I ) How to install SAR ION LINUX

Install Sysstat Package

First, make sure the latest version of sar is available on your system. Install it using any one of the following methods depending on your distribution.

  • # sudo apt-get install sysstat
  • # yum install sysstat

 

 

Note: Make sure to pass the option –enable-install-cron. This does the following automatically for you. If you don’t configure sysstat with this option, you have to do this ugly job yourself manually.

Creates /etc/rc.d/init.d/sysstat

 create a sysstat

Once installed, verify the sar version using “sar -V”

Finally, make sure sar works. For example, the following gives the system CPU statistics 3 times (with 1 second interval).

sysst

 s1 and s2

Collect the sar statistics using cron job – sa1 and sa2

 

/usr/local/lib/sa/sa1

This runs every 10 minutes and collects sar data for historical reference.

If you want to collect sar statistics every 5 minutes, change */10 to */5 in the above /etc/cron.d/sysstat file.

This writes the data to /var/log/sa/saXX file. XX is the day of the month. saXX file is a binary file. You cannot view its content by opening it in a text editor.

/usr/local/lib/sa/sa2

/usr/local/lib/sa/sa2

This runs close to midnight (at 23:53) to create the daily summary report of the sar data.

/usr/local/lib/sa/sa2

sa2 creates /var/log/sa/sarXX file (Note that this is different than saXX file that is created by sa1). This sarXX file created by sa2 is an ascii file that you can view it in a text editor.

 

 

Linux 2.6.32-431.e16 – Linux kernel version of the system.

01/18/2017 – The date when the sar data was collected.

_x86_64_ – The system architecture

(2 CPU) – Number of CPUs available on this system. On multi core systems, this indicates the total number of cores.

  1. CPU Usage of ALL CPUs (sar -u)

CPU Usage of ALL CPUs (sar -u)

This gives the cumulative real-time CPU usage of all CPUs. “1 5” reports for every 1 seconds a total of 5 times. Most likely you’ll focus on the last field “%idle” to see the cpu load.

  • sar -u Displays CPU usage for the current day that was collected until that point.
  • sar -u 1 5 Displays real time CPU usage every 1 second for 5 times.
  • sar -u ALL Same as “sar -u” but displays additional fields.
  • sar -u ALL 1 5 Same as “sar -u 1 5” but displays additional fields.
  • sar -u -f /var/log/sa/sa10 Displays CPU usage for the 10day of the month from the sa10 file.
  1. CPU Usage of Individual CPU or Core (sar -P)

CPU Usage of Individual CPU or Core

 

If you have 4 Cores on the machine and would like to see what the individual cores are doing, do the following.

  • -P ALL” indicates that it should displays statistics for ALL the individual Cores.
  • In the following example under “CPU” column 0, 1, 2, and 3 indicates the corresponding CPU core numbers.
  1. Memory Free and Used (sar -r)

 3. Memory Free and Used (sar -r)

 

This reports the memory statistics. “1 5” reports for every 1 seconds a total of 5 times. Most likely you’ll focus on “kbmemfree” and “kbmemused” for free and used memory.

Following are few variations:

  • # sar -r
  • # sar -r 1 5
  • # sar -r -f /var/log/sa/sa10
  1. Swap Space Used (sar -S)

 

 

This reports the swap statistics. “1 5” reports for every 1 seconds a total of 5 times. If the “kbswpused” and “%swpused” are at 0, then your system is not swapping.

Following are few variations:

  • #sar -S
  • # sar -S 1 5
  • # sar -S -f /var/log/sa/sa10
  1. Overall I/O Activities (sar -b)

I/O Activities

 

This reports I/O statistics. “1 5” reports for every 1 seconds a total of 5 times.

Following fields are displays in the example below.

tps – Transactions per second (this includes both read and write)

rtps – Read transactions per second

wtps – Write transactions per second

bread/s – Bytes read per second

bwrtn/s – Bytes written per second

Following are a few variations:

  • # sar -b
  • # sar -b 1 5
  • # sar -b -f /var/log/sa/sa10
  1. Individual Block Device I/O Activities (sar -d)

To identify the activities by the individual block devices (i.e a specific mount point, or LUN, or partition), use “sar -d”

s1

 

Following are a few variations:

  • # sar -d
  • # sar -d 1 1
  • # sar -d -f /var/log/sa/sa10
  • # sar -p -d
  1. Report network statistics (sar -n)

This reports various network statistics. For example number of packets received (transmitted) through the network card, statistics of packet failure, etc.,. “1 5” reports for every 1 second a total of 5 times.

  • # sar -n KEYWORD

KEYWORD can be one of the following:

  • # sar -n DEV 1 1
  • DEV – Displays network devices vital statistics for eth0, eth1, etc.,
  • EDEV – Display network device failure statistics
  • NFS – Displays NFS client activities
  • NFSD – Displays NFS server activities
  • SOCK – Displays sockets in use for IPv4
  • IP – Displays IPv4 network traffic
  • EIP – Displays IPv4 network errors
  • ICMP – Displays ICMPv4 network traffic
  • ICMP – Displays ICMPv4 network errors
  • Display context switch per second (sar -w)

This reports the total number of processes created per second, and the total number of context switches per second. “1 5” reports for every 1 second a total of 5 times.

  • # sar -w 1 5
  1. Reports run queue and load average (sar -q)

This reports the run queue size and loads an average of last 1 minute, 5 minutes, and 15 minutes. “1 5” reports for every 1 second a total of 5 times.

  • # sar -q 1 5

By using SAR command we can find out the performance status of the server.

 

Tags: Cheap Linux VPS, Linux VPS hosting India

How to Change Process Priority using Linux Nice and Renice

In a Linux system, there are hundreds of processes, that are continuously running different tasks. Linux Kernel does a fantastic job of mediating between these processes and allotting CPU to these processes.

Every running process in Linux has a priority assigned to it. We can change the process priority using nice and renice utility.

With the help of the Nice command in Linux, you can set process priority. If you give a process a higher priority, then Kernel will allocate more CPU time to that process.

Linux Nice & Renice

The Nice command will launch a process with a user-defined scheduling priority. Renice command will modify the scheduling priority of a running process. Linux Kernel schedules the process and allocates CPU time accordingly for each of them.

The process scheduling priority range is from -20 to 19. We call this a nice value.

Nice value of -20 represents the highest priority, and a nice value of 19 represents the least priority for a process.

Follow the below process to increase the priority of any process:

1. Login into your Linux system via user name and password, enter # top command.

Cheap Linux VPS

After hitting enter you will get output like above screen, in that NI means Nice Value of particular process.

2. We can set NI value of any process or command in 2 ways.


a)
In the output of # top command, just enter ” r ”, we get the screen like below:

By default when a program is launched in Linux, it gets launched with the priority of ‘0’. However, you can change the priority of your service yourself.

Cheap Linux VPS

Simply just put the PID of any process or the PID of that process in which you want to increase the priority. Hit enter after putting PID.

Cheap Linux VPS

It will ask for Renice value, see the above screen. put the value priority range is from -20 to 19. We call this a nice value. Nice value of -20 represents the highest priority, and a nice value of 19 represents the least priority for a process.

After putting the renice value, the process priority will change according to NI value.

Check the NI column after purring renice value of any process, see below screen.

Cheap Linux VPS

In the above screen, PID of kthreadd is 2 and its nice value has been changed to -10, which means now it has higher priority among then all process, which is running under a Linux system.

We can also set the NI nice value of any process like httpd, java, mysql , ftp , sshd to make that service perform fast.

b) We can set NI via another way, by using simple below command

After top command, do the below step to increase the performance of any service, or process

# nice -10 httpd

Above command will set NI value of httpd service to 10, means it has lower priority among all the running process under Linux system.

# nice –10 httpd

The above command will set NI value of httpd service to -10, which means it has the highest priority, we can increase this value to -20, A nice value of -20 represents the highest priority.

For more information visit Ideastack.

Unblocked Particular ip from WHM/Cpanel

Log in to the main WHM Panel

1. Search for Plugin section

2. Go to ConfigServer Security and Firewall

WHM/CPANEl

3. Search for the IP which you want to get unblocked from WHM Panel

Cpanel vps

4. If given IP will be blocked then you’ll find that IP here after clicking on Search for IP button.

To unblock that IP you’ll get the Unblock button below, just simply click on that button and that IP will be unblocked.

Whm vps

Now user can open the panel from that IP

The reason why IP got blocked: User might attempt a multiple failed login attempt.

To know more visit Ideastack.

Last Edited: 06/05/2020

Open chat