Merge pull request #55 from Newtbot/update

update with server info
This commit is contained in:
noot 2024-01-27 16:04:14 +08:00 committed by GitHub
commit ec1dbfee44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 105 additions and 4 deletions

View File

@ -6,6 +6,7 @@ const bcrypt = require("bcrypt");
const crypto = require("crypto");
const validator = require('validator');
const axios = require('axios');
const pidusage = require('pidusage');
const { validationResult } = require('express-validator');
const { locationValidation, locationValidationUpdate, locationdeleteValidation
@ -197,17 +198,28 @@ app.post("/verify-otp", otpValidation ,async (req, res) => {
}
// Redirect to the login page after logout
res.redirect("/login");
res.redirect("/index");
});
} catch (error) {
console.error("Error in logout route:", error);
res.status(500).send("Internal Server Error");
}
});
const getSystemHealth = async () => {
const cpuInfo = await pidusage(process.pid);
return {
serverStatus: { uptime: process.uptime() },
databaseStatus: { connected: true }, // Replace with actual logic
resourceUtilization: {
cpuUsage: cpuInfo.cpu,
memoryUsage: process.memoryUsage(),
},
networkHealth: { latency: 10 }, // Replace with actual logic
};
};
app.get("/home", isAuthenticated, async (req, res) => {
res.render("home", { username: req.session.username});
const systemHealth = await getSystemHealth();
res.render("home", { username: req.session.username, systemHealth});
});
app.get("/inusers", isAuthenticated, async (req, res) => {

View File

@ -28,9 +28,46 @@
<main>
<h2>Welcome to the Home Page, <%= username %>!</h2>
</main>
<section>
<div class="health-container">
<h4>Server Uptime</h4>
<ul>
<li><strong>Uptime:</strong> <span id="serverUptime"><%= systemHealth && systemHealth.serverStatus ? (systemHealth.serverStatus.uptime / 60).toFixed(2) : 'N/A' %> minutes</span></li>
</ul>
</div>
<div class="health-container">
<h4>Database Status</h4>
<ul>
<li><strong>Status:</strong> <%= systemHealth && systemHealth.databaseStatus ? (systemHealth.databaseStatus.connected ? 'Connected' : 'Disconnected') : 'N/A' %></li>
</ul>
</div>
<div class="health-container">
<h4>CPU Usage</h4>
<ul>
<li><strong>Usage:</strong> <span id="cpuUsage"><%= systemHealth && systemHealth.resourceUtilization ? systemHealth.resourceUtilization.cpuUsage.toFixed(2) : 'N/A' %> %</span></li>
</ul>
</div>
<div class="health-container">
<h4>Memory Usage</h4>
<ul>
<li><strong>Usage:</strong> <%= systemHealth && systemHealth.resourceUtilization ? (systemHealth.resourceUtilization.memoryUsage.rss / (1024 * 1024)).toFixed(2) : 'N/A' %> MB</li>
</ul>
</div>
<div class="health-container">
<h4>Network Latency</h4>
<ul>
<li><strong>Latency:</strong> <%= systemHealth && systemHealth.networkHealth ? systemHealth.networkHealth.latency : 'N/A' %> ms</li>
</ul>
</div>
</section>
<footer>
Any Issue faced, Please contact the administrator at 11111111 or ecosaverAdmin@gmail.com
</footer>
</body>
</html>

View File

@ -635,4 +635,41 @@ footer {
/* Add any other specific styles for this form */
.custom-location-form h3 {
color: #333; /* Customize the heading color */
}
section {
margin-top: 20px;
display: flex; /* Use flexbox to arrange items in a row */
justify-content: space-between; /* Distribute items evenly along the main axis */
}
.health-container {
width: 200px; /* Set a fixed width for square shape */
height: 200px; /* Set a fixed height for square shape */
background-color: #f0f0f0; /* Background color */
border: 1px solid #ddd;
padding: 10px;
border-radius: 10px; /* Rounded corners */
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1); /* Box shadow for depth */
transition: transform 0.3s ease-in-out; /* Add a subtle transition effect */
}
.health-container:hover {
transform: scale(1.05); /* Scale up on hover */
}
.health-container h4 {
text-align: center;
color: #333; /* Heading color */
}
.health-container ul {
list-style: none;
margin: 0;
padding: 0;
text-align: center;
}
.health-container li {
margin: 5px 0;
color: #555; /* Text color */
}

13
package-lock.json generated
View File

@ -2100,6 +2100,11 @@
"wrappy": "1"
}
},
"os": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/os/-/os-0.1.2.tgz",
"integrity": "sha512-ZoXJkvAnljwvc56MbvhtKVWmSkzV712k42Is2mA0+0KTSRakq5XXuXpjZjgAt9ctzl51ojhQWakQQpmOvXWfjQ=="
},
"otp-generator": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/otp-generator/-/otp-generator-4.0.1.tgz",
@ -2203,6 +2208,14 @@
"integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==",
"dev": true
},
"pidusage": {
"version": "3.0.2",
"resolved": "https://registry.npmjs.org/pidusage/-/pidusage-3.0.2.tgz",
"integrity": "sha512-g0VU+y08pKw5M8EZ2rIGiEBaB8wrQMjYGFfW2QVIfyT8V+fq8YFLkvlz4bz5ljvFDJYNFCWT3PWqcRr2FKO81w==",
"requires": {
"safe-buffer": "^5.2.1"
}
},
"pngjs": {
"version": "5.0.0",
"resolved": "https://registry.npmjs.org/pngjs/-/pngjs-5.0.0.tgz",

View File

@ -38,8 +38,10 @@
"mysql2": "^3.7.1",
"node-fetch": "^3.3.2",
"nodemailer": "^6.9.8",
"os": "^0.1.2",
"otp-generator": "^4.0.1",
"otplib": "^12.0.1",
"pidusage": "^3.0.2",
"qrcode": "^1.5.3",
"sanitize-html": "^2.11.0",
"sequelize": "^6.35.2",