File Upload
						commit
						d97f2ae7b4
					
				| 
						 | 
				
			
			@ -0,0 +1,8 @@
 | 
			
		|||
{
 | 
			
		||||
  "dependencies": {
 | 
			
		||||
    "diskusage": "^1.1.3",
 | 
			
		||||
    "express": "^4.18.2",
 | 
			
		||||
    "pm2": "^5.2.2",
 | 
			
		||||
    "systeminformation": "^5.17.1"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,54 @@
 | 
			
		|||
const express = require('express');
 | 
			
		||||
const os = require('os');
 | 
			
		||||
const app = express();
 | 
			
		||||
const diskusage = require('diskusage');
 | 
			
		||||
const si = require('systeminformation');
 | 
			
		||||
const hostname = "localhost";
 | 
			
		||||
const port = "3001";
 | 
			
		||||
 | 
			
		||||
async function getNetworkStats() {
 | 
			
		||||
  try {
 | 
			
		||||
    const data = await si.networkStats("eno1");
 | 
			
		||||
    return data;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.error(error);
 | 
			
		||||
    return {};
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
async function getCurrentCPULoad() {
 | 
			
		||||
  try {
 | 
			
		||||
    const data = await si.currentLoad();
 | 
			
		||||
    const { currentLoad } = data;
 | 
			
		||||
    return currentLoad;
 | 
			
		||||
  } catch (error) {
 | 
			
		||||
    console.log(error);
 | 
			
		||||
    return {};
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
app.get('/server-stats/', (req, res) => {
 | 
			
		||||
    const cpuServer = os.cpus()[0].model;
 | 
			
		||||
    const totalRam = (os.totalmem() / 1024 ** 3);
 | 
			
		||||
    const ramUsage = (os.totalmem() - os.freemem()) / os.totalmem();
 | 
			
		||||
    diskusage.check('/', async (err, result) => {
 | 
			
		||||
        const totalHddSpace = (result.total / 1024 ** 3);
 | 
			
		||||
        const freeHddSpace = (result.available / 1024 ** 3);
 | 
			
		||||
	const networkStats = await getNetworkStats();
 | 
			
		||||
	const cpuUsage = await getCurrentCPULoad();
 | 
			
		||||
        res.json({
 | 
			
		||||
            cpuServer,
 | 
			
		||||
            cpuUsage,
 | 
			
		||||
            ramUsage,
 | 
			
		||||
            totalRam,
 | 
			
		||||
            totalHddSpace,
 | 
			
		||||
            freeHddSpace,
 | 
			
		||||
	    networkStats
 | 
			
		||||
        });
 | 
			
		||||
    });
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
app.listen(port, hostname, () => {
 | 
			
		||||
    console.log(`Server running at http://${hostname}:${port}/`);
 | 
			
		||||
})
 | 
			
		||||
		Loading…
	
		Reference in New Issue