View and monitor server load

I run my products on VPS and need a tool to view and monitor server load, especially during special occasions with high traffic like Black Friday.

View the server load

To view the server load, use the following command:

cat /proc/loadavg
0.08 0.12 0.09 1/413 3599988

The first three fields in this file are load average figures giving the number of jobs in the run queue (state R) or waiting for disk I/O (state D) averaged over 1, 5, and 15 minutes.

The fourth field consists of two numbers separated by a slash (/). The first of these is the number of currently runnable kernel scheduling entities (processes, threads). The value after the slash is the number of kernel scheduling entities that currently exist on the system.

The fifth field is the PID of the process that was most recently created on the system.

Source

You can also use other commands like uptime, top, or htop to get the same result.

Monitor the server load

Linux doesn't store the server load over time. To store these values, you can add it to your own file, like this:

cat /proc/loadavg >> loads

This command will write (append) the load average to the loads file of the current directory.

If you want to log the current time, use this command:

echo "$(date +'%F %T %z'): $(cat /proc/loadavg)"
2023-12-01 16:06:47 +0000: 0.18 0.36 0.47 1/438 1294230

To log the load average over time, use cronjob like this:

*/5 * * * * cat /proc/loadavg >> loads

This will log the server load average every 5 minutes.

In one day, it will write 24 * 60 / 5 = 288 times (lines). Each line is around 30 bytes, so each day, the log file will increase 30 Bytes * 288 / 1024 ~ 8.5 KB. And after a month, the log file is around 8.5 KB * 30 = 255 KB, which is very small.

This log file is a text file. It's not too difficult to read but it's not easy either because there are no graphics like charts. However, when scanning this file, you will easily find out the times when your server load is high and what the load level is. Based on that information, you can decide whether to upgrade the server or not.

🔥 HOT: Interested in boosting your WordPress SEO? My Slim SEO plugin is a super lighweight and automated plugin that handles most the hard work for you: meta tags, sitemap, redirection, schema & link building.

👉 Have a look and you will love it: wpslimseo.com

PS: we'll drop lifetime pricing from Dec 01, 2024. Get it now before it's gone!

Leave a Reply

Your email address will not be published. Required fields are marked *


Copyright © 2024 Deluxe Blog Tips. All rights reserved.

My products: Meta Box | Slim SEO