Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

crossmon-cpu

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crossmon-cpu - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

167

lib/mon.js
var ps = require('./ps');
function setup(config,callback){
if (typeof config['scale']=='undefined'){
config['scale'] = 1;
}
if (typeof config['cpu-all']=='undefined'){
config['cpu-all'] = false;
}
if (typeof config['programs']=='undefined'){
config['programs'] = [];
}
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
rl.question("How many cores you have installed? ["+Math.round(1/config.scale)+"] ", function(answer) {
if (answer==''){
answer = config.scale;
}
if (isNaN(answer)){
callback({error:'no number'},config);
}else{
config.scale = Math.round( (1/answer)*100 )/100;
var chrs = 'y,n';
if(config['cpu-all']){ chrs = 'yes'; }else{ chrs = 'no'; }
rl.question("Should the sum of all processes be monitored? [y,n] (currently "+chrs+") ", function(answer) {
answer = answer.toLowerCase();
if (answer=='y'){
config['cpu-all'] = true;
}
if (answer=='n'){
config['cpu-all'] = false;
}
//rl.close();
//callback(null,config);
_setup(config,rl,{cmd:'help'},callback);
});
}
});
}
function _text(str,length,fill){
if (!fill) fill = ' ';
while(str.length<length){
str+=fill;
}
return str;
}
function _setup(config,rl,opt,callback){
console.log('');
var help = [
'Now you can setup the processes that you want to monitor.',
'Following commands are allowed: ',
"\thelp\tprint this help",
"\tlist\tshow the current configured process list",
"\tadd\tadd an entry",
"\tremove\tremoving an entry",
"\tsave\tsave the current settings and exit",
"\texit\texit without saving"
];
var lines = [];
switch (opt.cmd){
case 'help':
lines = help;
break;
case 'list':
lines.push(' '+_text('',78,'-')+' ');
lines.push('|'+_text(' Title',25)+'|'+_text(' Command contains',52)+'|');
lines.push(' '+_text('',78,'-')+' ');
for(var i in config.programs){
if (typeof config.programs[i].indexOf!='undefined'){
config.programs[i].contains = config.programs[i].indexOf;
delete config.programs[i].indexOf;
}
lines.push('|'+_text(' '+config.programs[i].tag,25)+'|'+_text(' '+config.programs[i].contains,52)+'|');
}
lines.push(' '+_text('',78,'-')+' ');
break;
}
console.log(lines.join("\n"));
rl.question('> ',function(answer) {
switch(answer){
case 'exit':
rl.close();
callback({code:0},config);
break;
case 'save':
rl.close();
callback(null,config);
break;
case 'list':
_setup(config,rl,{cmd:'list'},callback);
break;
case 'remove':
rl.question('title to remove> ',function(answer) {
var new_list = [];//config.programs;
for(var i in config.programs){
if (config.programs[i].tag!=answer){
new_list.push(config.programs[i]);
}
}
config.programs = new_list;
_setup(config,rl,{cmd:'list'},callback);
});
case 'add':
rl.question('title to add> ',function(title) {
rl.question('command contains> ',function(contains) {
config.programs.push({
tag: title,
contains: contains
});
_setup(config,rl,{cmd:'list'},callback);
});
});
break;
default:
_setup(config,rl,{cmd:'help'},callback);
break;
}
});
}
function test(config){
if (typeof config['scale']=='undefined'){
config['scale'] = 1;
}
collect(config,function(items){
console.log( items);
});
}

@@ -10,2 +140,13 @@ function monitor(socket,config){

}
collect(config,function(items){
for(var i in items){
var item = items[i];
socket.emit('put', item);
}
});
}
function collect(config,callback){
scale = config['scale'];

@@ -18,3 +159,3 @@ ps()

}else{
var timestamp = Math.round(new Date().getTime()); // JS Timestamp
var timestamp = new Date().getTime() ; // JS Timestamp
var pslist = parsePS(str);

@@ -30,3 +171,3 @@ if (config['cpu-all'] === true){

};
socket.emit('put', item);
callback([item]);
}

@@ -46,4 +187,5 @@ /*

*/
if (typeof config['programms'] !== 'undefined'){
var programms = config['programms'];
if (typeof config['programs'] !== 'undefined'){
var programms = config['programs'];
var items=[];
for(var p in programms){

@@ -64,10 +206,14 @@ if (typeof programms[p].regex!=='undefined'){

};
socket.emit('put', item);
items.push(item);
}
if (typeof programms[p].indexOf!=='undefined'){
var indexOf = programms[p].indexOf ;
programms[p].contains=programms[p].indexOf; // support old configs
}
if (typeof programms[p].contains!=='undefined'){
var contains = programms[p].contains ;
var sum = 0;
for(var i in pslist){
if (pslist[i].command.indexOf(indexOf)>=0){
if (pslist[i].command.indexOf(contains)>=0){
sum+=pslist[i].cpu;

@@ -82,5 +228,7 @@ }

};
socket.emit('put', item);
items.push(item);
}
}
callback(items);
}

@@ -90,3 +238,2 @@

})
}

@@ -123,2 +270,4 @@

module.exports.setup=setup;
module.exports.test=test;
module.exports.monitor=monitor;

9

package.json
{
"name": "crossmon-cpu",
"version": "0.0.1",
"version": "0.0.2",
"author": {

@@ -8,3 +8,3 @@ "name": "Thomas Hoffmann",

},
"description": "CPU Usage collector for Cross Monitor",
"description": "CPU Usage collector for crossmon-collect",
"main": "./lib/mon",

@@ -28,3 +28,6 @@ "engines": {

},
"readmeFilename": "README.md"
"readmeFilename": "README.md",
"dependencies": {
"commander": ">=2.0.0"
}
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc