{"id":3056,"date":"2022-10-18T11:59:27","date_gmt":"2022-10-18T11:59:27","guid":{"rendered":"https:\/\/www.gridhosting.co.uk\/blogs\/?p=3056"},"modified":"2022-10-12T12:03:11","modified_gmt":"2022-10-12T12:03:11","slug":"how-to-check-linux-cpu-usage-or-utilization","status":"publish","type":"post","link":"https:\/\/www.gridhosting.co.uk\/blogs\/how-to-check-linux-cpu-usage-or-utilization\/","title":{"rendered":"How to Check Linux CPU Usage or Utilization?"},"content":{"rendered":"<p><span style=\"font-weight: 400;\">CPU usage is a significant metric for the Performance of CPU in Linux. On the other hand, Linux is a multi-tasking operating system that distributes the time of each CPU and allows it to do every task via a scheduler. In this article, you will learn how to monitor CPU usage, and you will also understand how to fix high <\/span><b><a href=\"https:\/\/www.gridhosting.co.uk\/linux-hosting\">Linux <\/a><\/b>CPU usage<b>.<\/b><span style=\"font-weight: 400;\"> Although there are multiple ways through which you can check the CPU usage. However, the easiest way of doing it is using the top Command.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You have to type \u2018top\u2019 in the command prompt and there will be a list of the currently running processes. Moreover, you will also see information about CPU usage. Memory Usage and load average. Press the w key to exit from the top command.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">According to IT experts, Top Command is a great tool to measure <\/span><b>Linux CPU usage.<\/b><span style=\"font-weight: 400;\"> It offers you a quick insight into how much CPU is utilized by each process. It helps the user to determine the Per CPU usage. Moreover, you will be in a good position to decide how you can reduce the usage. Although the user interface of the top command is not user-friendly. You will see a huge amount of information on this page. Here we will try to cover every important information which can be helpful.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In this first line, you will see <\/span><span style=\"font-weight: 400;\">(in order): system time (duration since the last restart), the number of active users\u2019 sessions, and the load average of every system. Here the load average is highly relevant for us it puts light on CPU usage of the system over time.<\/span><\/p>\n<h2><b>Load Average\u00a0<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Load average has three given numbers which are 1 5 and 15. Consider these numbers as percentages such as 0.2 means 20% and a load of 1.00 refers to 100%. It is very easy to understand for everyone but you might see averages of more than 1.00. It is because the load average is not an accurate measurement of <\/span><b>Linux CPU usage<\/b><span style=\"font-weight: 400;\">. However, it helps you figure out how much work your system is processing. For instance, a value of 2.50 means that the current load is 250% and demonstrates that the system is overloaded by 150%.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The second line is quite easy to understand which shows the number of tasks currently running and their current situation. There will be a third line where you will find CPU usage along with statistical data.\u00a0<\/span><\/p>\n<h2><b>Linux CPU Usage From Top<\/b><\/h2>\n<ul>\n<li><b>us<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">refers to the time utilized in the user space\u00a0<\/span><\/li>\n<li><b>sy; <\/b><span style=\"font-weight: 400;\">Percentage of CPU time utilized in kernel space\u00a0<\/span><\/li>\n<li><b>ni<\/b><span style=\"font-weight: 400;\">:<\/span><span style=\"font-weight: 400;\"> indicates the percentage of CPU time spent on current running processes with priority defined by the users\u00a0<\/span><\/li>\n<li><b>id<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">percentage of CPU remained idle\u00a0<\/span><\/li>\n<li><b>wa<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">percentage spent on waiting for a hard drive to complete reading the available data<\/span><\/li>\n<li><b>hi<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">Time spent a percentage of CPU on hardware processing\u00a0<\/span><\/li>\n<li><b>si<\/b><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">Time spent processing the software interrupts\u00a0<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">you will see the next two lines are dedicated to the memory information as they are not related to the CPU usage monitoring.<\/span><\/p>\n<h2><b>Simplifying Top<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">Since there is huge information on the top command which means it is not easy to get quick information for anyone. However, top offers us an easy opportunity to get the required details without wasting time by streamlining things. When the top is under process a user can press \u2018t\u2019 key to cycle through different views and get an easy outcome of CPU usage<\/span><\/p>\n<h2><b>CPU Usage Graph <\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In case you are finding it difficult to monitor <\/span><b>Linux CPU usage<\/b><span style=\"font-weight: 400;\"> through the top you can do it via top. You can use the package manager for the installation\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">htop command<\/span><\/p>\n<p><span style=\"font-weight: 400;\">As you can see from the screenshot above, the output from htop is more concise and better suited than\u00a0top \u00a0for simple measuring of CPU usage.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can exit this screen the same way as top, by pressing \u2018q\u2019.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">There are also other ways through which you can monitor the CPU usage which is mentioned below\u00a0<\/span><\/p>\n<p style=\"text-align: center;\"><strong>You May Also Like to Read: <a href=\"https:\/\/www.gridhosting.co.uk\/blogs\/best-linux-server-distributions-or-distros-of-2022\/\">Best Linux Server Distributions Or Distros of 2022<\/a><\/strong><\/p>\n<h2><b>More Ways To Find Usage\u00a0<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">A few more tools are available for anyone to check the CPU usage which is available in the sysstat package. You need to install it in your system to use all the commands.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After the installation of sysstat you will have total access to mpstat command. Which indicates information similar to the top. However, it will be in an easy-to-understand manner. There is another command available in the package which is sar.\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">It is very helpful when combined with a number in the command. It will help you to determine how often the sar command should produce information about CPU usage<\/span><\/p>\n<p><span style=\"font-weight: 400;\">For example, to check CPU usage every 4 seconds:<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ sar 4<\/span><\/p>\n<h2><b>Graphical Monitoring\u00a0<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">In case you are using a desktop client or a graphical user interface. There will be graphical tools for keeping a check on the <\/span><b>Linux CPU usage. <\/b><span style=\"font-weight: 400;\">If we talk about UBUNTU, it has Gnome by default and the command required to initiate the system manager is\u00a0<\/span><\/p>\n<p><span style=\"font-weight: 400;\">$ gnome-system-monitor<\/span><\/p>\n<p><span style=\"font-weight: 400;\">After giving the command a window will open in front of you resembling with window\u2019s task manager. Where you can easily specify the processors by their usage. On the other hand, some other distributions might have the same tool for the purpose.<\/span><\/p>\n<h2><b>How to Configure Alerts for Monitoring<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">An individual can use multiple ways to code a script that can easily measure the usage of the CPU. Here we will explore some possible ways which can help you track down the CPU usage every second. It will inform you by email when the usage of the CPU is higher than usual.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">The Script uses sad to find out the average Idle CPU Percentage from sar. In addition to that, it uses and if function to check if the percentage is below a certain level. If it is low then the administrator will receive an email in the form of intimation regarding the situation. In case the CPU configuration is 20% and the usage is more than 70% user will get an email instantly.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">You can adjust the script as per your own requirements for instance if you want it to send you a warning alert to record a log fine instead of sending an email you can do it by calling the script from cron.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">In case there are issues with Linux CPU usage you don\u2019t need to worry at all. As we are here to help you fix the problem without asking for further assistance.<\/span><\/p>\n<h2><b>How to <\/b><b>high Linux CPU Usage<\/b><\/h2>\n<p><span style=\"font-weight: 400;\">You need to do a few things in case you find your system is showing a high CPU usage for a couple of days.<\/span><\/p>\n<ul>\n<li><span style=\"font-weight: 400;\">Run the command prompt and type \u2018top\u2019 and hit enter. You will see the current processes running on your system<\/span><\/li>\n<li><span style=\"font-weight: 400;\">In case you see a certain Process utilizing a lot of your CPU you can stop it through a command of <\/span><span style=\"font-weight: 400;\">kill &lt;pid&gt;. Here kill &lt;pid&gt; is the actual process id which you want to stop quickly<\/span><\/li>\n<li><span style=\"font-weight: 400;\">If you want to find the source of high CPU usage you need to run the command prompt and type <\/span><span style=\"font-weight: 400;\">journalctl -xe. The command will display all the logs of your computer\u00a0<\/span><\/li>\n<li><span style=\"font-weight: 400;\">Here you can sort out the entries which contain the word \u2018cpu\u2019 by using the \u201c-e\u201d parameter.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">If the results are not fruitful despite following the above steps and you are not getting the root cause of the problem. You can diagnose the issue by typing the command lsof.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">The \u201clsof\u201d tool can be used to show information about open files and network connections.<\/span><\/li>\n<li><span style=\"font-weight: 400;\">\u00a0If you\u2019re still having trouble, you can try to find more information about your problem by searching the internet or posting a question on a forum.<\/span><\/li>\n<\/ul>\n<p>For Special discounts and offers, visit our official\u00a0<strong><a href=\"https:\/\/www.facebook.com\/GridHosting\" target=\"_blank\" rel=\"noopener\">Facebook<\/a><\/strong>\u00a0Page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>CPU usage is a significant metric for the Performance of CPU in Linux. On the other hand, Linux is a multi-tasking operating system that distributes the time of each CPU and allows it to do every task via a scheduler. In this article, you will learn how to monitor CPU usage, and you will also [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":3109,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-site-content-layout":"","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-gradient":""}},"footnotes":""},"categories":[5],"tags":[740,738,739,737],"class_list":["post-3056","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-configure-alerts-for-monitoring","tag-cpu-usage","tag-cpu-usage-graph","tag-linux-cpu-usage"],"_links":{"self":[{"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/posts\/3056","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/comments?post=3056"}],"version-history":[{"count":4,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/posts\/3056\/revisions"}],"predecessor-version":[{"id":3101,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/posts\/3056\/revisions\/3101"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/media\/3109"}],"wp:attachment":[{"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/media?parent=3056"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/categories?post=3056"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gridhosting.co.uk\/blogs\/wp-json\/wp\/v2\/tags?post=3056"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}