This application processes system logs to track job execution times and generate alerts if processing times exceed defined thresholds. Implemented by Mithun Wijethunga
The output file is specified using --output argument (default: output.log). Added in the repository root directory.
- Batch Mode: Reads the entire log file once and produces a report.
- Stream Mode (Real-Time): Monitors the log file continuously for new entries and updates the report dynamically.
- Configurable thresholds via
config.json:warning_threshold_secondserror_threshold_seconds
- Alerts:
- OK → Job completed within warning threshold.
- WARNING → Job exceeded warning threshold.
- ERROR → Job exceeded error threshold.
- Handles malformed lines, invalid timestamps, and missing START/END gracefully.
- Includes:
- Unit Tests (logic validation)
- End-to-End Tests (full file processing)
- Dockerized for portability and includes CI/CD workflow for automated testing.
The application supports custom thresholds using a JSON config file:
{
"warning_threshold_seconds": 300,
"error_threshold_seconds": 600
}If no config is provided or it's invalid, defaults are:
- WARNING → 300 seconds (5 mins)
- ERROR → 600 seconds (10 mins)
python3 log_monitor.py --logfile logs.log --output output.log --mode batch --config config.json- Best for static log analysis.
- Reads the entire log file in one go and generates a summary report.
- Example:
python3 log_monitor.py --logfile logs.log --output output.log --mode batch- Best for live monitoring.
- Continuously watches the log file for changes using
watchdog. - Processes new log entries as they arrive and updates the report dynamically.
- Example:
python3 log_monitor.py --logfile logs.log --output output.log --mode stream- Each log line should follow this format:
TIME, JOB_DESCRIPTION, STATUS, PID
Example: 11:35:23,scheduled task 032, START,37980
- The application pairs
STARTandENDentries for the same PID to compute duration. - Generates a report showing:
PID: 37980 | Job: scheduled task 032 | Duration: 33s | Start: 11:35:23 | End: 11:35:56 | Status: OK
To run all tests:
python3 -m unittest discover testsBuild image:
docker build -t log-monitor .Run container:
docker run -v $(pwd):/app log-monitor- The included GitHub Actions workflow (
.github/workflows/ci.yml) automatically:- Installs dependencies
- Runs unit and integration tests
- Triggered on every push and pull request to the
mainbranch.