Skip to content

Commit

Permalink
- Code instance now reports CPU usage
Browse files Browse the repository at this point in the history
  • Loading branch information
jungkumseok committed Jun 1, 2018
1 parent f3edda0 commit 2f1d141
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/core/CodeV3.js
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ var MasterIPCHandler = {
});
},
'stats': function(proc, payload){
proc.code.pubsub.publish(proc.code.name+'/'+proc.id+'/resource' , { memory: payload });
proc.code.pubsub.publish(proc.code.name+'/'+proc.id+'/resource' , payload);
},
'publish': function(proc, payload){
proc.code.pubsub.publish(payload.topic, payload.message);
Expand Down
12 changes: 11 additions & 1 deletion lib/core/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ process.once('message', function(message){
}());

if (message.options.enableStats){
var pidusage = require('pidusage');
setInterval(function(){
process.send({ ctrl: 'stats', payload: process.memoryUsage() })
pidusage.stat(process.pid, function(err, stat) {
process.send({
ctrl: 'stats',
payload: {
timestamp: Date.now(),
memory: process.memoryUsage(),
cpu: stat.cpu
}
});
});
}, 1000);
}
}
Expand Down

0 comments on commit 2f1d141

Please sign in to comment.