Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated demo GIF #96

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added img/gtop_updated_demo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 20 additions & 6 deletions lib/gtop.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@ var blessed = require('blessed'),
contrib = require('blessed-contrib'),
monitor = require('./monitor');

const { argv } = require('yargs');

var netInterface = null;

if(typeof argv.net != 'undefined') {
netInterface = argv.net;
}

var screen = blessed.screen()
var grid = new contrib.grid({
Expand All @@ -17,6 +24,12 @@ var cpuLine = grid.set(0, 0, 4, 12, contrib.line, {
showLegend: true,
})

var hostnameWidget = grid.set(0, 8, 1, 2, contrib.markdown, {
label: "HOSTNAME",
fg: "green",
selectedFg: "green"
})

var memLine = grid.set(4, 0, 4, 8, contrib.line, {
showNthLabel: 5,
maxY: 100,
Expand Down Expand Up @@ -69,7 +82,7 @@ var procTable = grid.set(8, 6, 4, 6, contrib.table, {
procTable.focus()

screen.render();
screen.on('resize', function(a) {
screen.on('resize', function (a) {
cpuLine.emit('attach');
memLine.emit('attach');
memDonut.emit('attach');
Expand All @@ -79,24 +92,25 @@ screen.on('resize', function(a) {
procTable.emit('attach');
});

screen.key(['escape', 'q', 'C-c'], function(ch, key) {
screen.key(['escape', 'q', 'C-c'], function (ch, key) {
return process.exit(0);
});

function init() {
new monitor.Cpu(cpuLine); //no Windows support
new monitor.Mem(memLine, memDonut, swapDonut);
new monitor.Net(netSpark);
new monitor.Net(netSpark, netInterface);
new monitor.Disk(diskDonut);
new monitor.Proc(procTable); // no Windows support
new monitor.Proc(procTable, blessed, screen); // no Windows support
new monitor.Host(hostnameWidget);
}


process.on('uncaughtException', function(err) {
process.on('uncaughtException', function (err) {
// avoid exiting due to unsupported system resources in Windows
});

module.exports = {
init: init,
monitor: monitor
};
};
21 changes: 21 additions & 0 deletions lib/monitor/hostname.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var si = require('systeminformation'),
utils = require('../utils');

var colors = utils.colors;

function Host(markdown) {
this.markdown = markdown;

this.interval = setInterval(() => {
this.updateData();
}, 1000);
}

Host.prototype.updateData = function () {
si.osInfo((info) => {
this.markdown.setMarkdown(info.hostname);
})
}


module.exports = Host;
3 changes: 2 additions & 1 deletion lib/monitor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ module.exports = {
Mem: require('./mem'),
Net: require('./net'),
Disk: require('./disk'),
Proc: require('./proc')
Proc: require('./proc'),
Host: require('./hostname')
}
28 changes: 14 additions & 14 deletions lib/monitor/net.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ var si = require('systeminformation'),

var colors = utils.colors;

function Net(sparkline) {
function Net(sparkline, netInterface) {
this.sparkline = sparkline;
this.netData = [Array(61).fill(0), Array(61).fill(0)];

si.networkInterfaceDefault(iface => {
var that = this;
var updater = function() {
si.networkStats(iface, data => {
that.updateData(data[0]);
});
}
updater();
this.interval = setInterval(updater, 1000);
})
si.networkInterfaceDefault(iface => {
var that = this;
var updater = function () {
si.networkStats(netInterface == null ? iface : netInterface, data => {
that.updateData(data[0], netInterface == null ? iface : netInterface);
});
}
updater();
this.interval = setInterval(updater, 1000);
})
}

Net.prototype.updateData = function(data) {
Net.prototype.updateData = function (data, iface) {

var rx_sec = Math.max(0, data['rx_sec']);
var tx_sec = Math.max(0, data['tx_sec']);
Expand All @@ -30,12 +30,12 @@ Net.prototype.updateData = function(data) {
this.netData[1].shift();
this.netData[1].push(tx_sec);

rx_label = 'Receiving: ' +
rx_label = iface + ' Receiving: ' +
utils.humanFileSize(rx_sec) +
'/s \nTotal received: ' +
utils.humanFileSize(data['rx_bytes']);

tx_label = 'Transferring: ' +
tx_label = iface + ' Transferring: ' +
utils.humanFileSize(tx_sec) +
'/s \nTotal transferred: ' +
utils.humanFileSize(data['tx_bytes']);
Expand Down
42 changes: 41 additions & 1 deletion lib/monitor/proc.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ var pars = {
m: 'pmem'
}

function Proc(table) {
function Proc(table, blessed, screen) {
this.table = table;

this.pSort = 'pcpu';
Expand Down Expand Up @@ -38,6 +38,46 @@ function Proc(table) {
updater();
});

var form;

this.table.rows.on('select', (node, index) => {
this.selectedProc = node.parent.value.match(/[0-9]+/g)[0];

form = blessed.form({
parent: screen,
width: 60,
height: 4,
keys: true,
border: {
type: 'line'
},
top: 'center',
left: 'center'
});

blessed.text({
parent: form,
fg: 'green',
content: 'Press y button to kill process #'+this.selectedProc+ ' \n Or, press n button to cancel'
});

form.on('submit', (data) => {
screen.remove(form);
process.kill(this.selectedProc, 'SIGHUP');
});

screen.render();
});

screen.key(['y'], (ch, key) => {
form.submit();
});

screen.key(['n'], (ch, key) => {
screen.remove(form);
this.selectedProc = 0;
});

}

Proc.prototype.updateData = function(data) {
Expand Down
Loading