Commit dac7026e authored by Ahmad Nemati's avatar Ahmad Nemati

jkjk

parent 32b57214
......@@ -5,7 +5,9 @@ const shell = require('shelljs')
const cron = require('node-cron');
const cronRemover = require('node-cron');
const fs = require('fs')
const cronSpeed = require('node-cron');
const shellExec = require('shell-exec')
var decimalPointRegex = /\-?\d+\.\d+/g;
app.get('/', (req, res) => {
res.send('Hello World!')
run()
......@@ -113,3 +115,53 @@ function getIp() {
});
}
async function calculateSpeed() {
let d = await shellExec('vnstat -tr')
d = d.stdout
d = d.match(decimalPointRegex)
if (d.includes('kbit/s')) {
d[0] = 1
d[1] = 1
} else if (d.includes('Mbit/s')) {
} else if (d.includes('Gbit/s')) {
d[0] = d[0] * 1000
d[1] = d[1] * 1000
} else if (d.includes('bit/s')) {
d[0] = 1
d[1] = 1
}
await sendRate(d[0], d[1])
}
function sendRate(rx, tx) {
const request = require('request');
let url = 'http://admin.fcfglobal.co:3000/rate/' + rx + '/' + tx
return new Promise(function (resolve, reject) {
request(url, {timeout: 6000}, function (error, res, body) {
resolve(true)
});
});
}
cronSpeed.schedule(' */5 * * * * *', () => {
return calculateSpeed()
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment