diff options
author | Can Güney Aksakalli <cgaksakalli@gmail.com> | 2017-08-11 18:14:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-08-11 18:14:14 +0200 |
commit | dc71150387261cb5a0e7f60510bae5e4b6c28e4d (patch) | |
tree | bb9750322d97b0a99eff52822edf68a025df84ee | |
parent | 6bc76360bbd4fc7c25006a6a538bac523193cca5 (diff) | |
parent | 4898f11c9e9cd79f62c481c1abb1e0cc3a431350 (diff) |
Merge pull request #13 from aksakalli/developv0.1.4
Develop
-rw-r--r-- | lib/monitor/net.js | 18 | ||||
-rw-r--r-- | lib/utils.js | 4 | ||||
-rw-r--r-- | package.json | 2 |
3 files changed, 14 insertions, 10 deletions
diff --git a/lib/monitor/net.js b/lib/monitor/net.js index 84cf280..5eebf4c 100644 --- a/lib/monitor/net.js +++ b/lib/monitor/net.js @@ -22,23 +22,27 @@ function Net(sparkline) { } Net.prototype.updateData = function(data) { + + var rx_sec = Math.max(0, data['rx_sec']); + var tx_sec = Math.max(0, data['tx_sec']); + this.netData[0].shift(); - this.netData[0].push(Math.max(0, data['rx_sec'])); + this.netData[0].push(rx_sec); this.netData[1].shift(); - this.netData[1].push(Math.max(0, data['tx_sec'])); + this.netData[1].push(tx_sec); - rx = 'Receiving: ' + - utils.humanFileSize(data['rx_sec']) + + rx_label = 'Receiving: ' + + utils.humanFileSize(rx_sec) + '/s \nTotal received: ' + utils.humanFileSize(data['rx']); - tx = 'Transferring: ' + - utils.humanFileSize(data['tx_sec']) + + tx_label = 'Transferring: ' + + utils.humanFileSize(tx_sec) + '/s \nTotal transferred: ' + utils.humanFileSize(data['tx']); - this.sparkline.setData([rx, tx], this.netData); + this.sparkline.setData([rx_label, tx_label], this.netData); this.sparkline.screen.render(); }; diff --git a/lib/utils.js b/lib/utils.js index ed88516..843ff08 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -2,13 +2,13 @@ var utils = {} utils.humanFileSize = function(bytes, isDecimal) { - isDecimal = (typeof isDecimal !== 'undefined') ? isDecimal : false; + isDecimal = (typeof isDecimal !== 'undefined') ? isDecimal : false; if (bytes == 0) { return "0.00 B"; } var base = isDecimal ? 1000 : 1024; var e = Math.floor(Math.log(bytes) / Math.log(base)); - return (bytes / Math.pow(base, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + (isDecimal ? '' : 'i') + 'B'; + return (bytes / Math.pow(base, e)).toFixed(2) + ' ' + ' KMGTP'.charAt(e) + (isDecimal || e == 0 ? '' : 'i') + 'B'; } utils.colors = ['magenta', 'cyan', 'blue', 'yellow', 'green', 'red']; diff --git a/package.json b/package.json index 8153cda..d3e32df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "gtop", - "version": "0.1.3", + "version": "0.1.4", "description": "graphic top", "main": "./index.js", "bin": { |