Here's how to run the dashboard on localhost using Create React App:
-
First, make sure you have Node.js installed (https://nodejs.org)
-
Create a new React app:
npx create-react-app uptime-dashboard
cd uptime-dashboard
- Replace the content of
src/App.js with:
import React from 'react';
import Dashboard from './Dashboard';
function App() {
return <Dashboard />;
}
export default App;
- Create a new file
src/Dashboard.js and paste the component code:
import React, { useState, useEffect } from 'react';
const Dashboard = () => {
const [services, setServices] = useState([]);
const [systemHealth, setSystemHealth] = useState({
uptime: '99.9%',
responseTime: '45ms',
status: 'Operational'
});
// Mock data initialization
useEffect(() => {
const mockServices = [
{ id: 1, name: 'API Server', status: 'up', uptime: '99.8%', responseTime: '120ms' },
{ id: 2, name: 'Database', status: 'up', uptime: '99.9%', responseTime: '15ms' },
{ id: 3, name: 'Cache Service', status: 'down', uptime: '98.2%', responseTime: 'N/A' },
{ id: 4, name: 'Auth Service', status: 'up', uptime: '99.5%', responseTime: '85ms' },
];
setServices(mockServices);
}, []);
const getStatusColor = (status) => {
return status === 'up' ? '#4CAF50' : '#F44336';
};
return (
<div style={styles.container}>
<header style={styles.header}>
<h1>System Uptime Dashboard</h1>
<div style={styles.refreshButton}>Last Updated: {new Date().toLocaleTimeString()}</div>
</header>
<div style={styles.summaryGrid}>
<div style={styles.summaryCard}>
<h3>System Uptime</h3>
<div style={styles.largeValue}>{systemHealth.uptime}</div>
</div>
<div style={styles.summaryCard}>
<h3>Avg. Response Time</h3>
<div style={styles.largeValue}>{systemHealth.responseTime}</div>
</div>
<div style={styles.summaryCard}>
<h3>System Status</h3>
<div style={{...styles.statusIndicator, color: '#4CAF50'}}>
● {systemHealth.status}
</div>
</div>
</div>
<div style={styles.servicesGrid}>
{services.map(service => (
<div key={service.id} style={styles.serviceCard}>
<div style={styles.serviceHeader}>
<span style={styles.serviceName}>{service.name}</span>
<span style={{...styles.statusDot, backgroundColor: getStatusColor(service.status)}}></span>
</div>
<div style={styles.serviceDetails}>
<div>Uptime: {service.uptime}</div>
<div>Response: {service.responseTime}</div>
</div>
</div>
))}
</div>
</div>
);
};
// Modern styling
const styles = {
container: {
fontFamily: 'Arial, sans-serif',
maxWidth: '1200px',
margin: '0 auto',
padding: '20px',
backgroundColor: '#f5f5f5',
},
header: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '30px',
paddingBottom: '15px',
borderBottom: '1px solid #ddd',
},
summaryGrid: {
display: 'grid',
gridTemplateColumns: 'repeat(3, 1fr)',
gap: '20px',
marginBottom: '30px',
},
summaryCard: {
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
textAlign: 'center',
},
largeValue: {
fontSize: '24px',
fontWeight: 'bold',
color: '#333',
},
servicesGrid: {
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(250px, 1fr))',
gap: '15px',
},
serviceCard: {
backgroundColor: 'white',
padding: '15px',
borderRadius: '8px',
boxShadow: '0 2px 4px rgba(0,0,0,0.1)',
},
serviceHeader: {
display: 'flex',
justifyContent: 'space-between',
alignItems: 'center',
marginBottom: '10px',
},
serviceName: {
fontWeight: 'bold',
fontSize: '16px',
},
statusDot: {
width: '12px',
height: '12px',
borderRadius: '50%',
display: 'inline-block',
},
statusIndicator: {
display: 'flex',
alignItems: 'center',
gap: '5px',
fontWeight: 'bold',
},
refreshButton: {
backgroundColor: '#2196F3',
color: 'white',
padding: '8px 16px',
borderRadius: '4px',
cursor: 'pointer',
},
};
export default Dashboard;