PyWebStatMon is a simple website status monitor, written in Python.
The main goals for this small tool are:
- Have a simple configuration for defining URLs, and their monitoring requirements
- Make periodic requests to all configured pages to confirm their status
- Verifies that the response matches the requirements (e.g. a specified string is found)
- Measures the response times for the web pages
- Writes everything in a log
- Provides the status information on a simple web interface
The tool should work with Python 2.6, 2.7 and 3.3. With 3.2 there's some odd issues with requirements.
If the above is true, this should be green:
It logs to a file and to console, and has a simple WebUI for viewing the status.
Just get the code, and run "pip install -r requirements.txt". Simple enough, should work on pretty much any platform, let me know if it doesn't. The tool has been confirmed to work with Windows and Linux.
I recommend you set up a Python virtualenv for PyWebStatMon to avoid conflicts with your global Python environment.
Example installation:
git clone https://github.com/lietu/pywebstatmon
cd pywebstatmon
pip install -r requirements.txt
The configuration file, config.yaml
, uses a simple YAML syntax, it should be pretty self-explanatory, but
if you need more information on the YAML syntax, please visit http://www.yaml.org/.
Check out config.example.yaml for a full example.
The syntax for the config is as follows:
monitors:
url:
poll_seconds: 60
content:
- Some text that must be found on the page
- Some other text.
Please note that the "-" and the ":" -characters have a special meaning on YAML and need to be there. The example above e.g. searches for "Some other text." and not "- Some other text." on the page.
So for example, to validate that "http://www.example.com/login" has the text "Please login.", you could use the following configuration:
monitors:
http://www.example.com/login:
poll_seconds: 60
content:
- Please login.
You can define the interval between checks with "poll_seconds". Just set it to the number of seconds between checks. The "content" -section is completely optional.
You can define the port the web server listens to with the "http_port" -option. If not set, no web interface will be provided. Log will be written to the file defined with "log_file", if set. If not set, no logging will be done.
The log will ALWAYS be written to STDOUT, if you do not like this, redirect it to /dev/null.
First of all, make sure you edit the configuration file as instructed above.
Then, in the directory with the code, run:
python pywebstatmon.py
You can of course run this with supervisor or similar, when you have finished testing out the configuration.
If you want to override the polling period globally for temporary testing purposes, you can use the argument "--poll_seconds=X" where X is the number of seconds you want to set it to.
For more help, try python pywebstatmon.py --help
.
Getting started with testing the system is fairly easy.
- Install Vagrant and VirtualBox
- Make sure you have a clone of the repository
- In the repository root, run
vagrant up
and wait for the machine to be up and running. - Run
vagrant ssh
to get into your new virtual development environment (orvagrant ssh-config
to show SSH settings) The user and pass are both "vagrant" btw. - The source code should be in /src
- Make sure your changes pass the tests before trying to send a pull request:
python -m nose
- Make sure your code conforms to PEP-8 and PyFlakes doesn't complain of anything.
Hint, try out Flake8 or my small script for monitoring PEP-8 and pyflakes compliancy
It will also open up the port 8000 on your workstation and forward it to the VM's port 8000.
The project uses Flask to provide the simple web interface. The frontend uses Twitter Bootstrap, jQuery, EJS and some other things from Initializr.
Be aware that this project relies completely on the Flask web server that shouldn't really be used as the only web server if you expect more than just a little traffic on the site. It should do for most basic uses, but the application really isn't made for big installations in it's current form.
The code is distributed with the very free new BSD and MIT licenses. More information in LICENSE.md -file.
The included libraries and dependencies have their own licenses.
This project has been made possible thanks to Cocreators and Lietu. You can help us continue our open source work by supporting us on Buy me a coffee.