mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
Added 'monitor' module to server-monitor
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
{
|
||||
"env": {
|
||||
"node": true,
|
||||
"commonjs": true
|
||||
},
|
||||
"extends": "eslint:recommended",
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
@@ -11,7 +15,7 @@
|
||||
],
|
||||
"linebreak-style": [
|
||||
"error",
|
||||
"windows"
|
||||
"unix"
|
||||
],
|
||||
"quotes": [
|
||||
"error",
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
const program = require('commander');
|
||||
const { prompt } = require('inquirer');
|
||||
const {
|
||||
authenticateUser
|
||||
} = require('./src/logic');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { authenticateUser, pingServer } = require('./src/logic');
|
||||
|
||||
// Questions to get projectId and API key
|
||||
const questions = [
|
||||
@@ -20,20 +19,21 @@ const questions = [
|
||||
}
|
||||
];
|
||||
|
||||
program
|
||||
.version('0.0.1')
|
||||
.description('Fyipe Monitoring Shell');
|
||||
program.version('0.0.1').description('Fyipe Monitoring Shell');
|
||||
|
||||
program
|
||||
.command('start')
|
||||
.alias('s')
|
||||
.description('Authenticates a user by accepting and confirming projectId and apiKey.' +
|
||||
'Begin server monitoring')
|
||||
.description(
|
||||
'Authenticates a user by accepting and confirming projectId and apiKey.' +
|
||||
'Begin server monitoring'
|
||||
)
|
||||
.action(() => {
|
||||
prompt(questions).then(input => {
|
||||
const { projectId, apiKey } = input;
|
||||
authenticateUser(projectId, apiKey)
|
||||
})
|
||||
})
|
||||
authenticateUser(projectId, apiKey);
|
||||
// pingServer.start();
|
||||
});
|
||||
});
|
||||
|
||||
program.parse(process.argv);
|
||||
|
||||
@@ -1,37 +1,38 @@
|
||||
const axios = require('axios');
|
||||
const si = require('systeminformation');
|
||||
const { apiUrl } = require('./config');
|
||||
|
||||
const postApi = (url, data) => {
|
||||
|
||||
axios({
|
||||
method: 'POST',
|
||||
url: `${apiUrl}/${url}`,
|
||||
data: data
|
||||
})
|
||||
.then(function (res) {
|
||||
return res
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
}
|
||||
.then(function (res) {
|
||||
return res;
|
||||
})
|
||||
.catch(function (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(error);
|
||||
});
|
||||
};
|
||||
|
||||
// Testing the getAPI
|
||||
const getApi = (url) => {
|
||||
const getApi = url => {
|
||||
axios({
|
||||
method: 'GET',
|
||||
url: `${apiUrl}/${url}`
|
||||
})
|
||||
.then(function (res) {
|
||||
if (res.data === 'Server Error.') console.log('success')
|
||||
})
|
||||
.catch(function (error) {
|
||||
console.error(error)
|
||||
});
|
||||
}
|
||||
.then(function (res) {
|
||||
// eslint-disable-next-line no-console
|
||||
if (res.data === 'Server Error.') console.log('success');
|
||||
})
|
||||
.catch(function (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.error(error);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = {
|
||||
module.exports = {
|
||||
postApi,
|
||||
getApi
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,19 +1,36 @@
|
||||
const os = require('os-utils')
|
||||
const os = require('os-utils');
|
||||
const cron = require('cron');
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const { postApi, getApi } = require('./api');
|
||||
const { getServerStats } = require('./monitor');
|
||||
|
||||
const authenticateUser = (projectId, apiKey) => {
|
||||
postApi(`serverMonitor/${projectId}/${apiKey}`)
|
||||
}
|
||||
postApi(`serverMonitor/${projectId}/${apiKey}`);
|
||||
};
|
||||
|
||||
let pingServer = new cron.CronJob('* * * * *', function() {
|
||||
const serverStat = {
|
||||
cpuCount: os.cpuCount()
|
||||
};
|
||||
postApi(`serverPackage/uploadServerData/${projectId}`, serverStat);
|
||||
}, null, false);
|
||||
let pingServer = new cron.CronJob(
|
||||
'* * * * *',
|
||||
function () {
|
||||
getServerStats()
|
||||
.then(data => {
|
||||
// eslint-disable-next-line no-console
|
||||
console.log(data);
|
||||
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const serverStat = {
|
||||
cpuCount: os.cpuCount()
|
||||
};
|
||||
|
||||
// postApi(`serverPackage/uploadServerData/${projectId}`, serverStat);
|
||||
})
|
||||
// eslint-disable-next-line no-console
|
||||
.catch(error => console.log(error));
|
||||
},
|
||||
null,
|
||||
false
|
||||
);
|
||||
|
||||
module.exports = {
|
||||
pingServer,
|
||||
authenticateUser
|
||||
}
|
||||
};
|
||||
|
||||
21
server-monitor/src/monitor.js
Normal file
21
server-monitor/src/monitor.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// monitor system params
|
||||
// Promise.all([
|
||||
// si.currentLoad(),
|
||||
// si.mem(),
|
||||
// si.blockDevices(),
|
||||
// si.networkStats(),
|
||||
// si.cpuTemperature(),
|
||||
// si.cpu(),
|
||||
// si.users(),
|
||||
// si.networkConnections(),
|
||||
// si.vboxInfo()
|
||||
// ]).then(data => data);
|
||||
// do something with data and pass it on
|
||||
|
||||
const si = require('systeminformation');
|
||||
|
||||
const getServerStats = () => {
|
||||
return si.getAllData();
|
||||
};
|
||||
|
||||
module.exports = { getServerStats };
|
||||
Reference in New Issue
Block a user