Monitoring RAM resources of your VPS is very important. Especially, if you use caching systems such as Redis or Memcached. If your server runs out of memory, or runs short on memory, your website or service can stop or may run slow.<\/p>\n
Luckily, Linux gives you a few handy tools that you would need to monitor memory usage. These tools can be easily used from the command line. This short (and sweet) article will give you an idea how to use those commands, and you can pick the one that fits your needs the most.<\/p>\n
Type in\u00a0 If you need more details, run vmstat with the\u00a0 This is a widely known command to check both memory and CPU usage.<\/p>\n This is my favorite, and probably the most simple command to view memory stats.<\/p>\n The example above shows you how much total memory your VPS has (in Megabytes), how much memory is used, and how much memory is free.<\/p>\n This command is similar to the\u00a0 The commands listed above can be used to manually monitor memory usage. You can also write a simple script using your preferred programming language to run these commands and alert you (by email, for example) if your memory resources are low.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"","format":"standard","manualknowledgebasecat":[242],"manual_kb_tag":[485],"_links":{"self":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2983"}],"collection":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb"}],"about":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/types\/manual_kb"}],"author":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/comments?post=2983"}],"version-history":[{"count":1,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2983\/revisions"}],"predecessor-version":[{"id":2984,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb\/2983\/revisions\/2984"}],"wp:attachment":[{"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/media?parent=2983"}],"wp:term":[{"taxonomy":"manualknowledgebasecat","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manualknowledgebasecat?post=2983"},{"taxonomy":"manual_kb_tag","embeddable":true,"href":"https:\/\/support.aklwebhost.com\/wp-json\/wp\/v2\/manual_kb_tag?post=2983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}vmstat<\/code>\u00a0to your command line and the program will display how much free memory is available.<\/p>\n
root@localhost:\/# vmstat\r\nprocs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----\r\n r b swpd free buff cache si so bi bo in cs us sy id wa st\r\n 3 0 0 185332 43880 150176 0 0 2 6 8 7 0 0 100 0 0\r\n<\/code><\/pre>\n
-s<\/code>\u00a0or\u00a0
--stats<\/code>\u00a0parameter. Check the first line of the output to see how much free memory is available on your server.<\/p>\n
root@209:\/# vmstat -s\r\n759872 K total memory\r\n575220 K used memory\r\n356148 K active memory\r\n86168 K inactive memory\r\n184652 K free memory\r\n44048 K buffer memory\r\n149248 K swap cache\r\n0 K total swap\r\n0 K used swap\r\n0 K free swap\r\n806545 non-nice user cpu ticks\r\n1 nice user cpu ticks\r\n533833 system cpu ticks\r\n424692262 idle cpu ticks\r\n54982 IO-wait cpu ticks\r\n244344 IRQ cpu ticks\r\n0 softirq cpu ticks\r\n0 stolen cpu ticks\r\n7190421 pages paged in\r\n27240788 pages paged out\r\n0 pages swapped in\r\n0 pages swapped out\r\n335817481 interrupts\r\n285597986 CPU context switches\r\n1425579890 boot time\r\n332134 forks\r\n<\/code><\/pre>\n
2. top command<\/h3>\n
top - 03:20:50 up 49 days, 8:55, 1 user, load average: 0.00, 0.01, 0.05\r\nTasks: 87 total, 1 running, 86 sleeping, 0 stopped, 0 zombie\r\n%Cpu(s): 0.3 us, 0.3 sy, 0.0 ni, 99.3 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st\r\nKiB Mem: 759872 total, 576156 used, 183716 free, 44628 buffers\r\nKiB Swap: 0 total, 0 used, 0 free. 149652 cached Mem\r\n\r\nPID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND\r\n1 root 20 0 36284 5312 1192 S 0.0 0.7 0:42.98 init\r\n2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd\r\n3 root 20 0 0 0 0 S 0.0 0.0 0:05.13 ksoftirqd\/0\r\n5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker\/0:0H\r\n<\/code><\/pre>\n
3. free command<\/h3>\n
root@209:\/# free -m\r\n total used free shared buffers cached\r\nMem: 742 562 179 27 43 146\r\n-\/+ buffers\/cache: 372 369\r\nSwap: 0 0 0\r\n<\/code><\/pre>\n
4. htop command<\/h3>\n
top<\/code>\u00a0command, but in my opinion, it gives you a better idea about the memory state of your server.<\/p>\n
Conclusion<\/h3>\n