revert 6f637968bdd5dea7f472e5a07517e072ed69715e
All checks were successful
Neutral/pipeline/head This commit looks good
All checks were successful
Neutral/pipeline/head This commit looks good
revert Version 1.0.0 - Basic Web Application
This commit is contained in:
74
bin/server-metrics.js
Normal file
74
bin/server-metrics.js
Normal file
@ -0,0 +1,74 @@
|
||||
const { LogType } = require("loguix")
|
||||
const fs = require("fs")
|
||||
const path = require("path")
|
||||
const { __glob } = require("./global-variables")
|
||||
const clog = new LogType("Serveur Metrics")
|
||||
const osutils = require("os-utils")
|
||||
const os = require("os")
|
||||
const { statfs } = require("fs")
|
||||
const config = require("./config")
|
||||
|
||||
|
||||
|
||||
module.exports.getMetrics = async function(server) {
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
if(server == "Alpha") {
|
||||
var resp = "NULL"
|
||||
const space = statfs("/", (err, stats) => {
|
||||
if (err) {
|
||||
throw err
|
||||
}
|
||||
|
||||
|
||||
|
||||
osutils.cpuUsage(function(cpuUsage) {
|
||||
resp = {
|
||||
cpu: Math.round(cpuUsage * 1000),
|
||||
usedram: osutils.totalmem() - osutils.freemem(),
|
||||
totalram: osutils.totalmem(),
|
||||
usedisk: stats.blocks - stats.bfree,
|
||||
totaldisk: stats.blocks,
|
||||
name: server
|
||||
}
|
||||
|
||||
resolve(resp)
|
||||
|
||||
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
|
||||
} else if(server == "Omega") {
|
||||
|
||||
const key = config.getFile().OMEGA_KEY;
|
||||
|
||||
fetch("http://omega.raphix.fr:4000/metrics?key="+key, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
|
||||
"Accept-Encoding": "gzip, deflate",
|
||||
"Accept-Language": "fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7",
|
||||
"Cache-Control": "no-cache",
|
||||
"Connection": "keep-alive"
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(raw => {
|
||||
raw.name = server;
|
||||
resolve(raw);
|
||||
})
|
||||
.catch(error => {
|
||||
|
||||
reject(error);
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user