231 lines
7.5 KiB
HTML
231 lines
7.5 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Service Outage Tracker</title>
|
|
<style>
|
|
/*
|
|
* ----------------------------------------
|
|
* CSS STYLING (Same as before)
|
|
* ----------------------------------------
|
|
*/
|
|
body {
|
|
font-family: Arial, sans-serif;
|
|
margin: 0;
|
|
padding: 0;
|
|
background-color: #f4f4f9;
|
|
color: #333;
|
|
}
|
|
|
|
header {
|
|
background-color: #007bff;
|
|
color: white;
|
|
padding: 20px 0;
|
|
text-align: center;
|
|
margin-bottom: 20px;
|
|
}
|
|
|
|
header h1 {
|
|
margin: 0;
|
|
}
|
|
|
|
#outage-tracker {
|
|
display: flex;
|
|
gap: 25px;
|
|
flex-wrap: wrap;
|
|
justify-content: center;
|
|
padding: 0 20px;
|
|
}
|
|
|
|
.service-card {
|
|
background-color: white;
|
|
border: 2px solid #ddd;
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
width: 300px;
|
|
text-align: center;
|
|
transition: transform 0.2s, box-shadow 0.2s;
|
|
}
|
|
|
|
.service-card:hover {
|
|
transform: translateY(-5px);
|
|
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
|
}
|
|
|
|
.service-card h2 {
|
|
margin-top: 0;
|
|
color: #007bff;
|
|
font-size: 1.6em;
|
|
border-bottom: 1px solid #eee;
|
|
padding-bottom: 10px;
|
|
margin-bottom: 15px;
|
|
}
|
|
|
|
.time-label {
|
|
font-size: 0.9em;
|
|
color: #666;
|
|
display: block;
|
|
margin-bottom: 5px;
|
|
}
|
|
|
|
.time-display {
|
|
font-size: 2em;
|
|
font-weight: bold;
|
|
color: #28a745; /* Green for "good" status */
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>⏰ Uptime Since Last Outage Tracker</h1>
|
|
<p>These services are widely considered "important" so...</p>
|
|
</header>
|
|
|
|
<main id="outage-tracker">
|
|
<p id="loading-message">Fetching data from outages.csv...</p>
|
|
<p id="error-message" style="color: red; display: none;"></p>
|
|
</main>
|
|
|
|
<script>
|
|
/*
|
|
* ----------------------------------------
|
|
* JAVASCRIPT LOGIC
|
|
* ----------------------------------------
|
|
*/
|
|
|
|
const CSV_URL = './outages.csv'; // Relative path to your CSV file
|
|
let services = []; // This will hold the parsed service data
|
|
|
|
/**
|
|
* Simple CSV parser for the "service,time" format.
|
|
* Time is expected to be in milliseconds since epoch.
|
|
* @param {string} csvText - The raw content of the CSV file.
|
|
* @returns {Array} - Array of service objects.
|
|
*/
|
|
function parseCSV(csvText) {
|
|
const lines = csvText.trim().split('\n');
|
|
// Skip the header line (service,time)
|
|
lines.shift();
|
|
|
|
const parsedData = lines.map(line => {
|
|
// Use a simple split by comma
|
|
const [serviceName, timestampStr] = line.split(',');
|
|
|
|
// Ensure the service name is cleaned up and a valid timestamp exists
|
|
if (serviceName && timestampStr && !isNaN(Number(timestampStr))) {
|
|
return {
|
|
name: serviceName.trim(),
|
|
// Convert the string to a number (timestamp in milliseconds)
|
|
lastOutageTimestamp: Number(timestampStr.trim()),
|
|
status: "online" // Default status
|
|
};
|
|
}
|
|
return null;
|
|
}).filter(item => item !== null); // Remove any null (invalid) entries
|
|
|
|
return parsedData;
|
|
}
|
|
|
|
|
|
/**
|
|
* Fetches the CSV file, parses it, and populates the global 'services' array.
|
|
*/
|
|
async function fetchAndParseData() {
|
|
const errorMessage = document.getElementById('error-message');
|
|
errorMessage.style.display = 'none';
|
|
|
|
try {
|
|
const response = await fetch(CSV_URL);
|
|
|
|
if (!response.ok) {
|
|
throw new Error(`HTTP error! Status: ${response.status}`);
|
|
}
|
|
|
|
const csvText = await response.text();
|
|
|
|
services = parseCSV(csvText);
|
|
|
|
if (services.length === 0) {
|
|
throw new Error("CSV file loaded, but no valid service data was found.");
|
|
}
|
|
|
|
// Start the tracker display once data is ready
|
|
runTracker();
|
|
|
|
// Set the interval for updates
|
|
setInterval(runTracker, 1000);
|
|
|
|
} catch (error) {
|
|
// Display the error to the user
|
|
const loading = document.getElementById('loading-message');
|
|
if (loading) loading.style.display = 'none';
|
|
|
|
errorMessage.textContent = `Error fetching or parsing data: ${error.message}. Check if ${CSV_URL} exists and is correctly formatted.`;
|
|
errorMessage.style.display = 'block';
|
|
console.error("Tracker initialization failed:", error);
|
|
}
|
|
}
|
|
|
|
// --- Display Functions (Same as before) ---
|
|
|
|
function getTimeSinceOutage(timestamp) {
|
|
const now = new Date().getTime();
|
|
const difference = now - timestamp;
|
|
|
|
const totalSeconds = Math.floor(difference / 1000);
|
|
|
|
const seconds = totalSeconds % 60;
|
|
const minutes = Math.floor(totalSeconds / 60) % 60;
|
|
const hours = Math.floor(totalSeconds / (60 * 60)) % 24;
|
|
const days = Math.floor(totalSeconds / (24 * 60 * 60));
|
|
|
|
const d = `${days}d`;
|
|
const h = `${hours.toString().padStart(2, '0')}h`;
|
|
const m = `${minutes.toString().padStart(2, '0')}m`;
|
|
const s = `${seconds.toString().padStart(2, '0')}s`;
|
|
|
|
return `${d} ${h} ${m} ${s}`;
|
|
}
|
|
|
|
function updateServiceDisplay(service) {
|
|
const container = document.getElementById('outage-tracker');
|
|
const serviceId = `service-${service.name.toLowerCase().replace(/\s/g, '-')}`;
|
|
|
|
const timeSince = getTimeSinceOutage(service.lastOutageTimestamp);
|
|
|
|
let card = document.getElementById(serviceId);
|
|
|
|
if (!card) {
|
|
card = document.createElement('div');
|
|
card.id = serviceId;
|
|
card.classList.add('service-card', service.status);
|
|
|
|
card.innerHTML = `
|
|
<h2>${service.name}</h2>
|
|
<span class="time-label">Time Since Last Outage:</span>
|
|
<div class="time-display">${timeSince}</div>
|
|
`;
|
|
container.appendChild(card);
|
|
} else {
|
|
card.querySelector('.time-display').textContent = timeSince;
|
|
}
|
|
}
|
|
|
|
function runTracker() {
|
|
// Remove loading message after the first successful run
|
|
const loading = document.getElementById('loading-message');
|
|
if (loading) loading.remove();
|
|
|
|
services.forEach(updateServiceDisplay);
|
|
}
|
|
|
|
// Start the process: Fetch the data, then start the tracker
|
|
fetchAndParseData();
|
|
|
|
</script>
|
|
</body>
|
|
</html>
|