- Created a GitHub Actions workflow for CI/CD to deploy to Ghyamah, including testing, building, and pushing Docker images. - Added architecture design document for handling 15,000 requests per second, detailing system components, capacity planning, and cold start strategies. - Introduced a Python-based uptime/latency/SSL monitor with a static dashboard, utilizing standard libraries only. - Included Dockerfile and entrypoint script for the monitoring application, ensuring it runs as a non-root user and handles process management. - Added a .dockerignore file to exclude unnecessary files from the Docker build context. - Created an HTML dashboard for visualizing monitoring metrics, including uptime, latency, and SSL certificate status.
35 أسطر
746 B
JavaScript
35 أسطر
746 B
JavaScript
const express = require('express');
|
|
const cors = require('cors');
|
|
const app = express();
|
|
|
|
app.use(cors());
|
|
|
|
let requestCount = 0;
|
|
let lastResponseTime = 0;
|
|
|
|
app.use((req, res, next) => {
|
|
requestCount++;
|
|
const start = Date.now();
|
|
res.on('finish', () => {
|
|
lastResponseTime = Date.now() - start;
|
|
});
|
|
next();
|
|
});
|
|
|
|
app.get('/health', (req, res) => {
|
|
res.json({
|
|
status: 'Online',
|
|
uptime_seconds: process.uptime(),
|
|
request_count: requestCount,
|
|
response_time_ms: lastResponseTime
|
|
});
|
|
});
|
|
|
|
app.get('/', (req, res) => {
|
|
res.send('Welcome to the Backend API!');
|
|
});
|
|
|
|
const PORT = process.env.PORT || 3000;
|
|
app.listen(PORT, () => {
|
|
console.log(`API is running on port ${PORT}`);
|
|
}); |