This project provides a Server-Sent Events (SSE) implementation to stream Apache access logs in real-time to a web client for visualization. The backend is written in PHP and monitors an Apache log file, parsing and streaming all log entries to the client.

- Real-time streaming of Apache access logs using Server-Sent Events (SSE).
sse.phpparses log entries to extract meaningful data (e.g., method, URL, status code, size, timestamp).tail_log.shmonitors thetail -fprocess for excessive CPU usage and terminates it if a threshold is breached, reporting an error.
sse.php: The PHP script that handles log file monitoring and streams parsed log entries to the client via SSE.tail_log.sh: A bash script executed bysse.phpto tail the Apache log file. It includes CPU usage monitoring for thetailprocess.index.html: The frontend HTML file (currently empty) intended to display the streamed log data.
- Read permissions for the Apache log file (
/var/log/apache2/other_vhosts_access.log) on the local server. bashinterpreter available on the server.- Standard Unix utilities
ps,awk,tail,kill(used bytail_log.sh).
- The client (
index.html) connects tosse.phpto initiate a Server-Sent Events (SSE) stream. sse.phpexecutestail_log.sh.tail_log.shperforms the following:- Verifies read access to the Apache log file (configurable via
LOG_FILE). - Starts
tail -fon the log file, outputting new lines. - Monitors the CPU usage of the
tail -fprocess. IfCPU_THRESHOLDis exceeded, it terminatestail -fand outputs an error.
- Verifies read access to the Apache log file (configurable via
sse.phpreads output fromtail_log.sh:- Lines starting with "Error: " are sent to the client as SSE error events.
- Other lines are parsed as Apache log entries.
- Successfully parsed log entries are converted to JSON and streamed to the client via SSE.
index.htmlreceives and visualizes these SSE events (log data or errors).
The tail_log.sh script contains the following configurable variables at the top of the file:
LOG_FILE: Path to the Apache access log file (default:"/var/log/apache2/other_vhosts_access.log").CPU_THRESHOLD: CPU usage percentage (integer) above which thetail -fprocess will be terminated (default:50).CHECK_INTERVAL: Interval in seconds at which CPU usage is checked (default:10).
The sse.php script parses lines from tail_log.sh (which outputs lines from the Apache log file) if they are not error messages. Each successfully parsed log entry is transformed into a JSON object with the following fields:
id: Unique identifier for the log entry.method: HTTP method (e.g., GET, POST).url: Requested URL (without query parameters).status: HTTP status code (e.g., 200, 404).size: Response size in bytes.timestamp: Unix timestamp of the log entry.
- Ensure the Apache log file (specified by
LOG_FILEintail_log.sh) is readable by the user executing the PHP script (e.g.,www-data). For default log locations, you might need to add the PHP user to a group likeadm:
sudo usermod -a -G adm www-data