Building Network Monitoring with PHP Server Monitor

Publish: 2017-10-17 | Modify: 2021-01-03

PHP Server Monitor is a network monitoring tool developed using PHP. It is used to check if your website and servers are up and running properly. It provides a user-friendly web interface for easy management and viewing. It can automatically send email or SMS notifications when a server goes down.

Image

PHP Server Monitor supports monitoring of ping, tcping, and websites. It is recommended to install it on a VPS as it requires the use of crontab for scheduling tasks. To monitor the network changes of a foreign VPS, I installed PHP Server Monitor on my 占美小主机 and it provides a visual representation of the VPS network condition, which is very convenient.

Installation

Download from GitHub: https://github.com/phpservermon/phpservermon

Extract the downloaded files to the root directory of your website. Access http://yourdomain.com/install.php and follow the prompts to complete the installation. If you are unable to write to the configuration file, you can manually add the database information to config.php as follows:

# Copy the configuration file
cp config.php.sample config.php
# Edit the configuration file
vi config.php
# Fill in the database information
define('PSM_DB_PREFIX', 'monitor_'); # Table prefix, keep the default
define('PSM_DB_USER', 'status'); # Database user
define('PSM_DB_PASS', 'xxxxxxx'); # Database password
define('PSM_DB_NAME', 'status'); # Database username
define('PSM_DB_HOST', 'localhost'); # Database connection address
define('PSM_DB_PORT', '3306'); # Database connection port, usually default to 3306
define('PSM_BASE_URL', 'http://status.xiaoz.org'); # Website address

Official installation documentation: http://docs.phpservermonitor.org/en/latest/install.html

Adding Scheduled Tasks

After the website is installed, you need to add a collection task. Otherwise, data cannot be obtained. Taking Linux (CentOS) as an example, Linux generally uses crontab as the scheduling task. Here's how you can do it:

# Install crontab
yum -y install crontabs
# Add scheduled task
crontab -e
# Add the following content to the scheduled task, please modify the path according to your actual situation
*/5 * * * * /usr/local/php/bin/php /data/wwwroot/status.xiaoz.org/cron/status.cron.php
# Reload crontab
service crond reload
  • To find the PHP path: which php, and then replace /usr/local/php/bin/php with your PHP path.
  • status.cron.php is the address of the PHP Server Monitor script, please fill in the absolute path.
  • exec function needs to be enabled, otherwise ping will not work properly.

Setting Chinese Language

Yes, PHP Server Monitor supports multiple languages. You can change it to Chinese in the backend settings, as shown in the screenshot below. Adding monitors and SMTP settings are relatively simple, you can explore them on your own.

Image

Backend Screenshots

Image

Image

Image

Conclusion

PHP Server Monitor is easy to configure and has sufficient functionality. The code is open source and can be easily integrated or further developed. I installed PHP Server Monitor to monitor the network changes of foreign VPS and will send monitoring reports on a weekly or monthly basis. If you find that these features are not enough to meet your needs, you can try Smokeping, which is more powerful but a bit more complicated to configure.

Official website: http://www.phpservermonitor.org/


Comments