Posted in Linux, Oracle

Linux mpstat Command

What is mpstat?

mpstat is used to monitor cpu utilization on your system. It will be more useful if your system has multiple processors. The first processors will signed as CPU 0. The second one will be signed CPU 1 and so on.

The mpstat command writes to standard output activities for each available processor, processor 0 being the first one. Global average activities among all processors are also reported. The mpstat command can be used both on SMP and UP machines, but in the latter, only global average activities will be printed. If no activity has been selected, then the default report is the CPU utilization report:

 mpstat -P ALL 5 1

It shows the various stats for the CPUs in the system. The –P ALL options directs the command to display stats for all the CPUs, not just a specific one. The parameters 5 2 directs the command to run every 5 seconds and for 2 times. The above output shows the metrics for all the CPUs first (aggregated) and for each CPU individually. Finally, the average for all the CPUs has been shown at the end.

Let’s see what the column values mean:

%user   -Indicates the percentage of the processing for that CPU consumes by user processes. User processes are non-kernel processes used for applications such as an Oracle database. In this example output, the user CPU %age is very little.
%nice   -Indicates the percentage of CPU when a process was downgraded by nice command. The command nice has been described in an earlier installment. It brief, the command nice changes the priority of a process.
%system -Indicates the CPU percentage consumed by kernel processes
%iowait -Shows the percentage of CPU time consumed by waiting for an I/O to occur
%irq    -Indicates the %age of CPU used to handle system interrupts
%soft   -Indicates %age consumed for software interrupts
%idle   -Shows the idle time of the CPU
%intr/s -Shows the total number of interrupts received by the CPU per second

It’s possible that a poorly written application not using multi-threadd architecture runs on a multi-processor machine but does not use all the processors. As a result, one CPU overloads while others remain free. You can easily diagnose these sorts of issues via mpstat.

And now and example:

oracle@primary:PRI::$ mpstat -P ALL 5 1
Linux 3.10.0-862.11.6.el7.x86_64 (primary.localdomain) 10/15/2018 _x86_64_(2 CPU)

07:35:11 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
07:35:16 AM all 0.51 0.00 0.51 0.61 0.00 0.00 0.00 0.00 0.00 98.36
07:35:16 AM 0 0.82 0.00 0.62 0.21 0.00 0.00 0.00 0.00 0.00 98.36
07:35:16 AM 1 0.20 0.00 0.40 1.21 0.00 0.20 0.00 0.00 0.00 97.98

Average: CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
Average: all 0.51 0.00 0.51 0.61 0.00 0.00 0.00 0.00 0.00 98.36
Average: 0 0.82 0.00 0.62 0.21 0.00 0.00 0.00 0.00 0.00 98.36
Average: 1 0.20 0.00 0.40 1.21 0.00 0.20 0.00 0.00 0.00 97.98

Print CPU utilization using intervals

You may want to see the CPU utilization movement. To do this, you can use intervals. Here’s an example.
The below command is to show you 3 reports about CPU utilization with 3 seconds interval:

oracle@primary:PRI::$ mpstat 1 2
Linux 3.10.0-862.11.6.el7.x86_64 (primary.localdomain) 10/15/2018 _x86_64_(2 CPU)

07:40:37 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
07:40:38 AM all 1.03 0.00 0.00 0.51 0.00 0.00 0.00 0.00 0.00 98.46
07:40:39 AM all 0.51 0.00 0.51 1.03 0.00 0.00 0.00 0.00 0.00 97.95
Average: all 0.77 0.00 0.26 0.77 0.00 0.00 0.00 0.00 0.00 98.21
Posted in Linux

Some Linux commands I use often

Get the total size of some files:

du -ch /path/patern* | grep total

Get the total number of files being backed up using the log of the RMAN job:

grep -i 'input datafile file number=' rman_BKUP.log | wc -l

Use grep to display the next 2 lines after the pattern you’re looking for (-A= AFTER , B=BEFORE):

grep -i -A 2 'input datafile file number'  rman_BKUP.log
input datafile file number=00001 name=/storage/datafile.dbf
channel ch02: starting piece 1 at 14-MAR-18 15:30:25
channel ch01: finished piece 1 at 14-MAR-18 15:30:32
Posted in Linux, Oracle, Virtualbox

X11 forwarding request failed on channel 0

I got this error while trying to redirect my display to the local host.

marius$ ssh -X oracle@rac1
Warning: the ECDSA host key for 'rac1' differs from the key for the IP address ''
Offending key for IP in /Users/marius/.ssh/known_hosts:10
Matching host key in /Users/marius/.ssh/known_hosts:13
Are you sure you want to continue connecting (yes/no)? yes
oracle@rac1's password:
X11 forwarding request failed on channel 0
Last login: Mon Apr 25 18:02:35 2016 from
[oracle@rac1 ~]$

The solution that I’ve found is this one: just set the X11UseLocalhost to “no” (in my case was set to “yes”):

vi /etc/ssh/sshd_config
X11Forwarding yes
#X11DisplayOffset 10
X11UseLocalhost no