Monitoring CPU Usage with cpu.cgi on a Multi-Processor Linux Server
As a system administrator, it’s essential to monitor the performance of your server to ensure that it’s running efficiently and effectively. One crucial aspect of server performance is CPU usage, as high CPU usage can lead to slow response times, increased errors, and decreased productivity. In this blog post, we’ll explore how to use the cpu.cgi script to monitor CPU usage on a multi-processor Linux server.
What is cpu.cgi?
cpu.cgi is a cgi (Common Gateway Interface) script that allows you to view the current CPU usage of your Linux server in real-time. The script uses the mpstat command to gather data on the CPU usage and displays it in an easy-to-read format.
Prerequisites
Before we dive into the installation and use of cpu.cgi, there are a few prerequisites you need to be aware of:
1. Linux server with a cgi-capable webserver installed and running (e.g., Apache).
2. sh shell installed on the server.
3. mpstat command installed on the server. The latter is part of the sysstat package, so it can be installed on Centos/Fedora/RedHat systems with the command:
“`
sudo yum install sysstat
“`
Installing cpu.cgi
To install cpu.cgi on your Linux server, follow these steps:
1. Using your favorite editor, open a new text file called cpu.cgi in the cgi-bin folder on your server (e.g., /var/www/cgi-bin/cpu.cgi).
2. Copy and paste the following code into the file:
“`css
#!/usr/local/bin/sh
# Define the CPU usage command
mpstat -a 1 5 30
# Define the echo statement
echo “$ mpstat -a 1 5 30”
“`
Be aware that the line starting with mpstat is quite long, so be careful not to chop it up when copying and pasting.
3. Make the script executable:
“`bash
chmod +x cpu.cgi
“`
Now that the script is installed, let’s explore how to use it to monitor CPU usage on your multi-processor Linux server.
Using cpu.cgi
To view the current CPU usage of your server, simply point your web browser at the following URL:
“`http://myserver/cgi-bin/cpu.cgi“`
Replace myserver with the hostname or IP address of your server.
When you access the URL, you’ll see a simple page with a list of CPU usage statistics for each processor on your server. The statistics are updated in real-time and display the following information:
1. CPU usage for each processor (%).
2. System load average (1m, 5m, 15m).
3. Number of processes running on each processor.
Benefits of Using cpu.cgi
There are several benefits to using cpu.cgi to monitor your server’s CPU usage:
1. Easy to use: The script is straightforward to install and use, making it an excellent choice for system administrators who want a simple solution for monitoring CPU usage.
2. Real-time updates: The script provides real-time updates of CPU usage, allowing you to quickly identify any performance issues on your server.
3. Multi-processor support: cpu.cgi supports multi-processor servers, making it an excellent choice for large servers with multiple processors.
4. Customizable: You can customize the script to fit your needs by modifying the mpstat command and other settings.
Conclusion
In this blog post, we’ve explored how to use the cpu.cgi script to monitor CPU usage on a multi-processor Linux server. We’ve covered the installation and use of the script, as well as its benefits and features. By using cpu.cgi, you can quickly and easily check the load on your system and see if multi-processor applications are spreading themselves across the available cores. With this information, you can make informed decisions about server performance and capacity planning.