Simple, self-contained PHP script to record server load and display results in a chart.
This script is used for tracking the server load figures. Only works on Linux servers.
It is run in 2 ways:
-
As a cron task that records the server load figures every X mins
-
When run in browser, it displays the results in a chart
-
Create a new database on remote web host
-
Create a new database user
-
Add both of these to the configuration section inside
server-load.php
-
Create an empty database table with the script below:
CREATE TABLE `server_load_monitor` ( `id` int(11) NOT NULL AUTO_INCREMENT, `timestamp` datetime NOT NULL, `load1` float(6,2) NOT NULL, `load5` float(6,2) NOT NULL, `load15` float(6,2) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB
-
Determine how many CPU cores your server has and update the line that says:
$NUMBER_OF_CORES = 16;
-
Upload
server-load.php
to remote web space -
Run the following URL (twice) in browser to begin to store some data (you can check to ensure it's being saved in DB correctly)
http://_________/server-load/server-load.php?savetodb=1
-
Load the following URL in browser to display the chart and confirm chart is working
http://_________/server-load/server-load.php
-
Setup cron job running every 5 mins (or however long you prefer) that runs this command to record load figures:
curl --silent --show-error http://_________/server-load/server-load.php?savetodb=1
Open source. Free MIT licence.