How to find out CPU Utilization in Linux?

June 1, 2010    |   Posted by admin   |    Category: Linux Administration

There are various ways to check the CPU usage on a Linux server, like using top and ps commands OR by installing the sysstat package which includes sar, iostat, mpstatĀ  commands to check the daily CPU usage on the Linux server.

CPU is the most important component in any server which is use to process all the tasks on your server. Whenever CPU is engaged in processing a specific task, it becomes unavailable for other processes. The other processes have to wait till the CPU is free thus creating a bottleneck in the system.

Using the following commands, one can track the:

  • Real time view of CPU utilization on the system
  • Utilization of each CPU on the system
  • CPU utilization of each running process
  • Average cpu usage since the last reboot

1) Top:
One of the common command in Linux to check the CPU usage is “top”. The top command provides a real time view of everything which includes CPU utilization, Memory utilization, running processes. To execute the command, just type “top”.

# top

 

The above output shows dynamic values of various CPU parameters like user, system, nice, idle, iowait.

2) PS:

The ‘ps’ command by default display the status of our terminal connection. ps offers various options to display the status of currently running processes. For example,

# ps -auxf

will display all the details of all the processes like User, PID, CPU/memory usage, the terminal it is executed from, the time and the process being executed.

You can use ‘ps’ command to sort out the high CPU utilization processes as well which in turn helps you to optimize your server in a better way. The option “eo” with ps is use to display contents field wise and then we can sort the generated output using ‘sort’.

# ps -eo pcpu,pid,user,args | sort -k 1 -r

 

 

 

 

 

  • Install SYSSTAT package to install different monitoring tools.

The other 3 commands to find out CPU utilization are
iostat
mpstat
sar

but they are not available by default.

In order to use the above commands, you need to install a monitoring package called “sysstat” using yum.

# yum install sysstat

Once ‘sysstat’ package is installed, start the service

# service sysstat start

3) IOSTAT:

The iostat command displays the average CPU usage since the last reboot. By default, the command without an option displays the average CPU usage and input/output stats of all the drives and their partitions. Execute

# iostat

 

To display the stats of CPU usage only, execute

# iostat -c
 

 

 

 

You may also want to display the CPU stats after every specific interval say, 2 seconds

# iostat -tc 2
 

 

4) MPSTAT:

mpstat command is use to display CPU usage of each CPU individually. By default, mpstat command without option shows the extended output of CPU usage. See below:

# mpstat

 

In order to display the usage of each CPU on the server, execute

# mpstat -p ALL
 

 

5) SAR :

sar command generates the stats for CPU usage, RAM usage and load average of the server and stores them in a file at regular interval. By default, the command without an option displays CPU stats of the current day.

# sar
 

One can also display the current CPU usage in specific time interval. The following command generates the output every 2 seconds for 3 times.

# sar -u 2 3
 

 

These are the ways to figure out the CPU usage on your system and then take appropriate steps to tackle CPU related issues.

Related Links:

How to check RAM/Memory usage in Linux?

How to generate a full backup of an account/domain from cPanel?

May 23, 2010    |   Posted by admin   |    Category: cPanel Management

You can perform a full backup of your account/domain from cPanel >> “Backups” option under the Files section. The full cPanel backup is very useful when migrating an account from one server to another.

1) Login to cPanel at http://yourdomainname.tld:2082 click the “Backups” option as shown in the screen below

 

2) On the next screen, cPanel will offer you various option to generate a full backup, i.e. to backup a home directory, databases, emails etc. Click on “Download or Generate a Full Website Backup” as shown in the following screen.

 

 

 

 

 

 

 

 

 

 

 

 

3) Here you will have to decide where you need to save the copy of the backup file by selecting the appropriate option from the “Backup Destination” drop down list.

a) “Home Directory” to keep the backup under your home directory itself i.e. /home/username. Click “Generate Backup” button to start the backup process and the backup file will be visible on the same screen once the process completes.

 

 

 

 

 

 

 

 

 

 

 

 

b) “Remote Ftp Server” if you want to send the backup file to a remote server in which case, you need to mention the Remote Server IP, Ftp user/password, port and directory. Click “Generate Backup” button and the backup file will be copied to the remote server once the process completes.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

In either of the above case, you can specify an email address in the “Email Address” field to receive a notification.

Note: This cPanel generated backup cannot be restored from the cPanel interface. It can only be restored from shell as root OR from WHM interface.

Comments Off on How to generate a full backup of an account/domain from cPanel?

open /dev/mptctl: No such device. Make sure mptctl is loaded into the kernel

May 21, 2010    |   Posted by admin   |    Category: Linux Administration

The “mptctl” kernel module is required to check the RAID status on a Linux server using “mpt-status” tool.

You may receive “/dev/mptctl: No such device” message OR “Make sure mptctl is loaded into the kernel” while checking the RAID status which indicates that the module is not loaded in the kernel OR the device “/dev/mptctl” is not created.

# mpt-status 
 open /dev/mptctl: No such device 
 Are you sure your controller is supported by mptlinux? 
 Make sure mptctl is loaded into the kernel

To create the mptctl device, execute:

# mknod /dev/mptctl c 10 22

and verify it by

# ls -la 
 /dev/mptctl crw------- 1 root root 10, 220 Apr 12 08:05 /dev/mptctl

Once the device is created, load the module in the kernel using modprobe

# modprobe mptctl

and verify it using lsmod which should list the following modules along with it’s details

# lsmod |grep mptctl 
 mptctl 
 mptbase 
 scsi_mod

Add the module in /etc/rc.modules file to load the module in kernel on every reboot.

modprobe mptctl

Save the file. This will make sure the module is loaded in the kernel on every server reboot.

Once done, you will be able to check the RAID status by executing the ‘mpt-status’ command and it should show something like the following:

# mpt-status
 ioc0 vol_id 0 type IM, 2 phy, 465 GB, state OPTIMAL, flags ENABLED 
 ioc0 phy 1 scsi_id 1 ATA ST3 CC38, 10 GB, state ONLINE, flags NONE 
 ioc0 phy 0 scsi_id 4 ATA ST3 CC38, 10 GB, state ONLINE, flags NONE

Invalid command “SSLEngine”, perhaps misspelled OR defined by a module not included.

May 16, 2010    |   Posted by admin   |    Category: Linux Administration

We install a SSL certificate on a domain to secure the transaction carried out on a website but sometimes we receive an error message

"Invalid command "SSLEngine", perhaps misspelled or 
 defined by a module not included in the server configuration"

while browsing the website. The error message indicates that the module mod_ssl required to run SSL engine on a CentOS server is missing and needs to be installed.

Install the mod_ssl module using yum

# yum install mod_ssl

Once it is installed, make sure to restart the Apache service

# service httpd restart

You should now be able to browse the website using https.

mpt-status.h:6:28: error: linux/compiler.h: No such file or directory

May 14, 2010    |   Posted by admin   |    Category: Linux Administration

While compiling ‘mpt-status’ tool with the kernel source, you may receive a ‘linux/compiler.h: No such file or directory’ message.

mpt-status.h:6:28:error: linux/compiler.h: No such file or directory
make: *** [mpt-status] Error 1

The reason is the missing compiler.h header file which isn’t all that necessary. The fix is to edit the mpt-status.h file which is under the extracted directory

# vi mpt-status.h

and remove the line which states

#include <linux/compiler.h>

Save the file and you should be able to compile ‘mpt-status’ using “make” with the kernel source.

Comments Off on mpt-status.h:6:28: error: linux/compiler.h: No such file or directory