Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
api.get('/network/receive/:interface', function(req, res) {
let interface = req.params.interface
si.networkStats(interface)
.then(data => res.send((data[0].rx_sec / 125) + '')) // Total data received in kilobits/second (network/recieve/[interface])
.catch(error => res.status(404).send(siError))
})
setInterval(() => {
// get upload speed
si.networkStats(defaultNetwork, data => {
let speed = Math.abs(data.tx_sec / 1024).toFixed(2)
this.upSpeed = speed > 0 ? speed : 0
// up bar update
max = max < this.upSpeed ? this.upSpeed : max
let percent = this.upSpeed / max < 1 ? this.upSpeed / max : 1
upBar.animate(percent)
})
}, 1000)
})
setInterval(() => {
// get down speed
si.networkStats(defaultNetwork, data => {
let speed = Math.abs(data.rx_sec / 1024).toFixed(2)
this.downSpeed = speed > 0 ? speed : 0
// down bar update
max = max < this.downSpeed ? this.downSpeed : max
let percent = this.downSpeed / max < 1 ? this.downSpeed / max : 1
downBar.animate(percent)
})
}, 1000)
})
getSpeed() {
networkStats().then(data =>
this.setState({
download: this.calculate(data.rx_sec),
upload: this.calculate(data.tx_sec)
})
)
}
setInterval(() => {
si.networkStats(defaultNetwork, data => {
let downSpeed = Math.abs(data.rx_sec / 1024).toFixed(2) || 0.00
let upSpeed = Math.abs(data.tx_sec / 1024).toFixed(2) || 0.00
this.networkValues.forEach((n, i) => this.networkValues[i].splice(0, 1))
this.networkValues[0].push(downSpeed > 0 ? downSpeed : 0)
this.networkValues[1].push(upSpeed > 0 ? upSpeed : 0)
this.networkData = []
this.networkData.push({
name: lang('download'),
data: this.networkValues[0].map((d, i) => [this.seconds[i], d])
})
this.networkData.push({
var updater = function() {
si.networkStats(iface, data => {
that.updateData(data[0]);
});
}
updater();
setInterval( () =>
{
si.networkStats(defaultNetwork, (data) =>
{
down = (data.rx_sec / 1024).toFixed(2)
up = (data.tx_sec / 1024).toFixed(2)
downBar.animate(down / 2000)
upBar.animate(up / 2000)
})
}, prop.networkBarsDuration);
}