Console program that tails a csv-encoded HTTP access log.
- Prints out summary statistics every 10 seconds.
- An alert message is printed when average traffic in the last two minutes exceeds a threshold.
- A message is printed when traffic drops below the threshold.
- Create a virtual environment and activate it.
- Install dependencies.
pip install -r requirements.txt
This repository follows pep8 with the exception max line length.
pycodestyle . --max-line-length=120
python -m unittest tests.py
Run the program from the terminal.
PYTHONUNBUFFERED=1 python main.py path/to/file.csv
-t
--threshold
- Requests per second considered to be high traffic.-i
--log_interval
- Number of seconds to collect logs before printing a summary.-w
--log_window
- Number of seconds to look back when checking for high traffic.
- When the end of the file has been reached it does not print a summary of any logs that it might have read before hitting the end of the file.
- When using a Windows machine the colors might not print properly.
- Add better error handling. Currently the program expects the information in the csv to be formatted like the sample csv and will raise an exception if the input deviates.
- Real log files are continuously growing. This program needs to be updated to wait for more logs to be written when it reaches the end of the log file.
- Add more unit tests.
- In a production scenario, the monitor would be started in the background and the results would only be checked occasionally indirectly.
- Instead of printing to the terminal, it should print to a more permanent store so a web interface can display the information.
- Graph of the number of requests per second over time.
- A count of the number of 500 errors.
- This program needs to be able to monitor multiple logs from multiple servers.
- For production logging, occasionally the log files get rotated. This program needs a way to detect this and open the new file.