This utility monitors website availability over the network, produces metrics about this and passes these events through an Aiven Kafka instance into an Aiven PostgreSQL database. It is implemented in python, and it runs on 2 different docker containers.
Following metrics parameters are being fetched and stored in PostgreSQL database in monitoring table:
- url: Website under monitoring
- timestamp: Date time present in response header
- status code: Response code
- reason: Response message
- response time: Response time
- regex pattern matched: site data validation by regex
- Python 3.9
- kafka-python 2.0.2
- requests 2.25.1
- psycopg2-binary 2.8.6
- pytest 6.2.2
- pytest-html-reporter 0.2.3
- apscheduler 3.7.0
- PyCharm or any other desired IDE
Kindly make sure
- Aiven Kafka & PostgreSQL services should be running
- Topic should be created as 'monitor'
-
Clone project
-
Navigate to root folder 'monitoring'
-
Install all required dependencies mentioned in requirements.txt using command
pip install -r requirements.txt
-
Copy your ca.pem, service.cert, service.key into certs folder
-
Update config.ini file present in resources folder with server details
-
Run this utility(check topic 'monitor' should be present)
-
Either via docker-compose.yml file.
docker-compose up
-
Or via command, to run both producer & consumer services.
python services/kafka_producer/producer_runner.py
python services/kafka_consumer/consumer_runner.py
-
-
To execute test scripts
pytest -s -v -l
Pytest html report is generated in root folder as pytest_html_report.html
- Add more parameters in the metrics.
- Implement proper way to shutdown producer/consumer running scheduler job.
- Implement CI.
- Better test coverage.
- Improve Error Handling.