{"id":835,"date":"2010-06-01T01:30:49","date_gmt":"2010-06-01T05:30:49","guid":{"rendered":"http:\/\/linuxhostingsupport.net\/blog\/?p=835"},"modified":"2013-03-20T08:42:47","modified_gmt":"2013-03-20T12:42:47","slug":"how-to-find-out-cpu-utilization-in-linux-2","status":"publish","type":"post","link":"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2","title":{"rendered":"How to find out CPU Utilization in Linux?"},"content":{"rendered":"<p>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\u00a0 commands to check the daily CPU usage on the Linux server.<\/p>\n<p>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.<\/p>\n<p>Using the following commands, one can track the:<\/p>\n<ul>\n<li><span style=\"color: #0000ff;\">Real time view of CPU utilization on the system<\/span><\/li>\n<\/ul>\n<ul>\n<li><span style=\"color: #0000ff;\">Utilization of each CPU on the system<\/span><\/li>\n<\/ul>\n<ul>\n<li><span style=\"color: #0000ff;\">CPU utilization of each running process<\/span><\/li>\n<\/ul>\n<ul>\n<li><span style=\"color: #0000ff;\">Average cpu usage since the last reboot<\/span><\/li>\n<\/ul>\n<p><span style=\"color: #0000ff;\"><strong>1) Top:<\/strong><\/span><br \/>\nOne of the common command in Linux to check the CPU usage is &#8220;top&#8221;. The top command provides a real time view of everything which includes CPU utilization, Memory utilization, running processes. To execute the command, just type &#8220;top&#8221;.<\/p>\n<pre><strong># top<\/strong><\/pre>\n<p><a href=\"https:\/\/linuxhostingsupport.net\/blog\/howto-check-memoryram-usage-in-linux\/top1\" rel=\"attachment wp-att-694\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-694\" title=\"top1\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/04\/top1-585x118.jpg\" alt=\"\" width=\"550\" height=\"110\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/04\/top1-585x118.jpg 585w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/04\/top1-300x60.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/04\/top1.jpeg 622w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>The above output shows dynamic values of various CPU parameters like user, system, nice, idle, iowait.<\/p>\n<p><span style=\"color: #0000ff;\"><strong>2) PS:<\/strong><\/span><\/p>\n<p>The &#8216;ps&#8217; command by default display the status of our terminal connection. ps offers various options to display the status of currently running processes. For example,<\/p>\n<pre><strong># ps -auxf<\/strong><\/pre>\n<p>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.<\/p>\n<p>You can use &#8216;ps&#8217; 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 &#8220;eo&#8221; with ps is use to display contents field wise and then we can sort the generated output using &#8216;sort&#8217;.<\/p>\n<pre><strong># ps -eo pcpu,pid,user,args | sort -k 1 -r<\/strong><\/pre>\n<p><a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/ps\" rel=\"attachment wp-att-892\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-892\" title=\"ps\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/ps.jpg\" alt=\"\" width=\"464\" height=\"115\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/ps.jpg 464w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/ps-300x74.jpg 300w\" sizes=\"(max-width: 464px) 100vw, 464px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<ul>\n<li><span style=\"color: #0000ff;\">Install SYSSTAT package to install different monitoring tools.<\/span><\/li>\n<\/ul>\n<p>The other 3 commands to find out CPU utilization are<br \/>\n<strong>iostat<\/strong><span style=\"color: #0000ff;\"><strong><br \/>\n<\/strong><\/span><strong>mpstat<\/strong><span style=\"color: #0000ff;\"><strong><br \/>\n<\/strong><\/span><strong>sar<\/strong><\/p>\n<p>but they are not available by default.<\/p>\n<p>In order to use the above commands, <strong>you need to install a monitoring package called &#8220;sysstat&#8221; using yum<\/strong>.<\/p>\n<blockquote>\n<pre><span style=\"color: #0000ff;\"># yum install sysstat<\/span><\/pre>\n<\/blockquote>\n<p>Once &#8216;sysstat&#8217; package is installed, start the service<\/p>\n<blockquote>\n<pre><span style=\"color: #0000ff;\"># service sysstat start<\/span><\/pre>\n<\/blockquote>\n<p><span style=\"color: #0000ff;\"><strong>3) IOSTAT:<\/strong><\/span><\/p>\n<p>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<\/p>\n<pre><strong># iostat<\/strong><\/pre>\n<p><a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/iostat\" rel=\"attachment wp-att-861\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-861\" title=\"iostat\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat.jpg\" alt=\"\" width=\"570\" height=\"182\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat.jpg 570w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-300x95.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-469x150.jpg 469w\" sizes=\"(max-width: 570px) 100vw, 570px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>To display the stats of CPU usage only, execute<\/p>\n<pre><strong># iostat -c<\/strong>\r\n <a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/iostat-1\" rel=\"attachment wp-att-864\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-864\" title=\"iostat-1\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-1.jpg\" alt=\"\" width=\"532\" height=\"92\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-1.jpg 532w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-1-300x51.jpg 300w\" sizes=\"(max-width: 532px) 100vw, 532px\" \/><\/a><\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p>You may also want to display the CPU stats after every specific interval say, 2 seconds<\/p>\n<pre><strong># iostat -tc 2<\/strong>\r\n <a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/iostat-2\" rel=\"attachment wp-att-873\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-full wp-image-873\" title=\"iostat-2\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-2.jpg\" alt=\"\" width=\"537\" height=\"225\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-2.jpg 537w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-2-300x125.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/iostat-2-358x150.jpg 358w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/a><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>4) MPSTAT:<\/strong><\/p>\n<p>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:<\/p>\n<p><span style=\"color: #0000ff;\"><strong># mpstat<\/strong><\/span><br \/>\n<a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/mpstat\" rel=\"attachment wp-att-876\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-876\" title=\"mpstat\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-550x62.jpg\" alt=\"\" width=\"550\" height=\"62\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-550x62.jpg 550w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-300x33.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat.jpg 727w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>In order to display the usage of each CPU on the server, execute<\/p>\n<pre><strong># mpstat -p ALL<\/strong>\r\n <a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/mpstat-1\" rel=\"attachment wp-att-883\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-883\" title=\"mpstat-1\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-1-550x113.jpg\" alt=\"\" width=\"550\" height=\"113\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-1-550x113.jpg 550w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-1-300x61.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/mpstat-1.jpg 729w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #0000ff;\"><strong>5) SAR :<\/strong><\/span><\/p>\n<p>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.<\/p>\n<pre><strong># sar<\/strong>\r\n <a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/sar-2\" rel=\"attachment wp-att-886\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-886\" title=\"sar\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-547x150.jpg\" alt=\"\" width=\"547\" height=\"150\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-547x150.jpg 547w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-300x82.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar.jpg 653w\" sizes=\"(max-width: 547px) 100vw, 547px\" \/><\/a><\/pre>\n<p>One can also display the current CPU usage in specific time interval. The following command generates the output every 2 seconds for 3 times.<\/p>\n<pre><strong># sar -u 2 3<\/strong>\r\n <a href=\"https:\/\/linuxhostingsupport.net\/blog\/how-to-find-out-cpu-utilization-in-linux-2\/sar-1\" rel=\"attachment wp-att-889\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-large wp-image-889\" title=\"sar-1\" src=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-1-550x114.jpg\" alt=\"\" width=\"550\" height=\"114\" srcset=\"https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-1-550x114.jpg 550w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-1-300x62.jpg 300w, https:\/\/linuxhostingsupport.net\/blog\/wp-content\/uploads\/2010\/05\/sar-1.jpg 660w\" sizes=\"(max-width: 550px) 100vw, 550px\" \/><\/a><\/pre>\n<p>&nbsp;<\/p>\n<p>These are the ways to figure out the CPU usage on your system and then take appropriate steps to tackle CPU related issues.<\/p>\n<h3><span style=\"text-decoration: underline;\"><span style=\"color: #0000ff;\"><strong>Related Links:<\/strong><\/span><\/span><\/h3>\n<p><strong><a title=\"How to check RAM\/Memory usage in Linux?\" href=\"https:\/\/linuxhostingsupport.net\/blog\/howto-check-memoryram-usage-in-linux\" target=\"_blank\">How to check RAM\/Memory usage in Linux?<\/a><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>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\u00a0 commands to check the daily CPU usage on the Linux server.<br \/>\nCPU 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 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[867,972,865,862,870,872,871,869,974,866,973,975,868,864],"_links":{"self":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/835"}],"collection":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/comments?post=835"}],"version-history":[{"count":84,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/835\/revisions"}],"predecessor-version":[{"id":2203,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/posts\/835\/revisions\/2203"}],"wp:attachment":[{"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/media?parent=835"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/categories?post=835"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linuxhostingsupport.net\/blog\/wp-json\/wp\/v2\/tags?post=835"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}