{"id":770,"date":"2024-09-04T01:44:19","date_gmt":"2024-09-04T01:44:19","guid":{"rendered":"https:\/\/vpswebhostingindia.in\/blog\/?p=770"},"modified":"2024-09-05T09:24:23","modified_gmt":"2024-09-05T09:24:23","slug":"check-memory-usage-in-linux-via-ssh","status":"publish","type":"post","link":"https:\/\/vpswebhostingindia.in\/blog\/check-memory-usage-in-linux-via-ssh\/","title":{"rendered":"How to Check Memory Usage in Linux via SSH"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Check Memory Usage in Linux &#8211; System administrators must ensure that a Linux system always operates at optimal levels. You can use a few simple terminal commands to access all relevant information and monitor memory statistics on your <a href=\"https:\/\/vpswebhostingindia.in\/vps_hosting\/\">server<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-rank-math-toc-block\" id=\"rank-math-toc\"><h2>Table of Contents<\/h2><nav><ul><li><a href=\"#check-memory-usage-in-linux-via-command-line\">Check Memory Usage in Linux via Command Line<\/a><ul><li><a href=\"#vmstat-command\">vmstat Command<\/a><\/li><li><a href=\"#top-command\">top Command<\/a><\/li><li><a href=\"#htop-command\">htop Command<\/a><\/li><li><a href=\"#cat-command\">cat Command<\/a><\/li><li><a href=\"#free-command\">free Command<\/a><\/li><li><a href=\"#sar-command\">sar Command<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"check-memory-usage-in-linux-via-command-line\">Check Memory Usage in Linux via Command Line<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Checking Linux memory usage via the command line is a highly efficient method and often the only way to check memory usage on <a href=\"https:\/\/www.squarebrothers.in\/hosting\/vps-hosting\" rel=\"nofollow noopener\" target=\"_blank\">remote headless servers<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Use the examples below to check memory usage via SSH<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"vmstat-command\">vmstat Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The vmstat command reports virtual memory statistics. Type <strong><code>vmstat<\/code><\/strong> to get a snapshot of the system&#8217;s virtual memory statistics, including processes, memory, paging, block IO, traps, and CPU activity:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vmstat<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"963\" height=\"169\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-4.png\" alt=\"Check Memory Usage in Linux\" class=\"wp-image-775\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-4.png 963w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-4-300x53.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-4-768x135.png 768w\" sizes=\"auto, (max-width: 963px) 100vw, 963px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Use the following list to interpret the virtual memory statistics provided by <strong><code>vmstat<\/code><\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Procs<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>r<\/strong> &#8211; Number of processes waiting for run time.<\/li>\n\n\n\n<li><strong>b<\/strong> &#8211; Number of processes in uninterruptible sleep.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Memory<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>swpd<\/strong> &#8211; Amount of virtual memory used.<\/li>\n\n\n\n<li><strong>free<\/strong> &#8211; Amount of idle memory.<\/li>\n\n\n\n<li><strong>buff<\/strong> &#8211; Amount of memory used as buffers.<\/li>\n\n\n\n<li><strong>cache<\/strong> &#8211; Amount of memory used as cache.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Swap<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>si<\/strong> &#8211; Memory swapped in from disk (\/s).<\/li>\n\n\n\n<li><strong>so<\/strong> &#8211; Memory swapped to disk (\/s).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>IO<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>bi<\/strong> &#8211; Blocks received from a block device (blocks\/s).<\/li>\n\n\n\n<li><strong>bo<\/strong> &#8211; Blocks sent to a block device (blocks\/s).<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>System<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>in<\/strong> &#8211; Number of interrupts per second, including the clock.<\/li>\n\n\n\n<li><strong>cs<\/strong> &#8211; Number of context switches per second.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>CPU<\/strong><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">These values represent the percentage of total CPU time.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>us<\/strong> &#8211; Time spent running non-kernel code (user time, including nice time).<\/li>\n\n\n\n<li><strong>sy <\/strong>&#8211; Time spent running kernel code (system time).<\/li>\n\n\n\n<li><strong>id<\/strong> &#8211; Time spent idle. Before Linux 2.5.41, this includes IO-wait time.<\/li>\n\n\n\n<li><strong>wa<\/strong> &#8211; Time spent waiting for IO. Before Linux 2.5.41, included in idle.<\/li>\n\n\n\n<li><strong>st<\/strong> &#8211; Time stolen from a virtual machine. Before Linux 2.6.11, unknown.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Use the information from the fields to identify potential bottlenecks or areas that may require optimization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"top-command\">top Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The top command is essential for monitoring CPU and memory usage on a per-process basis. To launch it, enter <strong><code>top<\/code><\/strong> in the terminal :<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>top<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The system displays information about:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>System uptime.<\/li>\n\n\n\n<li>Average load.<\/li>\n\n\n\n<li>Number of running tasks.<\/li>\n\n\n\n<li>Number of logged-in users.<\/li>\n\n\n\n<li>CPU utilization for each CPU or core.<\/li>\n\n\n\n<li>Memory and swap usage statistics for processes.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"699\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-5-1024x699.png\" alt=\"\" class=\"wp-image-776\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-5-1024x699.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-5-300x205.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-5-768x524.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-5.png 1242w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The data is continuously updated, which allows you to follow the process activity and system resources in real time.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In addition to providing essential memory information, the <strong><code>top<\/code><\/strong> command has an interactive interface that allows you to sort processes, change display settings, and manage operations without leaving the tool.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Press <strong><code>q<\/code><\/strong> to exit the interface.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"htop-command\">htop Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Like the <strong><code>top<\/code><\/strong> command, <strong><code>htop<\/code><\/strong> provides memory and CPU usage monitoring data but with several enhancements for a more user-friendly environment and improved controls.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It features color-coded output and allows full command lines for processes to be viewed. Additionally, <strong><code>htop<\/code><\/strong> supports vertical and horizontal scrolling for process lists.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">To start <strong><code>htop<\/code><\/strong>, enter:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>htop<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"579\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6-1024x579.png\" alt=\"\" class=\"wp-image-777\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6-1024x579.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6-300x170.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6-768x434.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6-1536x869.png 1536w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-6.png 1830w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The output is divided into two main sections:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. The top segment provides the summary and contains graphic meters and text counters.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">2. The lower section structures the detailed data per process. This allows users to perform actions on individual processes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The shortcuts at the bottom of the screen enable users to manipulate and customize the processes without typing commands.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"cat-command\">cat Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use the cat command to open the <em>\/proc\/meminfo<\/em> file in your terminal:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat \/proc\/meminfo<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><em>\/proc\/meminfo<\/em> is a virtual file that reports the amount of available and used memory. It contains real-time information about the system&#8217;s memory usage as well as buffers and shared memory used by the kernel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This is an example of the <em>\/proc\/meminfo<\/em> file in Ubuntu 22.04:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"698\" height=\"851\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-1.png\" alt=\"\" class=\"wp-image-772\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-1.png 698w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-1-246x300.png 246w\" sizes=\"auto, (max-width: 698px) 100vw, 698px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The values in the <em>\/proc\/meminfo<\/em> file are expressed in <strong>kibibytes<\/strong>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"free-command\">free Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The free command is used to monitor resource usage. It summarizes RAM and swap space usage, including total, used, free, shared, buff\/cache, and available memory.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Type <strong><code>free<\/code><\/strong> in your terminal, without options, to display information about memory and swap, expressed in kibibytes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>free<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"948\" height=\"165\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-2.png\" alt=\"\" class=\"wp-image-773\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-2.png 948w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-2-300x52.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-2-768x134.png 768w\" sizes=\"auto, (max-width: 948px) 100vw, 948px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Here&#8217;s what each column represents:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Column<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td><strong>total<\/strong><\/td><td>Total installed memory.<\/td><\/tr><tr><td><strong>used<\/strong><\/td><td>Memory currently in use (excluding buffers and cache).<\/td><\/tr><tr><td><strong>free<\/strong><\/td><td>Unused memory.<\/td><\/tr><tr><td><strong>shared<\/strong><\/td><td>Memory used by <strong>tmpfs<\/strong> and shared between processes.<\/td><\/tr><tr><td><strong>buff\/cache<\/strong><\/td><td>The sum of buffer and cache memory, which are used by the operating system to speed up processes.<\/td><\/tr><tr><td><strong>available<\/strong><\/td><td>An estimation of how much memory is available <br>for starting new applications, without swapping.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><code>free<\/code><\/strong> command has multiple options that allow users to customize the output.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Option<\/th><th>Result<\/th><\/tr><\/thead><tbody><tr><td><strong><code>-b<\/code><\/strong><\/td><td>Output in bytes.<\/td><\/tr><tr><td><strong><code>-k<\/code><\/strong><\/td><td>Output in kibibytes.<\/td><\/tr><tr><td><strong><code>-m<\/code><\/strong><\/td><td>Output in mebibytes.<\/td><\/tr><tr><td><strong><code>-g<\/code><\/strong><\/td><td>Output in gibibytes.<\/td><\/tr><tr><td><strong><code>-l<\/code><\/strong><\/td><td>Detailed low and high memory statistics.<\/td><\/tr><tr><td><strong><code>-o<\/code><\/strong><\/td><td>Old format (no -\/+buffers\/cache line).<\/td><\/tr><tr><td><strong><code>-t<\/code><\/strong><\/td><td>Total for RAM + swap.<\/td><\/tr><tr><td><strong><code>-s<\/code><\/strong><\/td><td>Update every [delay] seconds.<\/td><\/tr><tr><td><strong><code>-c<\/code><\/strong><\/td><td>Update [count] times.<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Use these options to adapt memory usage output to your needs.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"sar-command\">sar Command<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong><code>sar<\/code><\/strong> tool is a utility for monitoring system performance. It is not limited strictly to memory usage, but you can use the <strong><code>-r<\/code><\/strong> option to track memory utilization statistics at regular intervals.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">For example, enter the following command to direct <strong><code>sar<\/code><\/strong> to check memory usage statistics every second, five times in a row:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sar -r 1 5<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The metrics provide a detailed overview of your system&#8217;s memory utilization in several columns, including:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>kbmemfree<\/strong> &#8211; The amount of free memory in kilobytes.<\/li>\n\n\n\n<li><strong>kbmemused<\/strong> &#8211; The amount of used memory in kilobytes.<\/li>\n\n\n\n<li><strong>%memused<\/strong> &#8211; The percentage of used memory.<\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"235\" src=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-8-1024x235.png\" alt=\"\" class=\"wp-image-780\" srcset=\"https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-8-1024x235.png 1024w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-8-300x69.png 300w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-8-768x176.png 768w, https:\/\/vpswebhostingindia.in\/blog\/wp-content\/uploads\/2024\/09\/image-8.png 1517w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">he <strong><code>sar<\/code><\/strong> utility is part of the <strong><code>sysstat<\/code><\/strong> package, which may not be pre-installed on some Linux distributions. Use the appropriate command to install the <strong><code>sysstat<\/code><\/strong> package:<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Linux Distribution<\/th><th>Command<\/th><\/tr><\/thead><tbody><tr><td>Debian\/Ubuntu<\/td><td><strong><code>sudo apt install sysstat<\/code><\/strong><\/td><\/tr><tr><td>RHEL 8+ and CentOS Stream<\/td><td><strong><code>sudo dnf install sysstat<\/code><\/strong><\/td><\/tr><tr><td>Fedora<\/td><td><strong><code>sudo dnf install sysstat<\/code><\/strong><\/td><\/tr><tr><td>Arch Linux<\/td><td><strong><code>sudo pacman -S sysstat<\/code><\/strong><\/td><\/tr><tr><td>openSUSE<\/td><td><strong><code>sudo zypper install sysstat<\/code><\/strong><\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>Check Memory Usage in Linux &#8211; System administrators must ensure that a Linux system always operates at optimal levels. You can use a few simple terminal commands to access all relevant information and monitor memory statistics on your server. Check Memory Usage in Linux via Command Line Checking Linux memory usage via the command line [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":781,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"_eb_attr":"","footnotes":""},"categories":[17,35],"tags":[],"class_list":["post-770","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps","category-ssh"],"_links":{"self":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/770","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/comments?post=770"}],"version-history":[{"count":3,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions"}],"predecessor-version":[{"id":796,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/posts\/770\/revisions\/796"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media\/781"}],"wp:attachment":[{"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/media?parent=770"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/categories?post=770"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/vpswebhostingindia.in\/blog\/wp-json\/wp\/v2\/tags?post=770"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}