Files
harbor-ci-cd-demo/src/routes/health.js
stephenminakian daf3dbe0ef
Some checks failed
CI/CD Pipeline - Build, Test, and Deploy / 🧪 Test & Lint (push) Failing after 5m24s
CI/CD Pipeline - Build, Test, and Deploy / 🔒 Security Scan (push) Successful in 10m1s
CI/CD Pipeline - Build, Test, and Deploy / 🏗️ Build & Push Image (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🛡️ Image Security Scan (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🚀 Deploy to Development (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🏭 Deploy to Production (push) Has been skipped
CI/CD Pipeline - Build, Test, and Deploy / 🧹 Cleanup (push) Successful in 1s
Add System Monitoring Dashboard with Harbor CI/CD integration
2025-07-02 15:03:15 -06:00

93 lines
2.7 KiB
JavaScript

const express = require('express');
const os = require('os');
const router = express.Router();
// Basic health check
router.get('/', (req, res) => {
res.json({
status: 'healthy',
timestamp: new Date().toISOString(),
uptime: process.uptime(),
service: 'harbor-ci-cd-demo'
});
});
// Detailed health check
router.get('/detailed', (req, res) => {
const memoryUsage = process.memoryUsage();
const totalMem = os.totalmem();
const freeMem = os.freemem();
// Check memory usage (warn if over 80%)
const memoryPercentage = ((totalMem - freeMem) / totalMem) * 100;
const memoryStatus = memoryPercentage > 80 ? 'warning' : 'healthy';
// Check process memory (warn if heap over 100MB)
const heapUsedMB = memoryUsage.heapUsed / 1024 / 1024;
const processMemoryStatus = heapUsedMB > 100 ? 'warning' : 'healthy';
// Overall status
const overallStatus = (memoryStatus === 'warning' || processMemoryStatus === 'warning')
? 'warning'
: 'healthy';
res.json({
status: overallStatus,
timestamp: new Date().toISOString(),
service: 'harbor-ci-cd-demo',
version: process.env.npm_package_version || '1.0.0',
uptime: {
process: Math.round(process.uptime()),
system: Math.round(os.uptime())
},
memory: {
status: memoryStatus,
system: {
total: Math.round(totalMem / 1024 / 1024 / 1024 * 100) / 100,
used: Math.round((totalMem - freeMem) / 1024 / 1024 / 1024 * 100) / 100,
percentage: Math.round(memoryPercentage)
},
process: {
status: processMemoryStatus,
heapUsed: Math.round(heapUsedMB),
heapTotal: Math.round(memoryUsage.heapTotal / 1024 / 1024),
rss: Math.round(memoryUsage.rss / 1024 / 1024)
}
},
loadAverage: os.loadavg().map(load => Math.round(load * 100) / 100),
environment: process.env.NODE_ENV || 'development'
});
});
// Readiness probe (for Kubernetes-style deployments)
router.get('/ready', (req, res) => {
// Check if the application is ready to serve traffic
// In a real app, you might check database connections, external services, etc.
const isReady = true; // Simplified check
if (isReady) {
res.json({
status: 'ready',
timestamp: new Date().toISOString()
});
} else {
res.status(503).json({
status: 'not ready',
timestamp: new Date().toISOString()
});
}
});
// Liveness probe (for Kubernetes-style deployments)
router.get('/live', (req, res) => {
// Check if the application is alive and should not be restarted
res.json({
status: 'alive',
timestamp: new Date().toISOString(),
uptime: process.uptime()
});
});
module.exports = router;