| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 | 
							- var log = require('hlogger').createLogger("monitor");
 
- function ntokb(n) {
 
- 	var suffix = ["B","KB","MB","GB"];
 
- 	var si = 0;
 
- 	while( n> 1024 && si< suffix.length) {
 
- 		n/=1024;
 
- 		si++;
 
- 	}
 
- 	return n.toFixed(2) + " " +suffix[si];
 
- }
 
- var monitor = {
 
- 	bundleStart(context) {
 
- 		this.context = context;
 
- 		log.info("Bundle monitor started");
 
- 		this.registerCommands(context);
 
- 		context.on('hci-config', (config) => {
 
- 			context.on(config,"start",function() {
 
- 				config.test();
 
- 			});	
 
- 		});
 
- 	},
 
- 	registerCommands(context) {
 
- 		context
 
- 			.channel('core-shell:cmd')
 
- 			.on('stat',(req,res,e) => {
 
- 				this.showStat(res); // Should pass stdout
 
- 			});
 
- 		// listen from command from ourselves
 
- 		/*context.on('core-shell:cmd:stat',(req,res,e) => {
 
- 				this.showStat(res); // Should pass stdout
 
- 		}).on('core-shell:cmd:gc',(req,res,e) => {
 
- 			gc();
 
- 		})
 
- 		context.on('core-shell:cmd:test',(req,res,e) => {
 
- 		});/**/
 
- 	},
 
- 	showStat(res) {
 
- 		var context = this.context;
 
- 		var obj = process.memoryUsage();
 
- 		if(res == undefined) res = process.stdout;
 
- 		res.write("Memory Rss: " + ntokb(obj.rss)
 
- 				 +" Total: " + ntokb(obj.heapTotal)
 
- 				 +" Used: " + ntokb(obj.heapUsed) +"\n");
 
- 		// Weird?
 
- 		/*res.write("Modules registered: " + context.manager.stat.modulesRegistered
 
- 						+" Modules UnRegistered: " + context.manager.stat.modulesUnRegistered
 
- 						+" events emitted: " + context.manager.events.stat.emitted
 
- 						+" events called: " + context.manager.events.stat.called
 
- 						+" events tried: " + context.manager.events.stat.tried + "\n");*/
 
- 	},
 
- 	// Human readable stat
 
- 	getStat() {
 
- 		var obj = {};
 
- 		var mem = process.memoryUsage();
 
- 		obj.mem = {
 
- 			rss: ntokb(mem.rss),
 
- 			heapTotal: ntokb(mem.heapTotal),
 
- 			heapUsed: ntokb(mem.heapUsed),
 
- 		}
 
- 		return obj;
 
- 	}
 
- };
 
- module.exports = monitor;
 
 
  |