1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

Add memory metric reporting

This commit is contained in:
Nick O'Leary 2015-02-04 22:28:17 +00:00
parent 1712146836
commit 482c4e9c5e
5 changed files with 37 additions and 5 deletions

View File

@ -19,7 +19,7 @@ var EventEmitter = require("events").EventEmitter;
var levels = {
off: 0,
off: 1,
fatal: 10,
error: 20,
warn: 30,
@ -46,7 +46,6 @@ var ConsoleLogHandler = function(settings) {
this.logLevel = levels[settings.level]||levels.info;
this.metricsOn = settings.metrics||false;
metricsEnabled = this.metricsOn;
this.on("log",function(msg) {
if (this.shouldReportMessage(msg.level)) {
if (msg.level == log.METRIC) {

View File

@ -213,7 +213,7 @@ Node.prototype.metric = function(eventname, msg, metricValue) {
metrics.nodeid = this.id;
metrics.event = "node."+this.type+"."+eventname;
metrics.msgid = msg._id;
metrics.metric = metricValue;
metrics.value = metricValue;
Log.log(metrics);
}

View File

@ -34,9 +34,9 @@ var RED = {
init: function(httpServer,userSettings) {
userSettings.version = this.version();
log.init(userSettings);
settings.init(userSettings);
server.init(httpServer,settings);
log.init(userSettings);
return server.app;
},

View File

@ -28,6 +28,9 @@ var nodeApp = null;
var server = null;
var settings = null;
var runtimeMetricInterval = null;
function init(_server,_settings) {
server = _server;
settings = _settings;
@ -47,6 +50,11 @@ function start() {
storage.init(settings).then(function() {
settings.load(storage).then(function() {
if (log.metric()) {
runtimeMetricInterval = setInterval(function() {
reportMetrics();
}, 15000);
}
console.log("\nWelcome to Node-RED\n===================\n");
if (settings.version) {
log.info("Version: "+settings.version);
@ -193,9 +201,34 @@ function uninstallModule(module) {
});
}
function reportMetrics() {
var memUsage = process.memoryUsage();
// only need to init these once per report
var metrics = {};
metrics.level = log.METRIC;
//report it
metrics.event = "runtime.memory.rss"
metrics.value = memUsage.rss;
log.log(metrics);
metrics.event = "runtime.memory.heapTotal"
metrics.value = memUsage.heapTotal;
log.log(metrics);
metrics.event = "runtime.memory.heapUsed"
metrics.value = memUsage.heapUsed;
log.log(metrics);
}
function stop() {
if (runtimeMetricInterval) {
clearInterval(runtimeMetricInterval);
runtimeMetricInterval = null;
}
redNodes.stopFlows();
comms.stop();
}

View File

@ -402,7 +402,7 @@ describe('Node', function() {
});
var msg = {payload:"foo", _id:"987654321"};
n.metric("test.metric",msg,"15mb");
should.deepEqual({metric:"15mb", level:Log.METRIC, nodeid:n.id,
should.deepEqual({value:"15mb", level:Log.METRIC, nodeid:n.id,
event:"node.abc.test.metric",msgid:"987654321"}, loginfo);
Log.log.restore();
done();