-
Notifications
You must be signed in to change notification settings - Fork 0
/
getSpeeds.js
37 lines (30 loc) · 1002 Bytes
/
getSpeeds.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/*
* Written by Nilushan Costa
*
* Purpose - Obtain WAN link bandwidth utilization of a Huawei 4G router
* Input - None
* Output - Download speed and upload speed in Bytes per second as csv values output line by line
*
*/
var gatewayIp = process.argv[2];
var router = require('dialog-router-api').create({
gateway: gatewayIp });
var exec = require('child_process').exec;
var downloadRate = 0;
var uploadRate = 0;
var latency = 0;
function loop(){
router.getToken(function(error, token) {
router.getTrafficStatistics(token, function(error, response){
var downloadRateString =String(response.CurrentDownloadRate);
downloadRate = downloadRateString.substring(0);
});
router.getTrafficStatistics(token, function (error, response) {
var uploadRateString = String(response.CurrentUploadRate);
uploadRate = uploadRateString.substring(0);
});
});
console.log(downloadRate + "," + uploadRate);
setTimeout(loop,2000); //Run every 2 seconds
}
loop();