Monitor / View Log Files via Browser
I’ve a client that runs a special program on about 100 servers. This program writes a log to a central server every 3 minutes. So, when I checked the main server, I have a directory Logs (C:\Logs). Log’s directory contains many log files (each log for each server). We’ve installed a web server on our main server, Apache ;). So, I’d like to show a small AppsRuns.php file, which stored on web server. If we go to the http://server1/AppsRuns.php we will see a content of each log file on one web page. This web page refreshing every 10 sec. Here is a content of AppsRuns.php file:
<?php
$refresh_time = 10; // seconds
$path = "C:\LOGS";
header("Content-Type: text/plain");
header("Refresh: $refresh_time");
if($handle = opendir($path)) {
while (false !== ($file = readdir($handle))) {
$pi = pathinfo($path . '/' . $file);
if($pi['extension'] === 'txt') {
include($path . '/' . $file);
}
}
}
?>